Client.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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::map<ui8,CGameInterface *> playerint;
  44. CConnection *serv;
  45. SharedMem *shared;
  46. BattleAction *curbaction;
  47. void waitForMoveAndSend(int color);
  48. CClient(void);
  49. CClient(CConnection *con, StartInfo *si);
  50. ~CClient(void);
  51. void init();
  52. void close();
  53. void newGame(CConnection *con, StartInfo *si); //con - connection to server
  54. void save(const std::string & fname);
  55. void load(const std::string & fname);
  56. void process(int what);
  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 showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback){};
  73. void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback){}; //returns question id
  74. void giveResource(int player, int which, int val){};
  75. void showCompInfo(ShowInInfobox * comp){};
  76. void heroVisitCastle(int obj, int heroID){};
  77. void stopHeroVisitCastle(int obj, int heroID){};
  78. void giveHeroArtifact(int artid, int hid, int position){}; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
  79. 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
  80. void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb){}; //for hero<=>neutral army
  81. void setAmount(int objid, ui32 val){};
  82. void moveHero(int hid, int3 pos, bool instant){};
  83. void giveHeroBonus(GiveBonus * bonus){};
  84. void setMovePoints(SetMovePoints * smp){};
  85. void setManaPoints(int hid, int val){};
  86. void giveHero(int id, int player){};
  87. void changeObjPos(int objid, int3 newPos, ui8 flags){};
  88. //////////////////////////////////////////////////////////////////////////
  89. friend class CCallback; //handling players actions
  90. friend void processCommand(const std::string &message, CClient *&client); //handling console
  91. static void runServer(const char * portc);
  92. void waitForServer();
  93. };
  94. #endif // __CLIENT_H__