Client.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #include <queue>
  8. /*
  9. * Client.h, part of VCMI engine
  10. *
  11. * Authors: listed in file AUTHORS in main folder
  12. *
  13. * License: GNU General Public License v2.0 or later
  14. * Full text of license available in license.txt file, in main folder
  15. *
  16. */
  17. struct StartInfo;
  18. class CGameState;
  19. class CGameInterface;
  20. class CConnection;
  21. class CCallback;
  22. struct BattleAction;
  23. struct SharedMem;
  24. class CClient;
  25. struct CPathsInfo;
  26. void processCommand(const std::string &message, CClient *&client);
  27. class CClient : public IGameCallback
  28. {
  29. public:
  30. CCallback *cb;
  31. std::set<CCallback*> callbacks; //callbacks given to player interfaces
  32. std::map<ui8,CGameInterface *> playerint;
  33. CConnection *serv;
  34. SharedMem *shared;
  35. BattleAction *curbaction;
  36. CPathsInfo *pathInfo;
  37. CondSh<bool> waitingRequest;
  38. std::queue<CPack *> packs;
  39. boost::mutex packsM;
  40. void waitForMoveAndSend(int color);
  41. //void sendRequest(const CPackForServer *request, bool waitForRealization);
  42. CClient(void);
  43. CClient(CConnection *con, StartInfo *si);
  44. ~CClient(void);
  45. void init();
  46. void newGame(CConnection *con, StartInfo *si); //con - connection to server
  47. void endGame();
  48. void save(const std::string & fname);
  49. void loadGame(const std::string & fname);
  50. void run();
  51. void stop();
  52. bool terminate; // tell to terminate
  53. boost::thread *connectionHandler; //thread running run() method
  54. //////////////////////////////////////////////////////////////////////////
  55. //from IGameCallback
  56. int getCurrentPlayer();
  57. int getSelectedHero();
  58. //not working yet, will be implement somewhen later with support for local-sim-based gameplay
  59. void changeSpells(int hid, bool give, const std::set<ui32> &spells){};
  60. bool removeObject(int objid){return false;};
  61. void setBlockVis(int objid, bool bv){};
  62. void setOwner(int objid, ui8 owner){};
  63. void setHoverName(int objid, MetaString * name){};
  64. void setObjProperty(int objid, int prop, si64 val){};
  65. void changePrimSkill(int ID, int which, si64 val, bool abs=false){};
  66. void changeSecSkill(int ID, int which, int val, bool abs=false){};
  67. void showInfoDialog(InfoWindow *iw){};
  68. void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback){};
  69. ui32 showBlockingDialog(BlockingDialog *iw){return 0;}; //synchronous version of above
  70. void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb){};
  71. void giveResource(int player, int which, int val){};
  72. void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) {};
  73. void takeCreatures (int objid, CCreatureSet creatures){};
  74. void showCompInfo(ShowInInfobox * comp){};
  75. void heroVisitCastle(int obj, int heroID){};
  76. void stopHeroVisitCastle(int obj, int heroID){};
  77. void giveHeroArtifact(int artid, int hid, int position){}; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
  78. void removeArtifact(int artid, int hid){};
  79. void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, boost::function<void(BattleResult*)> cb = 0, const CGTownInstance *town = NULL){}; //use hero=NULL for no hero
  80. void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false){}; //if any of armies is hero, hero will be used
  81. void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false){}; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
  82. void setAmount(int objid, ui32 val){};
  83. bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255){return false;};
  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. void heroExchange(si32 hero1, si32 hero2){};
  91. //////////////////////////////////////////////////////////////////////////
  92. friend class CCallback; //handling players actions
  93. friend void processCommand(const std::string &message, CClient *&client); //handling console
  94. static void runServer(const char * portc);
  95. void waitForServer();
  96. CPack * retreivePack(); //gets from server next pack (allocates it with new)
  97. void handlePack( CPack * pack ); //applies the given pack and deletes it
  98. //////////////////////////////////////////////////////////////////////////
  99. template <typename Handler> void serialize(Handler &h, const int version);
  100. };
  101. #endif // __CLIENT_H__