Client.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 SharedMem;
  12. class CClient;
  13. void processCommand(const std::string &message, CClient *&client);
  14. namespace boost
  15. {
  16. class mutex;
  17. class condition_variable;
  18. }
  19. template <typename T>
  20. struct CSharedCond
  21. {
  22. boost::mutex *mx;
  23. boost::condition_variable *cv;
  24. T *res;
  25. CSharedCond(T*R)
  26. {
  27. res = R;
  28. mx = new boost::mutex;
  29. cv = new boost::condition_variable;
  30. }
  31. ~CSharedCond()
  32. {
  33. delete res;
  34. delete mx;
  35. delete cv;
  36. }
  37. };
  38. class CClient : public IGameCallback
  39. {
  40. CCallback *cb;
  41. std::map<ui8,CGameInterface *> playerint;
  42. CConnection *serv;
  43. SharedMem *shared;
  44. void waitForMoveAndSend(int color);
  45. public:
  46. CClient(void);
  47. CClient(CConnection *con, StartInfo *si);
  48. ~CClient(void);
  49. void init();
  50. void close();
  51. void newGame(CConnection *con, StartInfo *si); //con - connection to server
  52. void save(const std::string & fname);
  53. void load(const std::string & fname);
  54. void process(int what);
  55. void run();
  56. //////////////////////////////////////////////////////////////////////////
  57. //from IGameCallback
  58. int getCurrentPlayer();
  59. int getSelectedHero();
  60. //not working yet, will be implement somewhen later with support for local-sim-based gameplay
  61. void changeSpells(int hid, bool give, const std::set<ui32> &spells){};
  62. void removeObject(int objid){};
  63. void setBlockVis(int objid, bool bv){};
  64. void setOwner(int objid, ui8 owner){};
  65. void setHoverName(int objid, MetaString * name){};
  66. void setObjProperty(int objid, int prop, int val){};
  67. void changePrimSkill(int ID, int which, int val, bool abs=false){};
  68. void changeSecSkill(int ID, int which, int val, bool abs=false){};
  69. void showInfoDialog(InfoWindow *iw){};
  70. void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback){};
  71. void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback){}; //returns question id
  72. void giveResource(int player, int which, int val){};
  73. void showCompInfo(ShowInInfobox * comp){};
  74. void heroVisitCastle(int obj, int heroID){};
  75. void stopHeroVisitCastle(int obj, int heroID){};
  76. void giveHeroArtifact(int artid, int hid, int position){}; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
  77. 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
  78. void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb){}; //for hero<=>neutral army
  79. void setAmount(int objid, ui32 val){};
  80. void moveHero(int hid, int3 pos, bool instant){};
  81. void giveHeroBonus(GiveBonus * bonus){};
  82. void setMovePoints(SetMovePoints * smp){};
  83. void setManaPoints(int hid, int val){};
  84. void giveHero(int id, int player){};
  85. void changeObjPos(int objid, int3 newPos, ui8 flags){};
  86. //////////////////////////////////////////////////////////////////////////
  87. friend class CCallback; //handling players actions
  88. friend void processCommand(const std::string &message, CClient *&client); //handling console
  89. static void runServer(const char * portc);
  90. void waitForServer();
  91. };
  92. #endif // __CLIENT_H__