CRules.hh
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef CRULES_HH_
00018 # define CRULES_HH_
00019
00020 # include "rules/BaseApi.hh"
00021 # include "rules/BaseCRules.hh"
00022 # include "Constants.hh"
00023 # include "Player.hh"
00024
00025
00026 DECLARE_EMPTY_PACKET(CUSTOM_EVENT, CustomEvent);
00027
00028 class Api;
00029 class App;
00030 class CMatch;
00031 class CPlayerMsg;
00032 class CTeamMsg;
00033 class CTeam;
00034 class SendingQueue;
00035
00040 class CRules : public BaseCRules
00041 {
00042 friend class Api;
00043
00044 public:
00045 CRules(App* app);
00046 virtual ~CRules();
00047
00048
00049 virtual void serialize(std::ostream& os) const;
00050 virtual void unserialize(std::istream& is);
00051
00053 virtual Api* getApi();
00054 App* getApp();
00055 CMatch* getMatch();
00056 CPlayerMsg* getPlayerMsg();
00057 SendingQueue* getSendingQueue();
00058 CTeamMsg* getTeamMsg();
00059
00060
00062 void setState(int new_state);
00063 void switchToTeamState(int state);
00064 void restoreGameState();
00065
00066
00067 void countRequestSending();
00068 void countRequestProcessed();
00069 void countQueryReceived();
00070 void countQueryProcessed();
00071 void freezeRequestSending();
00072 void unfreezeRequestSending();
00073 int getNbRequestsSent() const;
00074
00075 void sendPacketLater(const MsgMove& m);
00076
00077 friend std::ostream& operator<< (std::ostream& os, const CRules& r);
00078
00079 private:
00081 const char* tokenToString(unsigned token) const;
00082
00083
00084 void msgIllegal(const MsgIllegal* m);
00085 void msgInitGame(const MsgInitGame* m);
00086 void msgDrawKicker(const MsgDrawKicker* m);
00087 void msgInitKickoff(const MsgInitKickoff* m);
00088 void msgTouchBack(const MsgTouchBack* m);
00089 void msgEndGame(const MsgEndGame* m);
00090 void msgCancelGame(const MsgCancelGame* m);
00091 void msgChatMessage(const MsgChat* m);
00092 void msgDebug(const MsgDebug* m);
00093 void msgCustomEvent(const CustomEvent* m);
00094 void msgRequestProcessed(const MsgRequestProcessed* m);
00095
00096 App* app_;
00097 Api* api_;
00098
00099 int saved_game_state_;
00100 int nb_requests_sent_;
00101 int nb_server_queries_;
00102
00103 CMatch* match_;
00104 CTeam* our_team_;
00105 CTeam* other_team_;
00106 CTeamMsg* team_msg_;
00107 CPlayerMsg* player_msg_;
00108 SendingQueue* sq_;
00109 };
00110
00111 # include "CRules.hxx"
00112
00113 #endif