Client.h 3.8 KB

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