Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

gamestateitem.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: gamestateitem.cpp,v 1.2 2004/12/30 15:23:26 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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     // field geometry parameter
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     // agent parameter
00078     PutFloatParam("AgentMass",pList);
00079     PutFloatParam("AgentRadius",pList);
00080     PutFloatParam("AgentMaxSpeed",pList);
00081 
00082     // ball parameter
00083     PutFloatParam("BallRadius",pList);
00084     PutFloatParam("BallMass",pList);
00085 
00086     // soccer rule parameters
00087     PutFloatParam("RuleGoalPauseTime",pList);
00088     PutFloatParam("RuleKickInPauseTime",pList);
00089     PutFloatParam("RuleHalfTime",pList);
00090 
00091     // play modes
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             // team names
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             // team names
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     // game half
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     // scores
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     // gamestate
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 }

Generated on Thu Apr 6 15:25:38 2006 for rcssserver3d by  doxygen 1.4.4