📄 worldmodel.cpp
字号:
return timeLastHearMessage ;}/*! This method sets the time of the last hear message. \param time hear message has arrived \return true when update was succesful */bool WorldModel::setTimeLastHearMessage( Time time ){ timeLastHearMessage = time; return true;}/*! This method returns the player number of the agent. The player number is the fixed number which is given by the server after initialization. \return player number of this player. */int WorldModel::getPlayerNumber( ) const{ return iPlayerNumber;}/*! This method sets the player number of the agent. This value is available in the conformation message sent by the soccerserver after the initialization. \param i new player number of the agent. \return bool indicating whether player number was set. */bool WorldModel::setPlayerNumber( int i ){ iPlayerNumber = i; return true;}/*! This method returns the side of the agent. Note that the side of the agent does not change after half time. \return side (SIDE_LEFT or SIDE_RIGHT) for agent */SideT WorldModel::getSide( ) const{ return sideSide;}/*! This method sets the side of the agent \param s (SIDE_LEFT or SIDE_RIGHT) for agent \return bool indicating whether update was succesful.*/bool WorldModel::setSide( SideT s ){ sideSide = s; m_iMultX = (getSide() == SIDE_LEFT ) ? 1 : -1 ; // set the draw info m_iMultY = (getSide() == SIDE_LEFT ) ? -1 : 1 ; // from Logger.C return true;}/*! This method returns the teamname of the agent in this worldmodel \return teamname for the agent in this worldmodel */const char* WorldModel::getTeamName( ) const{ return strTeamName ;}/*! This method sets the teamname of the agent. The maximum team name is MAX_TEAM_NAME_LENGTH as defined in Soccertypes.h. \param str teamname for the agent in this worldmodel \return bool indicating whether update was succesful.*/bool WorldModel::setTeamName( char * str ){ strcpy( strTeamName, str ); return true;}/*! This method returns the current playmode. This playmode is passed through by the referee. \return current playmode (see SoccerTypes for possibilities) */PlayModeT WorldModel::getPlayMode( ) const{ return playMode ;}/*! This method sets the play mode of the agent in this worldmodel \param pm for the agent in this worldmodel \return bool indicating whether update was succesful.*/bool WorldModel::setPlayMode( PlayModeT pm ){ playMode = pm; if( ( pm == PM_GOAL_KICK_LEFT && getSide() == SIDE_LEFT ) || ( pm == PM_GOAL_KICK_RIGHT && getSide() == SIDE_RIGHT ) ) setTimeLastCatch( getTimeLastSenseMessage() ); return true;}/*! This method returns the goal difference. When this value is below zero, the team of agent is behind, 0 means that the score is currently the same for both teams and a value higher than zero means that you're winning!. \return goal difference */int WorldModel::getGoalDiff( ) const{ return iGoalDiff;}/*!This method adds one goal to the goal difference. Call this method when your team has scored a goal \return new goal difference */int WorldModel::addOneToGoalDiff( ){ return ++iGoalDiff;}/*!This method subtracts one from the goal difference. Call this method when you're team has conceided a goal \return new goal difference */int WorldModel::subtractOneFromGoalDiff(){ return --iGoalDiff;}/*! This method returns the amount of commands c performed by the agent. This is supplied in the sense_body message. \param c CommandT of which number of commands should be returned. \return amount of commands c performed by the soccerserver. */int WorldModel::getNrOfCommands( CommandT c ) const{ return iCommandCounters[ (int) c ];}/*! This method sets the number of commands c that were performed by the agent. This is supplied in the sense_body message and can be used to check whether an action is actually performed by the soccer server, since the corresponding counter should be one higher than the previous sense_body message. When this is the case the corresponding index of the PerformedCommands array is set to true. \param c CommandT of which the number of commands should be set. \param i number of commands that are performed of this command \return bool indicating whether update was performed. */bool WorldModel::setNrOfCommands( CommandT c, int i ){ int iIndex = (int) c; // if counter is the same as before, no command is performed, otherwise it is performedCommands[iIndex] = ( iCommandCounters[iIndex] == i ) ? false : true; iCommandCounters [iIndex] = i; return true;}/*! This method returns the time the status of the ball was last checked (coach only). \return server cycle the status of the ball was last checked. */Time WorldModel::getTimeCheckBall( ) const{ return timeCheckBall;}/*! This method sets the time the ball was checked for the last time (coach only). \param time server time ball was checked. \return bool indicating whether update was succesfull. */bool WorldModel::setTimeCheckBall( Time time ){ timeCheckBall = time; return true;}/*! This method returns the status of the ball. This value is derived from the check_ball command that can only be used by the coach. The status of the ball corresponds to the server time returned by getTimeCheckBall. \return BallStatus status of the ball. */BallStatusT WorldModel::getCheckBallStatus( ) const{ return bsCheckBall;}/*! This method sets the status of the ball. The status of the ball corresponds to the server time returned by getTimeCheckBall. This method is only useful for the coach, since only he can sent a check_ball message. \return BallStatus status of the ball. */bool WorldModel::setCheckBallStatus( BallStatusT bs ){ bsCheckBall = bs; return true;}/*! This method returns a boolean indicating whether the synchronization method indicated we are ready. */bool WorldModel::getRecvThink( ){ return m_bRecvThink;}/*! This method returns the string that we want communicate. It can be set during the creation of the action. When the ActHandler sends its actions, it sends this string to the server. \return communication string. */char* WorldModel::getCommunicationString( ){ return m_strCommunicate;}/*! This methods returns the object type of the object that is currently listened to. This information is gathered from a sense message. When this agent says a message, we will definitely hear it. */ObjectT WorldModel::getObjectFocus( ){ return m_objFocus;}/*! This methods sets the object type of the object that is currently listened to. This information is gathered from a sense message. When this agent says a message, we will definitely hear it. */bool WorldModel::setObjectFocus( ObjectT obj ){ m_objFocus = obj; return true;}/*! This method sets the string that we want communicate. It can be set during the creation of the action. When the ActHandler sends its actions, it sends this string to the server. \return communication string. */bool WorldModel::setCommunicationString( char *str ){ strncpy( m_strCommunicate, str, MAX_SAY_MSG ); return true;}/*!This method starts an iteration over an object set g. This method will return the first ObjectT in an ObjectSetT that has a confidence higher than dConf. After this call use the method iterateObjectNext with the same argument to get the other objects that belong to this set. \param iIndex index that should be used in consecutive cycles. \param g ObjectSetT of which the ObjecT should be returned. \param dConf minimum confidence needed for ObjectT to be returned. \return ObjectT that is first in the set g. */ObjectT WorldModel::iterateObjectStart(int& iIndex,ObjectSetT g,double dConf, bool bForward){ iIndex = -1; return iterateObjectNext( iIndex, g, dConf, bForward );}/*!This method gets the next object in the iteration over an object set g. iterateObjectStart should have been called first. Only ObjectT with a confidence higher than dConf will be returned. When no more objects are available OBJECT_ILLEGAL is returned. \param iIndex same argument as was supplied to iterateObjectStart. \param g ObjectSetT of which the ObjecT should be returned. \param dConf minimum confidence needed for ObjectT to be returned. \return ObjectT that is next in the set g. */ObjectT WorldModel::iterateObjectNext(int& iIndex,ObjectSetT g, double dConf, bool bForward){ ObjectT o, objGoalie = OBJECT_TEAMMATE_1; bool bContinue = true; if( g == OBJECT_SET_TEAMMATES_NO_GOALIE ) objGoalie = getOwnGoalieType(); if( iIndex < 0 ) iIndex = (bForward==false) ? OBJECT_MAX_OBJECTS : -1 ; // when dConf is not specified it has the default value of -1.0, in this // case set it to the confidence threshold defined in PlayerSetting, but // only do this for dynamic objexts, not for flags, lines, etc. since all // should be returend. if( dConf == -1.0 && (g==OBJECT_SET_OPPONENTS || g==OBJECT_SET_PLAYERS || g==OBJECT_SET_TEAMMATES) ) dConf = PS->getPlayerConfThr(); int i = 0; if( bForward == true ) i = iIndex + 1; else i = iIndex - 1; bContinue = ( bForward == false ) ? ( i >= 0 ) : ( i < OBJECT_MAX_OBJECTS ); while( bContinue ) { o = (ObjectT) i; if( SoccerTypes::isInSet( o, g, objGoalie ) ) { if( getConfidence( o ) >= dConf ) { iIndex = i; return o; } else if( dConf == 1.0 && getTimeLastSeeMessage() == getTimeLastSeen( o )) { iIndex = i; // confidence of 1.0 can only be in same cycle as see return o; // message. Therefore first test should succeed normally; } // in cases where this method is called after see message, // but new sense has already arrived, confidence is lowered } // but we want to return object that was seen in last see // message; this compensates for those cases. if( bForward == true ) i++; else i--; bContinue = ( bForward == false ) ? ( i >= 0 ) :( i < OBJECT_MAX_OBJECTS); } return OBJECT_ILLEGAL;}/*!This method finsished the iteration. It should be called after iterateObjectNext has returned OBJECT_ILLEGAL indicating no more objects are available that satisfy the constraints. \param iIndex index of iteration */void WorldModel::iterateObjectDone( int &iIndex ){ iIndex = -1;}/*! This method returns the ObjectType of the agent. This is an ObjectT between OBJECT_TEAMMATE_1 and OBJECT_TEAMMATE_11 \return ObjectT that represent the type of the agent */ObjectT WorldModel::getAgentObjectType( ) const{ return agentObject.getType();}int WorldModel::getAgentIndex( ) const{ return SoccerTypes::getIndex( getAgentObjectType() );}/*! This method sets the ObjectType of the agent. This is an objectT between OBJECT_TEAMMATE_1 and OBJECT_TEAMMATE_11 \param ObjectT that represent the type of the agent \return bool indicating whether the update was succesful */bool WorldModel::setAgentObjectType( ObjectT o ){ agentObject.setType( o ); return true;}/*! This method returns the body angle relative to the neck of the agent. \return AngDeg representing the body angle relative to the neck */AngDeg WorldModel::getAgentBodyAngleRelToNeck( ) const{ return agentObject.getBodyAngleRelToNeck();}/*! This method returns the global neck angle of the agent in the world. \return global neck angle agent */AngDeg WorldModel::getAgentGlobalNeckAngle( ) const{ return agentObject.getGlobalNeckAngle( );}/*! This method returns the global body angle of the agent in the world. \return global body angle agent */AngDeg WorldModel::getAgentGlobalBodyAngle( ){ return agentObject.getGlobalBodyAngle( );}/*! This method returns the stamina information of the agent \return Stamina stamina of the agent */Stamina WorldModel::getAgentStamina( ) const{ return agentObject.getStamina();}/*! This method returns a TiredNessT value that indicates how tired the agent is. \return TiredNessT value that indicates how tired the agent is. */TiredNessT WorldModel::getAgentTiredNess( ) const{ return getAgentStamina().getTiredNess( SS->getRecoverDecThr(), SS->getStaminaMax() );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -