00001 /* 00002 ** TowBowlTactics, a turn-based strategy football game. 00003 ** 00004 ** Copyright (C) 2006-2010 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 "Packet.hh" 00025 # include "PacketHandler.hh" 00026 # include "PacketHistory.hh" 00027 # include "PacketSender.hh" 00028 00029 # define UID_COACH_BASE 0 ///< Base uid for coachs 00030 # define UID_VIEWER_BASE 100 ///< Base uid for viewers 00031 00033 const unsigned MAX_TOKEN = 256; 00035 const unsigned BASE_TOKEN_START = MAX_TOKEN - 8; 00036 00037 // Some very common game state. 00038 const int GS_WAIT = 0xFFFE; 00039 const int GS_END = 0xFFFF; 00040 00041 // Viewers State (VS). Only for the server. Set by the server. 00042 const unsigned VS_HAVEVIEWER = 0x0800; 00043 const unsigned VS_READY = 0x2000; 00044 00045 const unsigned MSG_SYNC = BASE_TOKEN_START; 00046 00052 DECLARE_EMPTY_PACKET(MSG_SYNC, MsgSync); 00053 00054 // Custom events. 00055 const unsigned CUSTOM_EVENT = BASE_TOKEN_START + 1; 00056 00057 const unsigned CLIENT_UID = BASE_TOKEN_START + 2; 00058 00063 DECLARE_PACKET(CLIENT_UID, ClientUid); 00064 int league_id; 00065 int nb_coach; 00066 int nb_team; 00067 END_PACKET 00068 00069 const unsigned BASE_TOKEN_LAST = BASE_TOKEN_START + 3; 00070 00077 struct RuleDescription 00078 { 00079 const char* name; 00080 const char* description; 00081 const char* server_lib; 00082 int major; 00083 int minor; 00084 }; 00085 00086 00096 class BaseRules 00097 { 00098 public: 00099 BaseRules(); 00100 virtual ~BaseRules(); 00101 00110 00111 00112 00113 void sendPacket(const Packet& p) const; 00114 00116 void handleWith(BasePacketHandler* bph, int when = 0); 00117 00119 const PacketHistory& getHistory() const; 00120 00122 int getCoachNumber() const; 00123 00125 int getTeamNumber() const; 00126 00128 int getState() const; 00130 void setState(int new_state); 00131 00133 const char* stringifyToken(unsigned token) const; 00134 00136 static const char* stringifyGameState(int game_state); 00137 00147 00148 void setSendPacketObject(PacketSender* ps); 00149 00151 void handlePacket(const Packet* p); 00152 00154 void setTeamNumber(int coach_nb, int team_nb); 00155 00156 // see later... 00157 virtual void serialize(std::ostream& os) const; 00158 virtual void unserialize(std::istream& is); 00159 00164 protected: 00165 virtual const char* tokenToString(unsigned token) const; 00166 00167 private: 00168 00169 int state_; 00170 int coach_number_; 00171 int team_number_; 00172 00173 protected: 00174 00175 PacketSender* packet_sender_; 00176 typedef std::vector<std::pair<int, BasePacketHandler*> > PktHList; 00177 PktHList pkt_hdl_[MAX_TOKEN]; 00178 00179 PacketHistory pkt_history_; 00180 00181 }; 00182 00183 #endif /* !BASE_RULES_HH_ */
1.6.3