Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Modules/BehaviorControl/CommonXabsl2Symbols/RoboCupGameManagerSymbols.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file RoboCupGameManagerSymbols.cpp
    00003 *
    00004 * Implementation of class RoboCupGameManagerSymbols.
    00005 *
    00006 * @author Matthias Jüngel
    00007 */
    00008
    00009 #include "RoboCupGameManagerSymbols.h"
    00010
    00011
    00012 RoboCupGameManagerSymbols::RoboCupGameManagerSymbols(const BehaviorControlInterfaces& interfaces)
    00013 : BehaviorControlInterfaces(interfaces),
    00014 lastGameControlDataState(GameControlData::initial),
    00015 timeWhenOwnTeamScored(0), lastOwnScore(0),
    00016 timeWhenOpponentTeamScored(0), lastOpponentScore(0), currentState(GameControlData::initial)
    00017 {
    00018 }
    00019
    00020
    00021 void RoboCupGameManagerSymbols::registerSymbols(Xabsl2Engine& engine)
    00022 {
    00023   // "game.state"
    00024   engine.registerEnumeratedInputSymbol("game.state",this,
    00025     (int (Xabsl2FunctionProvider::*)())&RoboCupGameManagerSymbols::getState);
    00026   engine.registerEnumeratedInputSymbolEnumElement("game.state","game.state.initial",GameControlData::initial);
    00027   engine.registerEnumeratedInputSymbolEnumElement("game.state","game.state.ready",GameControlData::ready);
    00028   engine.registerEnumeratedInputSymbolEnumElement("game.state","game.state.set",GameControlData::set);
    00029   engine.registerEnumeratedInputSymbolEnumElement("game.state","game.state.playing",GameControlData::playing);
    00030   engine.registerEnumeratedInputSymbolEnumElement("game.state","game.state.finished",GameControlData::finished);
    00031   engine.registerEnumeratedInputSymbolEnumElement("game.state","game.state.penalized",42); //HACK !
    00032   // "game.current-state"
    00033   engine.registerEnumeratedOutputSymbol("game.current-state",(int*) &currentState);
    00034   engine.registerEnumeratedOutputSymbolEnumElement("game.current-state","game.current-state.initial",GameControlData::initial);
    00035   engine.registerEnumeratedOutputSymbolEnumElement("game.current-state","game.current-state.ready",GameControlData::ready);
    00036   engine.registerEnumeratedOutputSymbolEnumElement("game.current-state","game.current-state.set",GameControlData::set);
    00037   engine.registerEnumeratedOutputSymbolEnumElement("game.current-state","game.current-state.playing",GameControlData::playing);
    00038   engine.registerEnumeratedOutputSymbolEnumElement("game.current-state","game.current-state.finished",GameControlData::finished);
    00039   engine.registerEnumeratedOutputSymbolEnumElement("game.current-state","game.current-state.penalized",42); //HACK !
    00040   // "game.kickoff"
    00041   engine.registerEnumeratedInputSymbol("game.kickoff",this,
    00042     (int (Xabsl2FunctionProvider::*)())&RoboCupGameManagerSymbols::getKickoff);
    00043   engine.registerEnumeratedInputSymbolEnumElement("game.kickoff","game.kickoff.invalid",GameControlData::undefinedTeam);
    00044   engine.registerEnumeratedInputSymbolEnumElement("game.kickoff","game.kickoff.own",GameControlData::ownTeam);
    00045   engine.registerEnumeratedInputSymbolEnumElement("game.kickoff","game.kickoff.opponent",GameControlData::opponentTeam);
    00046   // "game.team-color"
    00047   engine.registerEnumeratedInputSymbol("game.team-color",this,
    00048     (int (Xabsl2FunctionProvider::*)())&RoboCupGameManagerSymbols::getTeamColor);
    00049   engine.registerEnumeratedInputSymbolEnumElement("game.team-color","red",Player::red);
    00050   engine.registerEnumeratedInputSymbolEnumElement("game.team-color","blue",Player::blue);
    00051   // "game.set-team-color"
    00052   engine.registerEnumeratedOutputSymbol("game.set-team-color",this,
    00053     (void (Xabsl2FunctionProvider::*)(int))&RoboCupGameManagerSymbols::setTeamColor);
    00054   engine.registerEnumeratedOutputSymbolEnumElement("game.set-team-color","red",Player::red);
    00055   engine.registerEnumeratedOutputSymbolEnumElement("game.set-team-color","blue",Player::blue);
    00056   // "game.own-team-scored"
    00057   engine.registerBooleanInputSymbol("game.own-team-scored",this,
    00058     (bool (Xabsl2FunctionProvider::*)())&RoboCupGameManagerSymbols::getOwnTeamScored);
    00059   // "game.opponent-team-scored"
    00060   engine.registerBooleanInputSymbol("game.opponent-team-scored",this,
    00061     (bool (Xabsl2FunctionProvider::*)())&RoboCupGameManagerSymbols::getOpponentTeamScored);
    00062   // "game.own-score"
    00063   engine.registerDecimalInputSymbol("game.own-score",this,
    00064     (double (Xabsl2FunctionProvider::*)())&RoboCupGameManagerSymbols::getOwnScore);
    00065   // "game.opponent-score"
    00066   engine.registerDecimalInputSymbol("game.opponent-score",this,
    00067     (double (Xabsl2FunctionProvider::*)())&RoboCupGameManagerSymbols::getOpponentScore);
    00068   // "game.time-since-last-message"
    00069   engine.registerDecimalInputSymbol("game.time-since-last-message",this,
    00070     (double (Xabsl2FunctionProvider::*)())&RoboCupGameManagerSymbols::getTimeSinceLastMessage);
    00071   // self symbols
    00072 }
    00073
    00074 void RoboCupGameManagerSymbols::update()
    00075 {
    00076   /* If the robot is in ready now and was playing or penalized before */
    00077   if ((gameControlData.data.state == GameControlData::ready)&&
    00078     ((lastGameControlDataState == GameControlData::playing)))
    00079   {
    00080     if (gameControlData.getOwnTeam().score > (uint32)lastOwnScore)
    00081     {
    00082       timeWhenOwnTeamScored = SystemCall::getCurrentSystemTime();
    00083     }
    00084     if (gameControlData.getOpponentTeam().score > (uint32)lastOpponentScore)
    00085     {
    00086       timeWhenOpponentTeamScored = SystemCall::getCurrentSystemTime();
    00087     }
    00088   }
    00089   lastOwnScore = gameControlData.getOwnTeam().score;
    00090   lastOpponentScore = gameControlData.getOpponentTeam().score;
    00091   lastGameControlDataState = gameControlData.data.state;
    00092
    00093   if (getTimeSinceLastMessage() < 500) // why only then....
    00094   {
    00095     getPlayer().setTeamColor(
    00096       gameControlData.getOwnTeam().teamColour == TEAM_RED ? Player::red : Player::blue);
    00097   }
    00098 }
    00099
    00100 void RoboCupGameManagerSymbols::setTeamColor(int teamColor)
    00101 {
    00102   getPlayer().setTeamColor((Player::teamColor)teamColor);
    00103 }
    00104
    00105 int RoboCupGameManagerSymbols::getState()
    00106 {
    00107   // Small hack so that the old Behavior works with the new game-controller.
    00108   // Should be done better in the future.
    00109   if (gameControlData.getRobot().penalty != GameControlData::notPenalized)
    00110   {
    00111     return (42); // HACK !
    00112   }
    00113   return (int)gameControlData.data.state;
    00114 }
    00115
    00116 int RoboCupGameManagerSymbols::getKickoff()
    00117 {
    00118   return (int)gameControlData.getKickoffTeam();
    00119 }
    00120
    00121 int RoboCupGameManagerSymbols::getTeamColor()
    00122 {
    00123   return (int)(getPlayer().getTeamColor());
    00124 }
    00125
    00126 bool RoboCupGameManagerSymbols::getOwnTeamScored()
    00127 {
    00128   return (SystemCall::getTimeSince(timeWhenOwnTeamScored) < 5000);
    00129 }
    00130
    00131 bool RoboCupGameManagerSymbols::getOpponentTeamScored()
    00132 {
    00133   return (SystemCall::getTimeSince(timeWhenOpponentTeamScored) < 5000);
    00134 }
    00135
    00136 double RoboCupGameManagerSymbols::getOwnScore()
    00137 {
    00138   return (double)gameControlData.getOwnTeam().score;
    00139 }
    00140
    00141 double RoboCupGameManagerSymbols::getOpponentScore()
    00142 {
    00143   return (double)gameControlData.getOpponentTeam().score;
    00144 }
    00145
    00146 double RoboCupGameManagerSymbols::getTimeSinceLastMessage()
    00147 {
    00148   return (double)SystemCall::getTimeSince(gameControlData.timeStamp);
    00149 }
    00150