⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netif.c

📁 在LINUX下运行的仿真机器人服务器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
						done_received = TRUE;						return ;				}         else if (!strcmp(com, "compression"))           {            int level ;            if ((n = sscanf(command,"(%s %d)",com,&level)) < 2)              {                send("(error illegal_command_form)") ;                return ;              }#ifdef HAVE_LIBZ            if( level > 9 )              {                send("(error illegal_command_form)") ;                return ;              }            #ifdef HAVE_SSTREAM            std::ostringstream reply;                        reply << "(ok compression " << level << ")";            send ( reply.str().c_str() );#else            std::ostrstream reply;                        reply << "(ok compression " << level << ")" << std::ends;            send ( reply.str() );            reply.freeze( false );#endif            setCompressionLevel ( level );            #else            send ( "(warning compression_unsupported)" );#endif            return ;          }         else {						send("(error unknown_command)") ;						return ;        }}void Coach::look(Stadium& stad) {#ifdef HAVE_SSTREAM    std::ostringstream ost;#else    std::ostrstream ost;#endif    ost << "(ok look " << stad.time ;    if ( version >= 7.0 )      ost << " (" << GOAL_L_NAME_SHORT;    else      ost << " (" << GOAL_L_NAME;        ost << " " << -(PITCH_LENGTH/2.0)        << " " << 0.0        << ")" ;        if ( version >= 7.0 )      ost << " (" << GOAL_R_NAME_SHORT;     else      ost << " (" << GOAL_R_NAME;        ost << " " << (PITCH_LENGTH/2.0)        << " " << 0.0        << ")" ;    if ( version >= 7.0 )      ost << " (" << BALL_NAME_SHORT;    else      ost << " (" << BALL_NAME;        ost << " " << stad.ball->pos.x        << " " << stad.ball->pos.y        << " " << stad.ball->vel.x        << " " << stad.ball->vel.y        << ")" ;        TheNumber i ;    for(i = 0 ; i < MAX_PLAYER * 2; i++ )      {        if (stad.player[i]->alive == DISABLE)          continue ;        if ( version >= 7.0 )                         ost << " (" << (stad.player[i])->short_name              << " " << (stad.player[i])->pos.x              << " " << (stad.player[i])->pos.y              << " " << (stad.player[i])->vel.x              << " " << (stad.player[i])->vel.y              << " " << Rad2IDegRound((stad.player[i])->angle)              << " " << Rad2IDegRound((stad.player[i])->angle_neck_committed)              << ")" ;            else          ost << " (" << (stad.player[i])->name              << " " << (stad.player[i])->pos.x              << " " << (stad.player[i])->pos.y              << " " << Rad2IDeg((stad.player[i])->angle)              << " " << Rad2IDeg((stad.player[i])->angle_neck_committed)              << " " << (stad.player[i])->vel.x              << " " << (stad.player[i])->vel.y              << ")" ;      }    ost << ")" << std::endl;#ifdef HAVE_SSTREAM    send(ost.str().c_str());#else    ost << std::ends;    send(ost.str());    ost.freeze();#endif}void Coach::team_names(Stadium& stad){#ifdef HAVE_SSTREAM  std::ostringstream ost;#else  std::ostrstream ost;#endif    ost << "(ok team_names";    if (stad.team_l->name)    {      ost << " (team l " << stad.team_l->name << ")";    }  if (stad.team_r->name)    {      ost << " (team r " << stad.team_r->name << ")";    }    ost << ")" << std::endl;#ifdef HAVE_SSTREAM  send(ost.str().c_str()) ;#else  ost<< std::ends;  send(ost.str()) ;  ost.freeze();#endif}void Coach::recover(Stadium& stad){  stad.recovery_players();  #ifdef HAVE_SSTREAM  std::ostringstream ost;  ost << "(ok recover)" << std::endl;  send(ost.str().c_str());#else  std::ostrstream ost;  ost << "(ok recover)" << std::endl << std::ends;  send(ost.str()) ;  ost.freeze();#endif}void Coach::send_visual_info(void) {    int i;#ifdef HAVE_SSTREAM    std::ostringstream ost;#else    std::ostrstream ost;#endif    if ( version >= 7.0 )          ost << "(see_global " << stadium->time;     else      ost << "(see " << stadium->time;         if ( version >= 7.0 )      ost << " (" << GOAL_L_NAME_SHORT;    else      ost << " (" << GOAL_L_NAME;    ost << " " << -(PITCH_LENGTH/2.0)        << " " << 0.0        << ")" ;        if ( version >= 7.0 )      ost << " (" << GOAL_R_NAME_SHORT;    else        ost << " (" << GOAL_R_NAME;    ost << " " << (PITCH_LENGTH/2.0)        << " " << 0.0        << ")" ;        if ( version >= 7.0 )      ost << " (" << BALL_NAME_SHORT;    else      ost << " (" << BALL_NAME;        ost << " " << stadium->ball->pos.x        << " " << stadium->ball->pos.y        << " " << stadium->ball->vel.x        << " " << stadium->ball->vel.y        << ")" ;        for(i = 0 ; i < MAX_PLAYER * 2; i++ ) {      if (stadium->player[i]->alive == DISABLE)        continue ;            if ( version >= 7.0 )        {          ost << " (" << (stadium->player[i])->short_name              << " " << (stadium->player[i])->pos.x              << " " << (stadium->player[i])->pos.y              << " " << (stadium->player[i])->vel.x              << " " << (stadium->player[i])->vel.y              << " " << Rad2IDegRound((stadium->player[i])->angle)              << " " << Rad2IDegRound((stadium->player[i])->angle_neck_committed);          if ( version >= 8.0 )            {              double arm_dir;              if ( (stadium->player[i])->getArm ().getRelDir ( rcss::geom::Vector2D ( (stadium->player[i])->pos.x,                                                                                      (stadium->player[i])->pos.y ),                                                               (stadium->player[i])->angle_body                                                                + (stadium->player[i])->angle_neck_committed,                                                               arm_dir ) )                ost << " " << Rad2IDegRound ( normalize_angle ( arm_dir                                                                 + (stadium->player[i])->angle_neck_committed                                                                 + (stadium->player[i])->angle ) );              if( (stadium->player[i])->isTackling() )                ost << " t";            }          ost << ")" ;        }      else        ost << " (" << (stadium->player[i])->name            << " " << (stadium->player[i])->pos.x            << " " << (stadium->player[i])->pos.y            << " " << Rad2IDeg((stadium->player[i])->angle)            << " " << Rad2IDeg((stadium->player[i])->angle_neck_committed)            << " " << (stadium->player[i])->vel.x            << " " << (stadium->player[i])->vel.y            << ")" ;    }    ost << ")" << std::endl;#ifdef HAVE_SSTREAM    send(ost.str().c_str()) ;#else    ost << std::ends;        send(ost.str()) ;    ost.freeze( false );#endif}void Coach::check_ball(Stadium& stad){#ifdef HAVE_SSTREAM  std::ostringstream ost;#else  std::ostrstream ost;#endif  static char* BallPosInfoStr[] = BALL_POS_INFO_STRINGS ;  BallPosInfo info = stad.check_ball_pos() ;    ost << "(ok check_ball " << stad.time << " " ;    ost << BallPosInfoStr[info] << ")";  ost << std::ends ;  #ifdef HAVE_SSTREAM    send(ost.str().c_str()) ;#else    ost << std::ends;        send(ost.str()) ;    ost.freeze( false );#endif}void OnlineCoach::parse_command( const char *command ){  char com[MaxStringSize] ;  int n;  n = sscanf(command, "(%[-0-9a-zA-Z.+*/?<>_]",com) ;  if(n<1) {send("(error illegal_command_form)"); return ; }  if (!strcmp(com,"check_ball")) {    check_ball( *stadium ) ;  }  else if (!strcmp(com,"look")) {    look( *stadium ) ;  }  else if (!strcmp(com,"team_names")) {    team_names( *stadium ) ;  }  else if( !strcmp( com, "say" ) )    {      if (version >= 7.0)         {          /* parsing for new coach language */          rcss::clang::MsgBuilder builder;          rcss::clang::Parser parser( builder );          int ret = parser.parse( command );           if( ret == 0 && builder.getMsg() != NULL )            {              //succeful parse              bool should_queue = false;                            rcss::clang::Msg* msg = builder.detatchMsg().release();                            msg->setTimeRecv( stadium->time );              	      switch( msg->getType() )	      {		  case rcss::clang::Msg::META:		      if( stadium->mode != PM_PlayOn )		      {			  should_queue = true;		      } 		      else if( meta_messages_left != 0 )		      {			  //remember, negative implies we can send as many as we want			  --meta_messages_left;			  should_queue = true;		      } 		      else 		      {			  send( "(error said_too_many_meta_messages)" );		      }		      break;		  case rcss::clang::Msg::FREEFORM:		      if( stadium->mode != PM_PlayOn			  || stadium->canSendFreeform() )		      {			  if( freeform_messages_said < freeform_messages_allowed			      || freeform_messages_allowed < 0 )			  {			      should_queue = true;			      freeform_messages_said++;			  } 			  else 			  {			      send( "(error said_too_many_freeform_messages)" );			  }		      }		      else		      {			  send( "(error cannot_say_freeform_while_playon)" );		      }		      break;		  case rcss::clang::Msg::INFO:		      if( stadium->mode != PM_PlayOn )		      {			  should_queue = true;		      }		      else if(info_messages_left != 0)		      {			  //remember, negative implies we can send as many as we want			  --info_messages_left;			  should_queue = true;		      }		      else		      {			  send( "(error said_too_many_info_messages)" );		      }		      break;		  case rcss::clang::Msg::ADVICE:		      if( stadium->mode != PM_PlayOn )		      {			  should_queue = true;		      } 		      else if( advice_messages_left != 0 )		      {			  //remember, negative implies we can send as many as we want			  --advice_messages_left;			  should_queue = true;		      }		      else		      {			  send( "(error said_too_many_advice_messages)" );		      }		      break;		  case rcss::clang::Msg::DEFINE:		      if( stadium->mode != PM_PlayOn )		      {			  should_queue = true;		      }		      else if( define_messages_left != 0 )		      {			  //remember, negative implies we can send as many as we want			  --define_messages_left;			  should_queue = true;		      }		      else		      {			  send( "(error said_too_many_define_messages)" );		      }		      break;		  case rcss::clang::Msg::DEL:		      if( stadium->mode != PM_PlayOn )		      {			  should_queue = true;		      }		      else if( del_messages_left != 0 )		      {			  //remember, negative implies we can send as many as we want			  --del_messages_left;			  should_queue = true;		      }		      else		      {			  send( "(error said_too_many_del_messages)" );		      }		      break;		  case rcss::clang::Msg::RULE:		      if( stadium->mode != PM_PlayOn )		      {			  should_queue = true;		      }		      else if( rule_messages_left != 0 )		      {			  //remember, negative implies we can send as many as we want			  --rule_messages_left;			  should_queue = true;		      }		      else		      {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -