GameStateInterface.h

00001
00002 /***************************************************************************
00003  *  GameStateInterface.h - Fawkes BlackBoard Interface - GameStateInterface
00004  *
00005  *  Templated created:   Thu Oct 12 10:49:19 2006
00006  *  Copyright  2008  Tim Niemueller
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #ifndef __INTERFACES_GAMESTATEINTERFACE_H_
00025 #define __INTERFACES_GAMESTATEINTERFACE_H_
00026 
00027 #include <interface/interface.h>
00028 #include <interface/message.h>
00029 #include <interface/field_iterator.h>
00030
00031 namespace fawkes {
00032
00033 class GameStateInterface : public Interface
00034 {
00035  /// @cond INTERNALS
00036  INTERFACE_MGMT_FRIENDS(GameStateInterface)
00037  /// @endcond
00038  public:
00039   /* constants */
00040   static const unsigned int GS_FROZEN;
00041   static const unsigned int GS_PLAY;
00042   static const unsigned int GS_KICK_OFF;
00043   static const unsigned int GS_DROP_BALL;
00044   static const unsigned int GS_PENALTY;
00045   static const unsigned int GS_CORNER_KICK;
00046   static const unsigned int GS_THROW_IN;
00047   static const unsigned int GS_FREE_KICK;
00048   static const unsigned int GS_GOAL_KICK;
00049   static const unsigned int GS_HALF_TIME;
00050   static const unsigned int GS_SPL_INITIAL;
00051   static const unsigned int GS_SPL_READY;
00052   static const unsigned int GS_SPL_SET;
00053   static const unsigned int GS_SPL_PLAY;
00054   static const unsigned int GS_SPL_FINISHED;
00055 
00056   /** 
00057         Enumeration defining the different teams. Keep in sync with
00058         worldinfo_gamestate_team_t.
00059        */
00060   typedef enum {
00061     TEAM_NONE /**< No team, not team-specific */,
00062     TEAM_CYAN /**< Cyan team */,
00063     TEAM_MAGENTA /**< Magenta team */,
00064     TEAM_BOTH /**< Both teams */
00065   } if_gamestate_team_t;
00066 
00067   /** 
00068         Enumeration defining the different teams. Keep in sync with
00069         worldinfo_gamestate_goalcolor_t.
00070        */
00071   typedef enum {
00072     GOAL_BLUE /**< Blue goal */,
00073     GOAL_YELLOW /**< Yellow goal */
00074   } if_gamestate_goalcolor_t;
00075 
00076   /** 
00077         Enumeration defining the different teams. Keep in sync with
00078         worldinfo_gamestate_half_t.
00079        */
00080   typedef enum {
00081     HALF_FIRST /**< First half */,
00082     HALF_SECOND /**< Second half */
00083   } if_gamestate_half_t;
00084 
00085   /** 
00086         Enumeration defining the different robot roles. Keep in sync with
00087         worldinfo_gamestate_role_t.
00088        */
00089   typedef enum {
00090     ROLE_GOALIE /**< Goalie */,
00091     ROLE_DEFENDER /**< Defender */,
00092     ROLE_MID_LEFT /**< Midfield left */,
00093     ROLE_MID_RIGHT /**< Midfield right */,
00094     ROLE_ATTACKER /**< Attacker */
00095   } if_gamestate_role_t;
00096
00097  private:
00098   /** Internal data storage, do NOT modify! */
00099   typedef struct {
00100     unsigned int game_state; /**< Current game state */
00101     unsigned int score_cyan; /**< Score of team cyan */
00102     unsigned int score_magenta; /**< Score of team magenta */
00103     bool kickoff; /**< Whether we have kickoff */
00104     if_gamestate_team_t state_team; /**< Team referred to by game state */
00105     if_gamestate_team_t our_team; /**< Our team color */
00106     if_gamestate_goalcolor_t our_goal_color; /**< Our own goal color */
00107     if_gamestate_half_t half; /**< Current game half */
00108     if_gamestate_role_t role; /**< Current role of this robot */
00109   } GameStateInterface_data_t;
00110
00111   GameStateInterface_data_t *data;
00112
00113  public:
00114   /* messages */
00115   class SetTeamColorMessage : public Message
00116   {
00117    private:
00118     /** Internal data storage, do NOT modify! */
00119     typedef struct {
00120       if_gamestate_team_t our_team; /**< Our team color */
00121     } SetTeamColorMessage_data_t;
00122
00123     SetTeamColorMessage_data_t *data;
00124
00125    public:
00126     SetTeamColorMessage(const if_gamestate_team_t ini_our_team);
00127     SetTeamColorMessage();
00128     ~SetTeamColorMessage();
00129
00130     SetTeamColorMessage(const SetTeamColorMessage *m);
00131     /* Methods */
00132     if_gamestate_team_t our_team() const;
00133     void set_our_team(const if_gamestate_team_t new_our_team);
00134     size_t maxlenof_our_team() const;
00135     virtual Message * clone() const;
00136   };
00137
00138   class SetKickoffMessage : public Message
00139   {
00140    private:
00141     /** Internal data storage, do NOT modify! */
00142     typedef struct {
00143       bool kickoff; /**< Whether we have kickoff */
00144     } SetKickoffMessage_data_t;
00145
00146     SetKickoffMessage_data_t *data;
00147
00148    public:
00149     SetKickoffMessage(const bool ini_kickoff);
00150     SetKickoffMessage();
00151     ~SetKickoffMessage();
00152
00153     SetKickoffMessage(const SetKickoffMessage *m);
00154     /* Methods */
00155     bool is_kickoff() const;
00156     void set_kickoff(const bool new_kickoff);
00157     size_t maxlenof_kickoff() const;
00158     virtual Message * clone() const;
00159   };
00160
00161   class SetStateTeamMessage : public Message
00162   {
00163    private:
00164     /** Internal data storage, do NOT modify! */
00165     typedef struct {
00166       if_gamestate_team_t state_team; /**< Team referred to by game state */
00167     } SetStateTeamMessage_data_t;
00168
00169     SetStateTeamMessage_data_t *data;
00170
00171    public:
00172     SetStateTeamMessage(const if_gamestate_team_t ini_state_team);
00173     SetStateTeamMessage();
00174     ~SetStateTeamMessage();
00175
00176     SetStateTeamMessage(const SetStateTeamMessage *m);
00177     /* Methods */
00178     if_gamestate_team_t state_team() const;
00179     void set_state_team(const if_gamestate_team_t new_state_team);
00180     size_t maxlenof_state_team() const;
00181     virtual Message * clone() const;
00182   };
00183
00184   virtual bool message_valid(const Message *message) const;
00185  private:
00186   GameStateInterface();
00187   ~GameStateInterface();
00188
00189  public:
00190   /* Methods */
00191   unsigned int game_state() const;
00192   void set_game_state(const unsigned int new_game_state);
00193   size_t maxlenof_game_state() const;
00194   if_gamestate_team_t state_team() const;
00195   void set_state_team(const if_gamestate_team_t new_state_team);
00196   size_t maxlenof_state_team() const;
00197   if_gamestate_team_t our_team() const;
00198   void set_our_team(const if_gamestate_team_t new_our_team);
00199   size_t maxlenof_our_team() const;
00200   if_gamestate_goalcolor_t our_goal_color() const;
00201   void set_our_goal_color(const if_gamestate_goalcolor_t new_our_goal_color);
00202   size_t maxlenof_our_goal_color() const;
00203   if_gamestate_half_t half() const;
00204   void set_half(const if_gamestate_half_t new_half);
00205   size_t maxlenof_half() const;
00206   bool is_kickoff() const;
00207   void set_kickoff(const bool new_kickoff);
00208   size_t maxlenof_kickoff() const;
00209   if_gamestate_role_t role() const;
00210   void set_role(const if_gamestate_role_t new_role);
00211   size_t maxlenof_role() const;
00212   unsigned int score_cyan() const;
00213   void set_score_cyan(const unsigned int new_score_cyan);
00214   size_t maxlenof_score_cyan() const;
00215   unsigned int score_magenta() const;
00216   void set_score_magenta(const unsigned int new_score_magenta);
00217   size_t maxlenof_score_magenta() const;
00218   virtual Message * create_message(const char *type) const;
00219
00220   virtual void copy_values(const Interface *other);
00221
00222 };
00223
00224 } // end namespace fawkes
00225
00226 #endif