📄 objects.cpp
字号:
\param os output stream to which information is written. */void BallObject::show( ostream& os){ char buf[MAX_TEAM_NAME_LENGTH]; SoccerTypes::getObjectStr( buf, objectType, DEFAULT_TEAM_NAME ); os << buf << "r: " << posRelative.getMagnitude() << " phi: " << posRelative.getDirection() << " vel: " << vecGlobalVelocity << " " << timeGlobalVelocity << " rel: " << posRelative << ", " << timeRelativePosition << " global: " << posGlobal << ", " << timeGlobalPosition << ", changes: " << dRelativeDistanceChange << ", " << dRelativeAngleChange << " last seen:" << timeLastSeen << " globalposderived: " << timeGlobalPosDerivedFromSee << "\n";}/*****************************************************************************//********************* CLASS AGENTOBJECT *************************************//*****************************************************************************//*! This is the constructor for the class AgentObject and initializes the variables with the AgentObject. This the class that contains information about the agent itself. \param dStaminaMax maximum stamina for this agent (default 4000.0) */AgentObject::AgentObject( double dStaminaMax ):PlayerObject( ){ viewAngle = VA_NORMAL; viewQuality = VQ_HIGH; stamina.setStamina ( dStaminaMax ); stamina.setEffort ( 1.0 ); stamina.setRecovery( 1.0 ); velSpeedRelToNeck.setVecPosition( 0.0, 0.0 ); angGlobalNeckAngle = UnknownAngleValue; angBodyAngleRelToNeck = UnknownAngleValue;}/*! This methods prints the information about this AgentObject to the specified output stream. The default team name is used as the name. \param os output stream to which information is written. */void AgentObject::show( ostream& os ){ show( DEFAULT_TEAM_NAME, os );}/*! This methods prints the information about this AgentObject to the specified output stream. The specified team name is used as the name \param strTeamName team name for this agent. \param os output stream to which information is written. */void AgentObject::show( const char * strTeamName, ostream & os ){ char buf[MAX_TEAM_NAME_LENGTH]; SoccerTypes::getObjectStr( buf, objectType, strTeamName ); os << buf << " (global(" << posGlobal << ", " << timeGlobalPosition << ") (vel(" << vecGlobalVelocity << ", " << timeGlobalVelocity << ") (angles(n:" << angGlobalNeckAngle << ", b:" << angBodyAngleRelToNeck << ") "; stamina.show( os );}/*! This method returns the view angle of this PlayerObject. The view angle equals VA_NARROW, VA_NORMAL, VA_WIDE or VA_ILLEGAL. \return view angle of this PlayerObject */ViewAngleT AgentObject::getViewAngle() const{ return viewAngle;}/*! This method returns the difference between the predicted global position of the agent and the actual derived global position. This difference can be used in determining the actual movement of other objects since the noise caused by the difference in the global position of the agent is then filtered out. */VecPosition AgentObject::getPositionDifference() const{ return posPositionDifference;}/*! This method sets the position difference between the derived global position from the previous cycle information and the global position from the latest see message. \param p new position difference \return bool indicating whether the update was succesfull. */bool AgentObject::setPositionDifference( VecPosition p ){ posPositionDifference = p; return true;}/*! This method sets the view angle of this AgentObject. \param v new view angle (VA_NARROW, VA_NORMAL, VA_WIDE or VA_ILLEGAL) \return bool indicating whether value was set */bool AgentObject::setViewAngle( ViewAngleT v ){ viewAngle = v; return true;}/*! This method returns the view quality of this AgentObject. The view angle equals VQ_LOW, VQ_HIGH, or VQ_ILLEGAL. \return view quality of this AgentObject */ViewQualityT AgentObject::getViewQuality() const{ return viewQuality;}/*! Set the view quality of this AgentObject. \param v new view quality (VQ_LOW, VQ_HIGH, VQ_ILLEGAL) \return bool indicating whether value was set */bool AgentObject::setViewQuality( ViewQualityT v ){ viewQuality = v; return true;}/*! This method returns the Stamina of the AgentObject. \return stamina from the agent. */Stamina AgentObject::getStamina( ) const{ return stamina;}/*! This method sets the stamina of this AgentObject. \param sta new stamina for this AgentObject \return bool indicating whether value was set */bool AgentObject::setStamina( Stamina sta ){ stamina = sta; return true ;}/*! This method returns the velocity (speed and direction) of this AgentObject. This information is directly availablefrom the sense message, in which the speed factor and the angle of this speed (relative to the neck) are given. \return velocity agent relative to the neck. */VecPosition AgentObject::getSpeedRelToNeck( ) const{ return velSpeedRelToNeck;}/*! This method sets the velocity (speed and direction) of this AgentObject. This information comes directly from the sense message. \param v new velocity for this agentobject \return bool indicating whether value was set */bool AgentObject::setSpeedRelToNeck( VecPosition v ){ velSpeedRelToNeck = v; return true;}/*! This method sets the global neck angle for this AgentObject. \param ang value for the global neck angle. \return bool indicating whether value was set */bool AgentObject::setGlobalNeckAngle( AngDeg ang ){ angGlobalNeckAngle= ang; angGlobalBodyAngle= VecPosition::normalizeAngle(getBodyAngleRelToNeck()+ang); return true ;}/*! This method returns the relative angle of the body to the neck of this AgentObject. Example: global angle neck is 90 degrees and global body angle is 0, means that relative angle of body to neck is -90 degrees. \return relative body angle to the neck */AngDeg AgentObject::getBodyAngleRelToNeck( ) const{ return angBodyAngleRelToNeck;}/*! This method sets the relative body angle to the neck for this AgentObject. \param ang relative body angle to the neck \return bool indicating whether value was set */bool AgentObject::setBodyAngleRelToNeck( AngDeg ang ){ angBodyAngleRelToNeck = ang;// angGlobalBodyAngle = VecPosition::normalizeAngle(getGlobalNeckAngle()+ang); return true;}/*! This method sets whether it is allowed to move the arm of the agent. */bool AgentObject::getArmMovable( ) const{ return m_bArmMovable;}/*! This method returns whether it is allowed to move the arm of the agent. */bool AgentObject::setArmMovable( bool b ) { m_bArmMovable = b; return true;}/*! This method returns the numer of cycles it will take the arm to expire. In case of zero, the arm doesn't point anymore and the other players won't see the arm pointing anymore. */int AgentObject::getArmExpires( ) const{ return m_iArmExpires;}/*! This method sets the numer of cycles it will take the arm to expire. In case of zero, the arm doesn't point anymore and the other players won't see the arm pointing anymore. */bool AgentObject::setArmExpires( int i ){ m_iArmExpires = i; return true;}/*! This method returns the global position to which the arm points. If 'getArmExpires' returns zero, it means that the arm doesn't point anymore and this value is invalid. */VecPosition AgentObject::getGlobalArmPosition( ) const{ return m_posGlobalArm;}/*! This method sets the global position to which the arm points. */bool AgentObject::setGlobalArmPosition ( VecPosition v ){ m_posGlobalArm = v; return true;}/*! This method returns the number of cycles it will take the tackle to expire. In case of 0 a tackle command can be issued. */int AgentObject::getTackleExpires( ) const{ return m_iTackleExpires;}/*! This method sets the number of cycles it will take the tackle to expire. In case of 0 a tackle command can be issued. */bool AgentObject::setTackleExpires( int i ){ m_iTackleExpires = i; return true;}/*****************************************************************************//********************* CLASS STAMINA *****************************************//*****************************************************************************//*! This is the constructor for this class. It sets the stamina, effort and recovery on the supplied values. \param dSta new stamina value (default 4000.0) \param dEff new effort value (default 1.0) \param dRec new recovery value (default 1.0)*/Stamina::Stamina( double dSta, double dEff, double dRec ){ setStamina ( dSta ); setEffort ( dEff ); setRecovery( dRec );}/*! This method prints the stamina values (stamina, effort and recovery) to the specified output stream. \param os output stream */void Stamina::show( ostream & os){ os << "(sta:" << m_dStamina << ", eff:" << m_dEffort << ", rec: " << m_dRecovery << ")" << "\n";}/*! This method returns a TiredNessT enumeration that indicates how tired this associated agent with this Stamina value is. */TiredNessT Stamina::getTiredNess( double dRecDecThr, double dStaminaMax ){ double dStaDiffWithThr = getStamina() - dRecDecThr * dStaminaMax;// cerr << getStamina() << " " << dStaminaMax << // " " << dRecDecThr << " " << dStaDiffWithThr << endl; if( dStaDiffWithThr < 100 ) return TIREDNESS_TERRIBLE; else if( dStaDiffWithThr < 750 ) return TIREDNESS_VERY_BAD; else if( dStaDiffWithThr < 1500 ) return TIREDNESS_BAD; else if( dStaDiffWithThr < 2250 ) return TIREDNESS_AVERAGE; return TIREDNESS_GOOD;}/*! This method returns the current stamina value. \return current stamina value (>0) */double Stamina::getStamina() const{ return m_dStamina;}/*! This method sets the stamina value. This value should be positive, otherwise the value is set to 0 and false is returned. \param d new stamina value \return bool indicating whether value was set. */bool Stamina::setStamina( double d ){ if( d < 0.0 ) { m_dStamina = 0.0; return false; } else m_dStamina = d; return true;}/*! This method returns the effort. The effort denotes the percentage of the power in a dash that is actually used. Normally this is 1.0 (100%), but when it comes below a threshold, it decreases. It will again rise when stamina becomes higher than a certain threshold defined in ServerSettings. \return effort value between 0 and 1 */double Stamina::getEffort() const{ return m_dEffort;}/*! This method sets the effort value. This value should be between 0 and 1, otherwise the value is set to the closest value in this interval (0 for negative values, 1 for higher values) and false is returned. \param d new effort value (0..1) \return bool indicating whether value was set. */bool Stamina::setEffort( double d ){ if( d < 0.0 ) { m_dEffort = 0.0; return false; } else if( d > 1.0 ) { m_dEffort = 1.0; return false; } else m_dEffort = d; return true;}/*! This method returns the recovery. Recovery denotes the percentage of the stamina increase that is added to the stamina every cycle. If recovery is 1.0 all of the increase of stamina is added to the current stamina. When stamina becomes below a certain threshold defined in ServerSettings, the recovery is decreased. It can never increase! \return recovery value between 0 and 1 */double Stamina::getRecovery() const{ return m_dRecovery;}/*! This method sets the recovery value. This value should be between 0 and 1, otherwise the value is set to the closest value in this interval (0 for negative values, 1 for higher values) and false is returned. \param d new recovery value (0..1) \return bool indicating whether value was set. */bool Stamina::setRecovery( double d ){ if( d < 0.0 ) { m_dRecovery = 0.0; return false; } else if( d > 1.0 ) { m_dRecovery = 1.0; return false; } else m_dRecovery = d; return true;}/*****************************************************************************//********************* TESTING PURPOSES **************************************//*****************************************************************************//*int main( void ){ PlayerObject p(); BallObject b(); FixedObject s(); cout << p.getDeltaRelativeAngle() << "\n" << b.getDeltaRelativeDistance() << "\n" << p.getTimeRelativeDistance() << "\n"; return 0;}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -