📄 worldmodel.cpp
字号:
/*********************************************************************************** In the name of Almighty ** ** WorldModel.cpp : Robocup 3D Soccer Simulation Team Zigorat ** (This team was previously named Gcyrus) ** ** Date: 03/20/2007 ** Author: Mahdi Hamdarsi ** Comments: This is the agents memory of outside world ** ***********************************************************************************//*! \file WorldModel.cpp<pre><b>File:</b> WorldModel.cpp<b>Project:</b> Robocup Soccer Simulation Team: Zigorat<b>Authors:</b> Mahdi Hamdarsi<b>Created:</b> 03/20/2007<b>Last Revision:</b> $ID$<b>Contents:</b> This is the agents memory of outside world<hr size=2><h2><b>Changes</b></h2><b>Date</b> <b>Author</b> <b>Comment</b>03/20/2007 Mahdi Initial version created</pre>*/#include "WorldModel.h"#include "Parse.h"#include "string.h"#include "Logger.h"#include "SoccerTypes.h"#include <iostream>using namespace std;/*****************************************************************************//********************** CLASS WORLDMODEL *************************************//*****************************************************************************//*! This constructor creates the world model, all variables are initialized by default values \param formations Formations set for the agent */WorldModel::WorldModel( Formations * formations ){ m_SimulatorTime = 0.0; m_SimulatorStep = 0.02; m_GameTime = 0.0; m_Side = SIDE_ILLEGAL; m_Ball.setMass(0.45); m_Ball.setRadius( 0.7 ); for(int i = 0; i < (MAX_FLAGS / 2); i++) { m_Flags[i].setID( (ObjectT)(i + (int)OBJECT_CORNER_L_B) ); m_Goals[i].setID( (ObjectT)(i + (int)OBJECT_GOAL_L_B ) ); } // Currently server does not send the actual field width and height m_GoalHeight = 0.75; // FIFA: 2.44 m_GoalWidth = 7.32; // FIFA: 7.00; m_FieldWidth = 0; // Random(64.0, 75.9) 0 is to let WorldModel itself derive field coordinates m_FieldLength = 0; // Random(100, 110.9) 0 is to let WorldModel itself derive field coordinates m_AgentNumber = 0; m_TeamName = ""; m_Formations = formations;}/*! Destructor Currently does nothing */WorldModel::~WorldModel(){}/*! This method logs all the data stored in agents memory to standard logging output */void WorldModel::logWorldModel(){ WMLogger << "Siumlator Time : " << getSimulatorTime() << endl; WMLogger << "Game Time: " << getTime() << endl; WMLogger << "Ball Position: (" << m_Ball.getPosition().getX() << ", "; WMLogger << m_Ball.getPosition().getY() << ", " << m_Ball.getPosition().getZ() << ")" << endl; WMLogger << "Agent Info: (Position: (" << getAgentPosition().getX() << ", " << getAgentPosition().getY() << ", "; WMLogger << getAgentPosition().getZ() << ") Direction: " << getAgentDirection() << " Phi: " << getAgentPhi() << endl; for(int i = 0; i < MAX_JOINTS; i++ ) { WMLogger << "Joint: " << SoccerTypes::getJointStr( (JointT)i ) << "; Axis 1: " << m_Joints[i].getAxis1(); WMLogger << ", Rate 1: " << m_Joints[i].getRate1() << ", Axis 2: " << m_Joints[i].getAxis2(); WMLogger << ", Rate 2: " << m_Joints[i].getRate2() << endl; } WMLogger << "-----------------------------------------------\n\n";}/**************************************************************************//************************ DIRECT RETRIEVAL ******************************//**************************************************************************//*! This methods return the current time of simulator which is updated every cycle and sent by the server \return double indicating current time */double WorldModel::getSimulatorTime() const{ return m_SimulatorTime;}/*! This methods return the current simulator step gap which is sent every cycle by the server \return double indicating current simulator step */double WorldModel::getSimulatorStep() const{ return m_SimulatorStep;}/*! This method returns the current time of game, which differs from the simulator time, and it is evaluated from the time which kick off button is pressed, not from the time which simulator started simulation */double WorldModel::getTime() const{ return m_GameTime;}/*! This method returns current cycle of simulation \return unsigned Current cycle of simulation that agent is aware */unsigned WorldModel::getCurrentCycle() const{ return m_CurrentCycle;}/*! This method returns current playmode of game \return PlayModeT Current game mode */PlayModeT WorldModel::getPlayMode() const{ return m_PlayMode;}/*! This method returns the side which agent is playing for \return SideT Side which agent is playing for */SideT WorldModel::getSide() const{ return m_Side;}/*! This method returns the goal width \return double Goal width */double WorldModel::getGoalWidth() const{ return m_GoalWidth; }/*! This method sets the goal width value \param value New value of goal width \return bool Indicating wheather update was succesful */bool WorldModel::setGoalWidth( const double & value ){ m_GoalWidth = value; return true;}/*! This method returns the goal height form the field \return double Goal height */double WorldModel::getGoalHeight() const{ return m_GoalHeight;}/*! This method sets the goal height value \param value New value of goal height \return bool Indicating wheather update was succesful */bool WorldModel::setGoalHeight( const double & value ){ m_GoalHeight = true; return true;}/*! This method returns the field height from the field \return double field height */double WorldModel::getFieldLength() const{ return m_FieldLength;}/*! This method sets a length for field, currently WorldModel updates this value each cycle that a server message is recieved based on values that server sent, so using this method is not required \param value New value of field length \return bool Indicating wheather update was succesful */bool WorldModel::setFieldLength( const double & value ){ if( m_FieldLength == 0 ) return false; m_FieldLength = value; return true;}/*! This method returns the field width \return double field width */double WorldModel::getFieldWidth() const{ return m_FieldWidth;}/*! This method sets a width for field, currently WorldModel updates this value each cycle that a server message is recieved based on values that server sent, so using this method is not required \param value New value of field width \return bool Indicating wheather update was succesful */bool WorldModel::setFieldWidth( const double & value ){ if( m_FieldWidth == 0 ) return false; m_FieldWidth = value; return true;}/*! This method returns the rectangle of field consisting of the point upper-left, to the point downer-right \return Rect rectangle of the field */Rect WorldModel::getFieldRect() const{ return Rect( getGlobalPositionFlag( OBJECT_CORNER_L_T ), getGlobalPositionFlag( OBJECT_CORNER_R_B ) );}/*! This method return current ball position as a VecPosition constant \return VecPsoition Current position of ball */VecPosition WorldModel::getBallPosition( ) const{ return m_Ball.getPosition();}/*! This method returns the global position of the given flag \param objFlag Flag to give to global position \return VecPosition Position of the given flag */VecPosition WorldModel::getGlobalPositionFlag(ObjectT objFlag) const{ VecPosition posReturn; switch( objFlag ) { case OBJECT_CORNER_L_B: posReturn.setVecPosition( -m_FieldLength / 2.0, -m_FieldWidth / 2.0 ); break; case OBJECT_CORNER_L_T: posReturn.setVecPosition( -m_FieldLength / 2.0, m_FieldWidth / 2.0 ); break; case OBJECT_CORNER_R_B: posReturn.setVecPosition( m_FieldLength / 2.0, -m_FieldWidth / 2.0 ); break; case OBJECT_CORNER_R_T:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -