CRules.hh

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 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 // Mostly a big hack, to have BaseCRules::onEvent(int) working.
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   // FIXME: see later.
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   // For synchronization with server.
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   // Methods to catch server response.
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 /* !CRULES_HH_ */
Generated on Mon Apr 5 21:17:11 2010 for Stechec/TBT by  doxygen 1.6.3