Client.h 4.7 KB

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