📄 soccertypes.c
字号:
/*! This method determines whether object o is a player without checking whether its number or side is available. \param o an object type \return bool indicating whether o is a known player (true) or not (false) */bool SoccerTypes::isPlayer( ObjectT o ){ return isKnownPlayer( o ) || o == OBJECT_TEAMMATE_UNKNOWN || o == OBJECT_OPPONENT_UNKNOWN || o == OBJECT_PLAYER_UNKNOWN;}/*! This method determines whether object o is a known player, thus containing a number \param o an object type \return bool indicating whether o is a known player (true) or not (false) */bool SoccerTypes::isKnownPlayer( ObjectT o ){ return (o >= OBJECT_OPPONENT_1 && o <= OBJECT_OPPONENT_11) || (o >= OBJECT_TEAMMATE_1 && o <= OBJECT_TEAMMATE_11);}/*! This method determines whether object o is a goalie = teammate number is 1 (for now) \param o an object type \return bool indicating whether o is a goalie (true) or not (false) */bool SoccerTypes::isGoalie( ObjectT o ){ return o == OBJECT_TEAMMATE_1 || o == OBJECT_OPPONENT_1;}/*! This method determines whether object o is the ball \param o an object type \return bool indicating whether o is the ball (true) or not (false) */bool SoccerTypes::isBall( ObjectT o ){ return o == OBJECT_BALL;}/*! This method returns the object representing the own goal \param s own side \return object of the own goal, OBJECT_ILLEGAL when s is SIDE_ILLEGAL*/ObjectT SoccerTypes::getOwnGoal( SideT s ){ if( SIDE_LEFT == s ) return OBJECT_GOAL_L; else if( SIDE_RIGHT == s ) return OBJECT_GOAL_R; cerr << "(SoccerTypes::isOwnGoal) Wrong side argument" << endl; return OBJECT_ILLEGAL;}/*! This method returns the object representing the opponent goal \param s own side \return object of the goal opponent, OBJECT_ILLEGAL when s is SIDE_ILLEGAL*/ObjectT SoccerTypes::getGoalOpponent( SideT s ){ if( SIDE_LEFT == s ) return OBJECT_GOAL_R; else if( SIDE_RIGHT == s ) return OBJECT_GOAL_L; cerr << "(SoccerTypes::isGoalOpponent) Wrong side argument" << endl; return OBJECT_ILLEGAL;}/*! This method returns the global position on the field of a flag (a goal is also a flag). Since the global positions for both teams differ, the side of the agent team is also needed. Note that the global positions of the flags will not change in the second half. \param o flag of which global position should be determined \param s side of your team. \param dGoalWidth for some flags the goalWidth is necessary (default 14.02) \return VecPosition representing the global position. x and y value are both UnknownDoubleValue when o is not a flag or goal. */VecPosition SoccerTypes::getGlobalPositionFlag( ObjectT o, SideT s, double dGoalWidth ){ VecPosition pos; if( !(isFlag(o) || isGoal(o)) ) return VecPosition(UnknownDoubleValue, UnknownDoubleValue); switch( o ) // for every object the global position is entered { case OBJECT_GOAL_L: pos.setVecPosition( -PITCH_LENGTH/2.0, 0.0 ); break; case OBJECT_GOAL_R: pos.setVecPosition( PITCH_LENGTH/2.0, 0.0 ); break; case OBJECT_FLAG_L_T: pos.setVecPosition( -PITCH_LENGTH/2.0, -PITCH_WIDTH/2.0 ); break; case OBJECT_FLAG_T_L_50: pos.setVecPosition( -50.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break; case OBJECT_FLAG_T_L_40: pos.setVecPosition( -40.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break; case OBJECT_FLAG_T_L_30: pos.setVecPosition( -30.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break; case OBJECT_FLAG_T_L_20: pos.setVecPosition( -20.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break; case OBJECT_FLAG_T_L_10: pos.setVecPosition( -10.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break; case OBJECT_FLAG_T_0: pos.setVecPosition( 0.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break; case OBJECT_FLAG_C_T: pos.setVecPosition( 0.0, -PITCH_WIDTH/2.0); break; case OBJECT_FLAG_T_R_10: pos.setVecPosition( 10.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break; case OBJECT_FLAG_T_R_20: pos.setVecPosition( 20.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break; case OBJECT_FLAG_T_R_30: pos.setVecPosition( 30.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break; case OBJECT_FLAG_T_R_40: pos.setVecPosition( 40.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break; case OBJECT_FLAG_T_R_50: pos.setVecPosition( 50.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break; case OBJECT_FLAG_R_T: pos.setVecPosition( PITCH_LENGTH/2.0, -PITCH_WIDTH/2.0 ); break; case OBJECT_FLAG_R_T_30: pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, -30.0 ); break; case OBJECT_FLAG_R_T_20: pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, -20.0 ); break; case OBJECT_FLAG_R_T_10: pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, -10.0 ); break; case OBJECT_FLAG_G_R_T: pos.setVecPosition( PITCH_LENGTH/2.0, -dGoalWidth/2.0 ); break; case OBJECT_FLAG_R_0: pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, 0.0 ); break; case OBJECT_FLAG_G_R_B: pos.setVecPosition( PITCH_LENGTH/2.0, dGoalWidth/2.0 ); break; case OBJECT_FLAG_R_B_10: pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, 10.0 ); break; case OBJECT_FLAG_R_B_20: pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, 20.0 ); break; case OBJECT_FLAG_R_B_30: pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, 30.0 ); break; case OBJECT_FLAG_R_B: pos.setVecPosition( PITCH_LENGTH/2.0, PITCH_WIDTH/2.0 ); break; case OBJECT_FLAG_B_R_50: pos.setVecPosition( 50.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_B_R_40: pos.setVecPosition( 40.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_B_R_30: pos.setVecPosition( 30.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_B_R_20: pos.setVecPosition( 20.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_B_R_10: pos.setVecPosition( 10.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_C_B: pos.setVecPosition( 0.0, PITCH_WIDTH/2.0 ); break; case OBJECT_FLAG_B_0: pos.setVecPosition( 0.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_B_L_10: pos.setVecPosition( -10.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_B_L_20: pos.setVecPosition( -20.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_B_L_30: pos.setVecPosition( -30.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_B_L_40: pos.setVecPosition( -40.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_B_L_50: pos.setVecPosition( -50.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break; case OBJECT_FLAG_L_B: pos.setVecPosition( -PITCH_LENGTH/2.0, PITCH_WIDTH/2.0 ); break; case OBJECT_FLAG_L_B_30: pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, 30.0 ); break; case OBJECT_FLAG_L_B_20: pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, 20.0 ); break; case OBJECT_FLAG_L_B_10: pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, 10.0 ); break; case OBJECT_FLAG_G_L_B: pos.setVecPosition( -PITCH_LENGTH/2.0, dGoalWidth/2.0 ); break; case OBJECT_FLAG_L_0: pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, 0.0 ); break; case OBJECT_FLAG_G_L_T: pos.setVecPosition( -PITCH_LENGTH/2.0, -dGoalWidth/2.0 ); break; case OBJECT_FLAG_L_T_10: pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, -10.0 ); break; case OBJECT_FLAG_L_T_20: pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, -20.0 ); break; case OBJECT_FLAG_L_T_30: pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, -30.0 ); break; case OBJECT_FLAG_P_L_T: pos.setVecPosition( -PITCH_LENGTH/2.0 + PENALTY_AREA_LENGTH, - PENALTY_AREA_WIDTH/2.0 ); break; case OBJECT_FLAG_P_L_C: pos.setVecPosition( -PITCH_LENGTH/2.0 + PENALTY_AREA_LENGTH, 0.0 ); break; case OBJECT_FLAG_P_L_B: pos.setVecPosition( -PITCH_LENGTH/2.0 + PENALTY_AREA_LENGTH, PENALTY_AREA_WIDTH/2.0 ); break; case OBJECT_FLAG_P_R_T: pos.setVecPosition( PITCH_LENGTH/2.0 - PENALTY_AREA_LENGTH, -PENALTY_AREA_WIDTH/2.0 ); break; case OBJECT_FLAG_P_R_C: pos.setVecPosition( PITCH_LENGTH/2.0 - PENALTY_AREA_LENGTH, 0.0 ); break; case OBJECT_FLAG_P_R_B: pos.setVecPosition( PITCH_LENGTH/2.0 - PENALTY_AREA_LENGTH, PENALTY_AREA_WIDTH/2.0 ); break; case OBJECT_FLAG_C: pos.setVecPosition( 0.0 , 0.0 ); break; default: cerr << "(SoccerTypes::getGlobalPositionObject) wrong objecttype! " << (int)o << endl ; } if( s == SIDE_RIGHT ) // change side for team on the right side. pos.setVecPosition( -pos.getX(), -pos.getY() ); return pos;}/*! This method returns the global angle of a lines on the field. The global angle differs for the left and right side. For both teams the line behind the opponent goal is seen with global angle 0. Only for the left team this is the right line and for the right team this is the left line. \param o one of the four line objects \param s side on which the team was started \return AngDeg global angle of this line. */AngDeg SoccerTypes::getGlobalAngleLine( ObjectT o , SideT s ){ AngDeg angle = UnknownAngleValue; switch( o ) { case OBJECT_LINE_L: angle = 180.0; break; case OBJECT_LINE_R: angle = 0.0; break; case OBJECT_LINE_T: angle = -90.0; break; case OBJECT_LINE_B: angle = 90.0; break; default: cerr << "(SoccerTypes::getGlobalAngleLine) wrong objecttype! " << (int)o << endl; return UnknownAngleValue; } if( s == SIDE_RIGHT ) angle += 180; return VecPosition::normalizeAngle( angle );}/*! This method returns the string representation of a PlayModeT as is used in the Robocup Soccer Simulation and also said by the referee. \param pm PlayModeT which should be converted \return pointer to the string (enough memory has to be allocated) */char* SoccerTypes::getPlayModeStr( PlayModeT pm ){ switch( pm ) { case PM_BEFORE_KICK_OFF: return "before_kick_off"; case PM_KICK_OFF_LEFT: return "kick_off_l"; case PM_KICK_OFF_RIGHT: return "kick_off_r"; case PM_KICK_IN_LEFT: return "kick_in_l"; case PM_KICK_IN_RIGHT: return "kick_in_r"; case PM_CORNER_KICK_LEFT: return "corner_kick_l"; case PM_CORNER_KICK_RIGHT: return "corner_kick_r"; case PM_GOAL_KICK_LEFT: return "goal_kick_l"; case PM_GOAL_KICK_RIGHT: return "goal_kick_r"; case PM_GOAL_LEFT: return "goal_r"; case PM_GOAL_RIGHT: return "goal_l"; case PM_FREE_KICK_FAULT_LEFT: return "free_kick_fault_l"; case PM_FREE_KICK_FAULT_RIGHT: return "free_kick_fault_r"; case PM_FREE_KICK_LEFT: return "free_kick_l"; case PM_FREE_KICK_RIGHT: return "free_kick_r"; case PM_BACK_PASS_LEFT: return "back_pass_l"; case PM_BACK_PASS_RIGHT: return "back_pass_r"; case PM_OFFSIDE_LEFT: return "offside_l"; case PM_OFFSIDE_RIGHT: return "offside_l"; case PM_PLAY_ON: return "play_on"; case PM_FROZEN: return "play_off"; case PM_QUIT: return "quit"; case PM_ILLEGAL: default: return NULL; }}/*! This method returns the play mode associated with a string. \param str representing the play mode \return PlayModeT of string, PM_ILLEGAL if it is not recognized */PlayModeT SoccerTypes::getPlayModeFromStr( char* str ){ // all play modes are sent as referee message, so get referee message // and look up the associated play mode return getPlayModeFromRefereeMessage( getRefereeMessageFromStr( str ) );}/*! This method returns the play mode from the referee message. \param rm RefereeMessage that contains the play mode \return PlayModeT of RefereeMessage, PM_ILLEGAL if it is not recognized */PlayModeT SoccerTypes::getPlayModeFromRefereeMessage( RefereeMessageT rm ){ switch( rm ) { case REFC_BEFORE_KICK_OFF: return PM_BEFORE_KICK_OFF; case REFC_KICK_OFF_LEFT: return PM_KICK_OFF_LEFT; case REFC_KICK_OFF_RIGHT: return PM_KICK_OFF_RIGHT; case REFC_KICK_IN_LEFT: return PM_KICK_IN_LEFT; case REFC_KICK_IN_RIGHT: return PM_KICK_IN_RIGHT; case REFC_CORNER_KICK_LEFT: return PM_CORNER_KICK_LEFT; case REFC_CORNER_KICK_RIGHT: return PM_CORNER_KICK_RIGHT; case REFC_GOAL_KICK_LEFT: return PM_GOAL_KICK_LEFT; case REFC_GOAL_KICK_RIGHT: return PM_GOAL_KICK_RIGHT; case REFC_FREE_KICK_LEFT: return PM_FREE_KICK_LEFT; case REFC_FREE_KICK_RIGHT: return PM_FREE_KICK_RIGHT; case REFC_FREE_KICK_FAULT_LEFT: return PM_FREE_KICK_FAULT_LEFT; case REFC_FREE_KICK_FAULT_RIGHT: return PM_FREE_KICK_FAULT_RIGHT; case REFC_BACK_PASS_LEFT: return PM_BACK_PASS_LEFT; case REFC_BACK_PASS_RIGHT: return PM_BACK_PASS_RIGHT; case REFC_FOUL_LEFT: return PM_FREE_KICK_RIGHT; case REFC_FOUL_RIGHT: return PM_FREE_KICK_LEFT; case REFC_OFFSIDE_LEFT: return PM_OFFSIDE_LEFT; case REFC_OFFSIDE_RIGHT: return PM_OFFSIDE_RIGHT; case REFC_GOAL_LEFT: return PM_GOAL_LEFT; case REFC_GOAL_RIGHT: return PM_GOAL_RIGHT; case REFC_PLAY_ON: return PM_PLAY_ON; case REFC_FROZEN: return PM_FROZEN; case REFC_TIME_OVER: return PM_TIME_OVER; case REFC_QUIT: return PM_QUIT; default: return PM_ILLEGAL; }}/*! This method returns the string representation of a RefereeMessageT as is used in th
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -