Client.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /*
  8. * Client.h, part of VCMI engine
  9. *
  10. * Authors: listed in file AUTHORS in main folder
  11. *
  12. * License: GNU General Public License v2.0 or later
  13. * Full text of license available in license.txt file, in main folder
  14. *
  15. */
  16. struct StartInfo;
  17. class CGameState;
  18. class CGameInterface;
  19. class CConnection;
  20. class CCallback;
  21. struct BattleAction;
  22. struct SharedMem;
  23. class CClient;
  24. struct CPathsInfo;
  25. void processCommand(const std::string &message, CClient *&client);
  26. namespace boost
  27. {
  28. class mutex;
  29. class condition_variable;
  30. }
  31. template <typename T>
  32. struct CSharedCond
  33. {
  34. boost::mutex *mx;
  35. boost::condition_variable *cv;
  36. T *res;
  37. CSharedCond(T*R)
  38. {
  39. res = R;
  40. mx = new boost::mutex;
  41. cv = new boost::condition_variable;
  42. }
  43. ~CSharedCond()
  44. {
  45. delete res;
  46. delete mx;
  47. delete cv;
  48. }
  49. };
  50. class CClient : public IGameCallback
  51. {
  52. public:
  53. CCallback *cb;
  54. std::set<CCallback*> callbacks; //callbacks given to player interfaces
  55. std::map<ui8,CGameInterface *> playerint;
  56. CConnection *serv;
  57. bool must_close;
  58. SharedMem *shared;
  59. BattleAction *curbaction;
  60. CPathsInfo *pathInfo;
  61. CondSh<bool> waitingRequest;
  62. void waitForMoveAndSend(int color);
  63. //void sendRequest(const CPackForServer *request, bool waitForRealization);
  64. CClient(void);
  65. CClient(CConnection *con, StartInfo *si);
  66. ~CClient(void);
  67. void init();
  68. void close();
  69. void newGame(CConnection *con, StartInfo *si); //con - connection to server
  70. void save(const std::string & fname);
  71. void load(const std::string & fname);
  72. void run();
  73. //////////////////////////////////////////////////////////////////////////
  74. //from IGameCallback
  75. int getCurrentPlayer();
  76. int getSelectedHero();
  77. //not working yet, will be implement somewhen later with support for local-sim-based gameplay
  78. void changeSpells(int hid, bool give, const std::set<ui32> &spells){};
  79. bool removeObject(int objid){return false;};
  80. void setBlockVis(int objid, bool bv){};
  81. void setOwner(int objid, ui8 owner){};
  82. void setHoverName(int objid, MetaString * name){};
  83. void setObjProperty(int objid, int prop, si64 val){};
  84. void changePrimSkill(int ID, int which, si64 val, bool abs=false){};
  85. void changeSecSkill(int ID, int which, int val, bool abs=false){};
  86. void showInfoDialog(InfoWindow *iw){};
  87. void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback){};
  88. ui32 showBlockingDialog(BlockingDialog *iw){return 0;}; //synchronous version of above
  89. void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb){};
  90. void giveResource(int player, int which, int val){};
  91. void giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const {};
  92. void showCompInfo(ShowInInfobox * comp){};
  93. void heroVisitCastle(int obj, int heroID){};
  94. void stopHeroVisitCastle(int obj, int heroID){};
  95. void giveHeroArtifact(int artid, int hid, int position){}; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
  96. 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
  97. 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
  98. 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
  99. void setAmount(int objid, ui32 val){};
  100. bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255){return false;};
  101. void giveHeroBonus(GiveBonus * bonus){};
  102. void setMovePoints(SetMovePoints * smp){};
  103. void setManaPoints(int hid, int val){};
  104. void giveHero(int id, int player){};
  105. void changeObjPos(int objid, int3 newPos, ui8 flags){};
  106. void sendAndApply(CPackForClient * info){};
  107. void heroExchange(si32 hero1, si32 hero2){};
  108. //////////////////////////////////////////////////////////////////////////
  109. friend class CCallback; //handling players actions
  110. friend void processCommand(const std::string &message, CClient *&client); //handling console
  111. static void runServer(const char * portc);
  112. void waitForServer();
  113. //////////////////////////////////////////////////////////////////////////
  114. template <typename Handler> void serialize(Handler &h, const int version);
  115. };
  116. #endif // __CLIENT_H__