📄 monitor.cpp
字号:
} return true;}boolMonitor::dispfoul( const char * command ){ // foul or drop_ball int x, y, side; if ( std::sscanf( command, "(dispfoul %d %d %d)", &x, &y, &side ) != 3 ) { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; } double real_x = x / SHOWINFO_SCALE; double real_y = y / SHOWINFO_SCALE; if ( static_cast< Side >( side ) == NEUTRAL ) { M_stadium.referee_drop_ball( real_x, real_y, static_cast< Side >( side ) ); } else { M_stadium.referee_get_foul( real_x, real_y, static_cast< Side >( side ) ); } return true;}boolMonitor::dispplayer( const char * command ){ // a player is given new position by the monitor int side, unum; int x, y, a; if ( std::sscanf( command, "(dispplayer %d %d %d %d %d)", &side, &unum, &x, &y, &a ) != 5 ) { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; } double real_x = x / SHOWINFO_SCALE; double real_y = y / SHOWINFO_SCALE; double angle = Deg2Rad( a ); PVector vel( 0.0, 0.0 ); return M_stadium.movePlayer( static_cast< Side >( side ), unum, PVector( real_x, real_y ), &angle, &vel );}boolMonitor::dispdiscard( const char * command ){ // a player is discarded by the monitor int side = 0, unum = 0; if ( std::sscanf( command, "(dispdiscard %d %d)", &side, &unum ) != 2 ) { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; } M_stadium.discard_player( static_cast< Side >( side ), unum ); return true;}boolMonitor::compression( const char * command ){ int level = 0; if ( std::sscanf( command, "(compression %d)", &level ) != 1 ) { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; }#ifdef HAVE_LIBZ if ( level > 9 ) { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; }#ifdef HAVE_SSTREAM std::ostringstream reply; reply << "(ok compression " << level << ")"; sendMsg( MSG_BOARD, reply.str().c_str() );#else std::ostrstream reply; reply << "(ok compression " << level << ")" << std::ends; sendMsg( MSG_BOARD, reply.str() ); reply.freeze( false );#endif setCompressionLevel( level ); return true;#else sendMsg( MSG_BOARD, "(warning compression_unsupported)" ); return false;#endif}boolMonitor::coach_change_mode( const char * command ){ char new_mode[128]; if ( std::sscanf( command, "(change_mode %127[-0-9a-zA-Z.+*/?<>_])", new_mode ) != 1 ) { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; } PlayMode mode_id = play_mode_id( new_mode ); if ( mode_id == PM_Null ) { sendMsg( MSG_BOARD, "(error illegal_mode)" ); return false; } M_stadium.change_play_mode( mode_id ); sendMsg( MSG_BOARD, "(ok change_mode)" ); return true;}boolMonitor::coach_move( const char * command ){ char obj[128]; double x = 0.0, y = 0.0, ang = 0.0, velx = 0.0, vely = 0.0; int n = std::sscanf( command, " (move (%127[^)]) %lf %lf %lf %lf %lf ) ", obj, &x, &y, &ang, &velx, &vely ); if ( n < 3 || std::isnan( x ) != 0 || std::isnan( y ) != 0 || std::isnan( ang ) != 0 || std::isnan( velx ) != 0 || std::isnan( vely ) != 0 ) { sendMsg( MSG_BOARD, "(error illegal_object_form)" ); return false; } std::string obj_name = "("; obj_name += obj; obj_name += ')'; if ( obj_name == BALL_NAME ) { M_stadium.clearBallCatcher(); if ( n == 3 || n == 4 ) { M_stadium.set_ball( NEUTRAL, PVector( x, y ) ); } else if ( n == 6 ) { M_stadium.set_ball( NEUTRAL, PVector( x, y ), PVector( velx, vely ) ); } else { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; } } else { char teamname[128]; int unum = 0; if ( std::sscanf( obj_name.c_str(), PLAYER_NAME_FORMAT, teamname, &unum ) != 2 || unum < 1 || MAX_PLAYER < unum ) { sendMsg( MSG_BOARD, "(error illegal_object_form)" ); return false; } Side side = ( M_stadium.teamLeft().name() == teamname ? LEFT : M_stadium.teamRight().name() == teamname ? RIGHT : NEUTRAL ); PVector pos( x, y ); PVector vel( velx, vely ); ang = Deg2Rad( rcss::bound( ServerParam::instance().minMoment(), ang, ServerParam::instance().maxMoment() ) ); if ( n == 3 ) { M_stadium.movePlayer( side, unum, pos, NULL, NULL ); } else if ( n == 4 ) { M_stadium.movePlayer( side, unum, pos, &ang, NULL ); } else if ( n == 6 ) { M_stadium.movePlayer( side, unum, pos, &ang, &vel ); } else { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; } } sendMsg( MSG_BOARD, "(ok move)" ); return true;}boolMonitor::coach_recover(){ M_stadium.recoveryPlayers(); sendMsg( MSG_BOARD, "(ok recover)" ); return true;}boolMonitor::coach_check_ball(){#ifdef HAVE_SSTREAM std::ostringstream ost;#else std::ostrstream ost;#endif static const char * s_ball_pos_info_str[] = BALL_POS_INFO_STRINGS; BallPosInfo info = M_stadium.ballPosInfo(); ost << "(ok check_ball " << M_stadium.time() << " " ; ost << s_ball_pos_info_str[info] << ")"; ost << std::ends;#ifdef HAVE_SSTREAM sendMsg( MSG_BOARD, ost.str().c_str() );#else ost << std::ends; sendMsg( MSG_BOARD, ost.str() ); ost.freeze( false );#endif return true;}boolMonitor::coach_change_player_type( const char * command ){ char teamname[128]; int unum, player_type; if ( std::sscanf( command, "(change_player_type %127s %d %d)", teamname, &unum, &player_type ) != 3 ) { sendMsg( MSG_BOARD, "(error illegal_command_form)" ); return false; } const Team * team = NULL; if ( M_stadium.teamLeft().name() == teamname ) { team = &( M_stadium.teamLeft() ); } else if ( M_stadium.teamRight().name() == teamname ) { team = &( M_stadium.teamRight() ); } if ( team == NULL ) { sendMsg( MSG_BOARD, "(warning no_team_found)" ); return false; } if ( player_type < 0 || player_type >= PlayerParam::instance().playerTypes() ) { sendMsg( MSG_BOARD, "(error out_of_range_player_type)" ); return false; } 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 ) { sendMsg( MSG_BOARD, "(warning no_such_player)" ); return false; } M_stadium.substitute( player, player_type ); char buf[64]; snprintf( buf, 64, "(ok change_player_type %s %d %d)", teamname, unum, player_type ); sendMsg( MSG_BOARD, buf ); return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -