Client.h 4.4 KB

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