Client.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. bool hotSeat;
  34. CConnection *serv;
  35. SharedMem *shared;
  36. BattleAction *curbaction;
  37. CPathsInfo *pathInfo;
  38. CondSh<bool> waitingRequest;
  39. std::queue<CPack *> packs;
  40. boost::mutex packsM;
  41. void waitForMoveAndSend(int color);
  42. //void sendRequest(const CPackForServer *request, bool waitForRealization);
  43. CClient(void);
  44. CClient(CConnection *con, StartInfo *si);
  45. ~CClient(void);
  46. void init();
  47. void newGame(CConnection *con, StartInfo *si); //con - connection to server
  48. void endGame(bool closeConnection = true);
  49. void stopConnection();
  50. void save(const std::string & fname);
  51. void loadGame(const std::string & fname);
  52. void run();
  53. void finishCampaign( CCampaignState * camp );
  54. void proposeNextMission( CCampaignState * camp );
  55. bool terminate; // tell to terminate
  56. boost::thread *connectionHandler; //thread running run() method
  57. //////////////////////////////////////////////////////////////////////////
  58. //from IGameCallback
  59. int getCurrentPlayer();
  60. int getSelectedHero();
  61. //not working yet, will be implement somewhen later with support for local-sim-based gameplay
  62. void changeSpells(int hid, bool give, const std::set<ui32> &spells){};
  63. bool removeObject(int objid){return false;};
  64. void setBlockVis(int objid, bool bv){};
  65. void setOwner(int objid, ui8 owner){};
  66. void setHoverName(int objid, MetaString * name){};
  67. void setObjProperty(int objid, int prop, si64 val){};
  68. void changePrimSkill(int ID, int which, si64 val, bool abs=false){};
  69. void changeSecSkill(int ID, int which, int val, bool abs=false){};
  70. void showInfoDialog(InfoWindow *iw){};
  71. void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback){};
  72. ui32 showBlockingDialog(BlockingDialog *iw){return 0;}; //synchronous version of above
  73. void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb){};
  74. void showThievesGuildWindow(int requestingObjId){};
  75. void giveResource(int player, int which, int val){};
  76. void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) {};
  77. void takeCreatures (int objid, TSlots creatures){};
  78. void changeCreatureType (int objid, TSlot slot, TCreature creature){};
  79. void showCompInfo(ShowInInfobox * comp){};
  80. void heroVisitCastle(int obj, int heroID){};
  81. void stopHeroVisitCastle(int obj, int heroID){};
  82. void giveHeroArtifact(int artid, int hid, int position){}; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
  83. bool removeArtifact(int artid, int hid){return false;};
  84. 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
  85. 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
  86. 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
  87. void setAmount(int objid, ui32 val){};
  88. bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255){return false;};
  89. void giveHeroBonus(GiveBonus * bonus){};
  90. void setMovePoints(SetMovePoints * smp){};
  91. void setManaPoints(int hid, int val){};
  92. void giveHero(int id, int player){};
  93. void changeObjPos(int objid, int3 newPos, ui8 flags){};
  94. void sendAndApply(CPackForClient * info){};
  95. void heroExchange(si32 hero1, si32 hero2){};
  96. //////////////////////////////////////////////////////////////////////////
  97. friend class CCallback; //handling players actions
  98. friend void processCommand(const std::string &message, CClient *&client); //handling console
  99. static void runServer(const char * portc);
  100. void waitForServer();
  101. CPack * retreivePack(); //gets from server next pack (allocates it with new)
  102. void handlePack( CPack * pack ); //applies the given pack and deletes it
  103. void updatePaths();
  104. //////////////////////////////////////////////////////////////////////////
  105. template <typename Handler> void serialize(Handler &h, const int version);
  106. };
  107. #endif // __CLIENT_H__