Client.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef __CLIENT_H__
  2. #define __CLIENT_H__
  3. #include "../global.h"
  4. #include <boost/thread.hpp>
  5. #include "../lib/IGameCallback.h"
  6. #include "../lib/CondSh.h"
  7. #include <queue>
  8. /*
  9. * Client.h, part of VCMI engine
  10. *
  11. * Authors: listed in file AUTHORS in main folder
  12. *
  13. * License: GNU General Public License v2.0 or later
  14. * Full text of license available in license.txt file, in main folder
  15. *
  16. */
  17. struct StartInfo;
  18. class CGameState;
  19. class CGameInterface;
  20. class CConnection;
  21. class CCallback;
  22. struct BattleAction;
  23. struct SharedMem;
  24. class CClient;
  25. struct CPathsInfo;
  26. void processCommand(const std::string &message, CClient *&client);
  27. class CClient : public IGameCallback
  28. {
  29. public:
  30. CCallback *cb;
  31. std::set<CCallback*> callbacks; //callbacks given to player interfaces
  32. std::map<ui8,CGameInterface *> playerint;
  33. bool hotSeat;
  34. CConnection *serv;
  35. SharedMem *shared;
  36. BattleAction *curbaction;
  37. CPathsInfo *pathInfo;
  38. CondSh<bool> waitingRequest;
  39. std::queue<CPack *> packs;
  40. boost::mutex packsM;
  41. void waitForMoveAndSend(int color);
  42. //void sendRequest(const CPackForServer *request, bool waitForRealization);
  43. CClient(void);
  44. CClient(CConnection *con, StartInfo *si);
  45. ~CClient(void);
  46. void init();
  47. void newGame(CConnection *con, StartInfo *si); //con - connection to server
  48. void endGame();
  49. void save(const std::string & fname);
  50. void loadGame(const std::string & fname);
  51. void run();
  52. void stop();
  53. bool terminate; // tell to terminate
  54. boost::thread *connectionHandler; //thread running run() method
  55. //////////////////////////////////////////////////////////////////////////
  56. //from IGameCallback
  57. int getCurrentPlayer();
  58. int getSelectedHero();
  59. //not working yet, will be implement somewhen later with support for local-sim-based gameplay
  60. void changeSpells(int hid, bool give, const std::set<ui32> &spells){};
  61. bool removeObject(int objid){return false;};
  62. void setBlockVis(int objid, bool bv){};
  63. void setOwner(int objid, ui8 owner){};
  64. void setHoverName(int objid, MetaString * name){};
  65. void setObjProperty(int objid, int prop, si64 val){};
  66. void changePrimSkill(int ID, int which, si64 val, bool abs=false){};
  67. void changeSecSkill(int ID, int which, int val, bool abs=false){};
  68. void showInfoDialog(InfoWindow *iw){};
  69. void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback){};
  70. ui32 showBlockingDialog(BlockingDialog *iw){return 0;}; //synchronous version of above
  71. void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb){};
  72. void showThievesGuildWindow(int requestingObjId){};
  73. void giveResource(int player, int which, int val){};
  74. void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) {};
  75. void takeCreatures (int objid, TSlots creatures){};
  76. void showCompInfo(ShowInInfobox * comp){};
  77. void heroVisitCastle(int obj, int heroID){};
  78. void stopHeroVisitCastle(int obj, int heroID){};
  79. void giveHeroArtifact(int artid, int hid, int position){}; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
  80. void removeArtifact(int artid, int hid){};
  81. void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, boost::function<void(BattleResult*)> cb = 0, const CGTownInstance *town = NULL){}; //use hero=NULL for no hero
  82. void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false){}; //if any of armies is hero, hero will be used
  83. void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false){}; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
  84. void setAmount(int objid, ui32 val){};
  85. bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255){return false;};
  86. void giveHeroBonus(GiveBonus * bonus){};
  87. void setMovePoints(SetMovePoints * smp){};
  88. void setManaPoints(int hid, int val){};
  89. void giveHero(int id, int player){};
  90. void changeObjPos(int objid, int3 newPos, ui8 flags){};
  91. void sendAndApply(CPackForClient * info){};
  92. void heroExchange(si32 hero1, si32 hero2){};
  93. //////////////////////////////////////////////////////////////////////////
  94. friend class CCallback; //handling players actions
  95. friend void processCommand(const std::string &message, CClient *&client); //handling console
  96. static void runServer(const char * portc);
  97. void waitForServer();
  98. CPack * retreivePack(); //gets from server next pack (allocates it with new)
  99. void handlePack( CPack * pack ); //applies the given pack and deletes it
  100. void updatePaths();
  101. //////////////////////////////////////////////////////////////////////////
  102. template <typename Handler> void serialize(Handler &h, const int version);
  103. };
  104. #endif // __CLIENT_H__