00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gamestateitem.h"
00023 #include "gamestateaspect.h"
00024 #include <soccer/soccerbase/soccerbase.h>
00025
00026 using namespace oxygen;
00027 using namespace std;
00028
00029 GameStateItem::GameStateItem() : MonitorItem()
00030 {
00031 ResetSentFlags();
00032 }
00033
00034 GameStateItem::~GameStateItem()
00035 {
00036 }
00037
00038 void GameStateItem::ResetSentFlags()
00039 {
00040 mSentLeftTeamname = false;
00041 mSentRightTeamname = false;
00042 mLastHalf = GH_NONE;
00043 mLastLeftScore = -1;
00044 mLastRightScore = -1;
00045 mLastPlayMode = PM_NONE;
00046 mSentFlags = false;
00047 }
00048
00049 void GameStateItem::PutFloatParam(const string& name, PredicateList& pList)
00050 {
00051 float value;
00052 if (! SoccerBase::GetSoccerVar(*this,name,value))
00053 {
00054 return;
00055 }
00056
00057 Predicate& pred = pList.AddPredicate();
00058 pred.name = name;
00059 pred.parameter.AddValue(value);
00060 }
00061
00062 void GameStateItem::GetInitialPredicates(PredicateList& pList)
00063 {
00064 ResetSentFlags();
00065
00066
00067 PutFloatParam("FieldLength",pList);
00068 PutFloatParam("FieldWidth",pList);
00069 PutFloatParam("FieldHeight",pList);
00070 PutFloatParam("GoalWidth",pList);
00071 PutFloatParam("GoalDepth",pList);
00072 PutFloatParam("GoalHeight",pList);
00073 PutFloatParam("BorderSize",pList);
00074 PutFloatParam("FreeKickDistance",pList);
00075 PutFloatParam("WaitBeforeKickOff",pList);
00076
00077
00078 PutFloatParam("AgentMass",pList);
00079 PutFloatParam("AgentRadius",pList);
00080 PutFloatParam("AgentMaxSpeed",pList);
00081
00082
00083 PutFloatParam("BallRadius",pList);
00084 PutFloatParam("BallMass",pList);
00085
00086
00087 PutFloatParam("RuleGoalPauseTime",pList);
00088 PutFloatParam("RuleKickInPauseTime",pList);
00089 PutFloatParam("RuleHalfTime",pList);
00090
00091
00092 Predicate& pred = pList.AddPredicate();
00093 pred.name = "play_modes";
00094
00095 for (int i=0; i<PM_NONE; ++i)
00096 {
00097 pred.parameter.AddValue
00098 (SoccerBase::PlayMode2Str(static_cast<TPlayMode>(i)));
00099 }
00100 }
00101
00102 void GameStateItem::GetPredicates(PredicateList& pList)
00103 {
00104 if (mGameState.get() == 0)
00105 {
00106 return;
00107 }
00108
00109 Predicate& timePred = pList.AddPredicate();
00110 timePred.name = "time";
00111 timePred.parameter.AddValue(mGameState->GetTime());
00112
00113 if (! mSentLeftTeamname)
00114 {
00115
00116 string name = mGameState->GetTeamName(TI_LEFT);
00117 if (! name.empty())
00118 {
00119 Predicate& teamPredLeft = pList.AddPredicate();
00120 teamPredLeft.name = "team_left";
00121 teamPredLeft.parameter.AddValue(name);
00122 mSentLeftTeamname = true;
00123 }
00124 }
00125
00126 if (! mSentRightTeamname)
00127 {
00128
00129 string name = mGameState->GetTeamName(TI_RIGHT);
00130 if (! name.empty())
00131 {
00132 Predicate& teamPredRight = pList.AddPredicate();
00133 teamPredRight.name = "team_right";
00134 teamPredRight.parameter.AddValue(name);
00135 mSentRightTeamname = true;
00136 }
00137 }
00138
00139
00140 TGameHalf half = mGameState->GetGameHalf();
00141 if (half != mLastHalf)
00142 {
00143 mLastHalf = half;
00144 Predicate& halfPred = pList.AddPredicate();
00145 halfPred.name = "half";
00146 halfPred.parameter.AddValue(static_cast<int>(half));
00147 }
00148
00149
00150 int left_score = mGameState->GetScore(TI_LEFT);
00151 if (left_score != mLastLeftScore)
00152 {
00153 mLastLeftScore = left_score;
00154 Predicate& scoreLeftPred = pList.AddPredicate();
00155 scoreLeftPred.name = "score_left";
00156 scoreLeftPred.parameter.AddValue(left_score);
00157 }
00158
00159 int right_score = mGameState->GetScore(TI_RIGHT);
00160 if (right_score != mLastRightScore)
00161 {
00162 mLastRightScore = right_score;
00163 Predicate& scoreRightPred = pList.AddPredicate();
00164 scoreRightPred.name = "score_right";
00165 scoreRightPred.parameter.AddValue(right_score);
00166 }
00167
00168
00169 TPlayMode play_mode = mGameState->GetPlayMode();
00170 if (play_mode != mLastPlayMode)
00171 {
00172 mLastPlayMode = play_mode;
00173 Predicate& modePred = pList.AddPredicate();
00174 modePred.name = "play_mode";
00175 modePred.parameter.AddValue(static_cast<int>(play_mode));
00176 }
00177 }
00178
00179 void GameStateItem::OnLink()
00180 {
00181 SoccerBase::GetGameState(*this,mGameState);
00182 }
00183
00184 void GameStateItem::OnUnlink()
00185 {
00186 mGameState.reset();
00187 }