coach.cpp
来自「2009 ROBOCUP 仿真2DSERVER 源码」· C++ 代码 · 共 1,850 行 · 第 1/4 页
CPP
1,850 行
} else if ( M_define_messages_left != 0 ) { //remember, negative implies we can send as many as we want --M_define_messages_left; should_queue = true; } else { send( "(error said_too_many_define_messages)" ); } break; case rcss::clang::Msg::DEL: if( M_stadium.playmode() != PM_PlayOn ) { should_queue = true; } else if ( M_del_messages_left != 0 ) { //remember, negative implies we can send as many as we want --M_del_messages_left; should_queue = true; } else { send( "(error said_too_many_del_messages)" ); } break; case rcss::clang::Msg::RULE: if( M_stadium.playmode() != PM_PlayOn ) { should_queue = true; } else if ( M_rule_messages_left != 0 ) { //remember, negative implies we can send as many as we want --M_rule_messages_left; should_queue = true; } else { send( "(error said_too_many_rule_messages)" ); } break; default: std::cerr << __FILE__ << ": " << __LINE__ << ": Coach msg has an unknown type: " << msg << std::endl; } if ( should_queue ) { M_message_queue.push_back( msg ); send( "(ok say)" ); } else { delete msg; } } else { send( "(error could_not_parse_say)" ); } } else { //pre v7.0 if ( M_stadium.playmode() != PM_PlayOn ) { if( M_freeform_messages_said < M_freeform_messages_allowed || M_freeform_messages_allowed < 0 ) { static char msg[MaxMesg]; n = std::sscanf( command, SAY_MESSAGE_SCAN_FORMAT, com, msg ); if( n < 2 ) { send( "(error illegal_command_form)" ); return; } chop_last_parenthesis( msg, ServerParam::instance().freeformMsgSize() ); say( msg ); send( "(ok say)" ); } else { send( "(error said_too_many_messages)" ); return; } } else { send( "(warning cannot_say_while_playon)" ); return; } } } else if ( ! std::strcmp( com, "bye" ) ) { disable(); return; } else if ( ! std::strcmp( com, "eye" ) ) { char mode[16] ; if ( std::sscanf( command, "(eye %15[^ ()])", mode ) != 1 ) { send( "(error illegal_command_form)" ); return; } eye( mode ); return; }// else if ( ! std::strcmp( com, "change_player_types" ) )// {// change_player_types( command );// return;// } else if ( ! std::strcmp ( com, "change_player_type" ) ) { int unum, player_type; if ( std::sscanf( command, "(%s %d %d)", com, &unum, &player_type ) != 3 ) { send( "(error illegal_command_form)" ); return; } change_player_type( unum, player_type ); return; } //pfr:SYNCH else if ( ! std::strcmp( com, "done" ) ) { //std::cerr << "Recv olc done" << std::endl; M_done_received = true; return; } else if ( ! std::strcmp( com, "compression" ) ) { int level ; if ( std::sscanf( command, "(%s %d)", com, &level ) < 2 ) { send( "(error illegal_command_form)" ); return; } compression( level ); return; } else if ( ! std::strcmp( com, "team_graphic" ) ) { team_graphic( command ); } else { send( "(error unknown_command)" ); return; }}voidOnlineCoach::awardFreeformMessageCount(){ if ( M_freeform_messages_allowed > 0 ) { M_freeform_messages_allowed += ServerParam::instance().freeformCountMax(); }}boolOnlineCoach::canSendFreeform() const{ if ( M_stadium.playmode() != PM_PlayOn ) { return true; } int playon_period = M_stadium.time() - M_stadium.lastPlayOnStart(); if ( playon_period > (int)ServerParam::instance().freeformWaitPeriod() ) { playon_period %= ServerParam::instance().freeformWaitPeriod(); return playon_period < (int)ServerParam::instance().freeformSendPeriod(); } return false;}voidOnlineCoach::sendPlayerClangVer(){ M_init_observer_olcoach->sendPlayerClangVer();// for ( Stadium::PlayerCont::iterator i = M_stadium.remotePlayers().begin();// i != M_stadium.remotePlayers().end();// ++i )// {// if ( (*i)->getClangMinVer() != 0// || (*i)->getClangMaxVer() != 0 )// {// sendPlayerClangVer( **i );// }// }}voidOnlineCoach::sendPlayerClangVer( const Player& player ){ M_init_observer_olcoach->sendPlayerClangVer( player );// #ifdef HAVE_SSTREAM// std::ostringstream msg;// getSerializer().serializePlayerClangVer( msg,// player.shortName(),// player.getClangMinVer(),// player.getClangMaxVer() );// send( msg.str().c_str() );// #else// std::ostrstream msg;// getSerializer().serializePlayerClangVer( msg,// player.shortName(),// player.getClangMinVer(),// player.getClangMaxVer() );// msg << std::ends;// send( msg.str() );// msg.freeze( false );// #endif}intOnlineCoach::check_message_queue( int time ){ if ( M_message_queue.size() <= 0 ) { return 0; } int messages_sent = 0; for ( int i = ServerParam::instance().clangMessPerCycle(); i > 0 && M_message_queue.size() > 0; ++i ) { rcss::clang::Msg* msg = *( M_message_queue.begin() ); if ( M_stadium.playmode() != PM_PlayOn || time - msg->getTimeRecv() >= ServerParam::instance().clangMessDelay() ) { msg->setTimeSend( M_stadium.time() ); msg->setSide( side() ); say( *msg ); M_message_queue.pop_front(); delete msg; ++messages_sent; } else { break; } } return messages_sent;}voidOnlineCoach::say( const rcss::clang::Msg & message ){ M_stadium.sendCoachStdAudio( *this, message );}voidOnlineCoach::say( const char * message ){ M_stadium.sendCoachAudio( *this, message );}voidOnlineCoach::change_player_type( int unum, int player_type ){ if ( M_stadium.playmode() == PM_PlayOn ) { send( "(warning cannot_sub_while_playon)" ); return; } else if ( ServerParam::instance().halfTime() < 0 ) { // OK } else if ( M_stadium.time() >= ( ( ServerParam::instance().halfTime() * ServerParam::instance().nrNormalHalfs() ) + ( ServerParam::instance().extraHalfTime() * ServerParam::instance().nrExtraHalfs() ) ) ) { // when time elapsed, do not allow substitutions anymore (for penalties) //send( "(warning no_subs_left)" ); send( "(warning cannot_sub_while_penalty_shootouts)" ); return; } const Team * team = NULL; if ( side() == LEFT ) { team = &( M_stadium.teamLeft() ); } if ( side() == RIGHT ) { team = &( M_stadium.teamRight() ); } if ( team == NULL ) { send( "(warning no_team_found)" ); return; } if ( team->subsCount() >= PlayerParam::instance().subsMax() ) { send( "(warning no_subs_left)" ); return; } if ( player_type < 0 || player_type >= PlayerParam::instance().playerTypes() ) { send( "(error out_of_range_player_type)" ); return; } // check the substitution count for each player type std::map< int, int >::const_iterator used_count = team->ptypeUsedCount().find( player_type ); if ( used_count != team->ptypeUsedCount().end() ) { if ( player_type == 0 && PlayerParam::instance().allowMultDefaultType() ) { } else if ( used_count->second >= PlayerParam::instance().ptMax() ) { send( "(warning no_left_of_that_type)" ); return; } } const Player * player = NULL; for ( int i = 0; i < team->size(); ++i ) { const Player * p = team->player( i ); if ( p && p->unum() == unum ) { player = p; break; } } if ( player == NULL ) { send( "(warning no_such_player)" ); return; } if ( player->isGoalie() && player_type != 0 ) { send( "(warning cannot_change_goalie)" ); return; } if ( player_type != 0 && team->ptypeCount( player_type ) >= PlayerParam::instance().ptMax() && player_type != player->playerTypeId() ) { send( "(warning max_of_that_type_on_field)" ); return; } M_stadium.substitute( player, player_type ); char buf[64]; snprintf( buf, 64, "(ok change_player_type %d %d)", unum, player_type ); send( buf );}voidOnlineCoach::team_graphic( const char * command ){ if ( M_stadium.playmode() != PM_BeforeKickOff ) { send( "(warning only_before_kick_off)" ); return; } unsigned int x, y; if ( std::sscanf( command, "(team_graphic (%u %u", &x, &y ) != 2 ) { send( "(error illegal_command_form)" ); return; } if ( x >= 32 || y >= 8 ) // needs to be parameterised { send( "(warning invalid_tile_location)" ); } std::auto_ptr< XPMHolder > holder( new XPMHolder( command ) ); if ( ! holder->valid() ) { send( "(error illegal_command_form)" ); return; } if ( holder->getWidth() != 8 || holder->getHeight() != 8 ) // needs to be parameterised { send( "(warning invalid_tile_size)" ); return; } M_stadium.addTeamGraphic( side(), x, y, holder ); M_stadium.sendTeamGraphic( side(), x, y );#ifdef HAVE_SSTREAM std::ostringstream msg; msg << "(ok team_graphic " << x << " " << y << ")"; send( msg.str().c_str() );#else std::ostrstream msg; msg << "(ok team_graphic " << x << " " << y << ")" << std::ends; send( msg.str() ); msg.freeze( false );#endif}boolOnlineCoach::update_messages_left( int time ){ if ( M_msg_left_update_time >= 0 && time - M_msg_left_update_time < ServerParam::instance().clangWinSize() ) { return false; } M_define_messages_left = ServerParam::instance().clangDefineWin(); M_meta_messages_left = ServerParam::instance().clangMetaWin(); M_advice_messages_left = ServerParam::instance().clangAdviceWin(); M_info_messages_left = ServerParam::instance().clangInfoWin(); M_del_messages_left = ServerParam::instance().clangDelWin(); M_rule_messages_left = ServerParam::instance().clangRuleWin(); M_msg_left_update_time = time; return true;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?