BaseRules.hh

Go to the documentation of this file.
00001 /*
00002 ** TowBowlTactics, an adaptation of the tabletop game Blood Bowl.
00003 **
00004 ** Copyright (C) 2006 The TBT Team.
00005 **
00006 ** This program is free software; you can redistribute it and/or
00007 ** modify it under the terms of the GNU General Public License
00008 ** as published by the Free Software Foundation; either version 2
00009 ** of the License, or (at your option) any later version.
00010 **
00011 ** The complete GNU General Public Licence Notice can be found as the
00012 ** `NOTICE' file in the root directory.
00013 **
00014 ** The TBT Team consists of people listed in the `AUTHORS' file.
00015 */
00016 
00017 #ifndef BASE_RULES_HH_
00018 # define BASE_RULES_HH_
00019 
00023 # include "tools.hh"
00024 # include "PacketHandler.hh"
00025 # include "PacketSender.hh"
00026 
00027 # define UID_COACH_BASE     0        
00028 # define UID_VIEWER_BASE    100      
00029 
00031 const unsigned MAX_TOKEN    = 256;
00033 const unsigned BASE_TOKEN_START = MAX_TOKEN - 8;
00034 
00035 // Some very common game state.
00036 const int GS_WAIT       = 0xFFFE; 
00037 const int GS_END        = 0xFFFF; 
00038 
00039 // Viewers State (VS). Only for the server. Set by the server.
00040 const unsigned VS_HAVEVIEWER    = 0x0800; 
00041 const unsigned VS_READY     = 0x2000; 
00042 
00043 const unsigned MSG_SYNC     = BASE_TOKEN_START; 
00044 
00050 DECLARE_EMPTY_PACKET(MSG_SYNC, MsgSync);
00051 
00052 // Custom events.
00053 const unsigned CUSTOM_EVENT = BASE_TOKEN_START + 1;
00054 
00055 const unsigned CLIENT_UID   = BASE_TOKEN_START + 2; 
00056 
00061 DECLARE_PACKET(CLIENT_UID, ClientUid);
00062   int league_id;
00063   int nb_coach;
00064   int nb_team;
00065 END_PACKET
00066 
00067 const unsigned BASE_TOKEN_LAST  = BASE_TOKEN_START + 3;
00068 
00075 struct RuleDescription
00076 {
00077   const char* name;
00078   const char* description;
00079   const char* server_lib;
00080   int major;
00081   int minor;
00082 };
00083 
00084 
00094 class BaseRules
00095 {
00096 public:
00097   BaseRules();
00098   virtual ~BaseRules();
00099 
00108 
00109 
00110 
00111   void          sendPacket(const Packet& p) const;
00112 
00114   void          handleWith(BasePacketHandler* bph, int when = 0);
00115 
00117   int           getCoachNumber() const;
00118 
00120   int           getTeamNumber() const;
00121 
00123   int           getState() const;
00125   void          setState(int new_state);
00126 
00128   const char*   stringifyToken(unsigned token) const;
00129 
00130 
00140 
00141   void          setSendPacketObject(PacketSender* ps);
00142 
00144   void          handlePacket(const Packet* p);
00145 
00147   void          setTeamNumber(int coach_nb, int team_nb);
00148 
00149   // see later...
00150   virtual void  serialize(std::ostream& os) const;
00151   virtual void  unserialize(std::istream& is);
00152 
00157 protected:
00158   virtual const char* tokenToString(unsigned token) const;
00159 
00160 private:
00161 
00162   int           state_;
00163   int           coach_number_;
00164   int           team_number_;
00165 
00166 protected:
00167 
00168   PacketSender* packet_sender_;
00169   typedef std::vector<std::pair<int, BasePacketHandler*> > PktHList;
00170   PktHList      pkt_hdl_[MAX_TOKEN];
00171 };
00172 
00173 #endif /* !BASE_RULES_HH_ */

Generated on Sat Jun 23 16:07:22 2007 for Stechec/TBT by  doxygen 1.4.7