IGameCallback.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #pragma once
  2. #include "BattleHex.h"
  3. #include "../client/FunctionList.h"
  4. #include "ResourceSet.h"
  5. #include "int3.h"
  6. #include "GameConstants.h"
  7. #include "CBattleCallback.h"
  8. /*
  9. * IGameCallback.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 SetMovePoints;
  18. struct GiveBonus;
  19. class CGObjectInstance;
  20. class CGTownInstance;
  21. class CGHeroInstance;
  22. struct BlockingDialog;
  23. struct InfoWindow;
  24. struct MetaString;
  25. struct ShowInInfobox;
  26. struct BattleResult;
  27. struct Component;
  28. class CGameState;
  29. struct PlayerSettings;
  30. struct CPackForClient;
  31. class CArtHandler;
  32. class CArtifact;
  33. class CArmedInstance;
  34. struct TerrainTile;
  35. struct PlayerState;
  36. class CTown;
  37. struct StackLocation;
  38. struct ArtifactLocation;
  39. class CArtifactInstance;
  40. struct StartInfo;
  41. struct InfoAboutTown;
  42. struct UpgradeInfo;
  43. struct SThievesGuildInfo;
  44. struct CPath;
  45. class CGDwelling;
  46. struct InfoAboutHero;
  47. class CMapHeader;
  48. struct BattleAction;
  49. class CStack;
  50. class CSpell;
  51. class CCreatureSet;
  52. class CCreature;
  53. class CStackBasicDescriptor;
  54. struct TeamState;
  55. struct QuestInfo;
  56. class CGCreature;
  57. class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase
  58. {
  59. protected:
  60. CGameInfoCallback();
  61. CGameInfoCallback(CGameState *GS, int Player);
  62. bool hasAccess(int playerId) const;
  63. bool isVisible(int3 pos, int Player) const;
  64. bool isVisible(const CGObjectInstance *obj, int Player) const;
  65. bool isVisible(const CGObjectInstance *obj) const;
  66. bool canGetFullInfo(const CGObjectInstance *obj) const; //true we player owns obj or ally owns obj or privileged mode
  67. bool isOwnedOrVisited(const CGObjectInstance *obj) const;
  68. public:
  69. //various
  70. int getDate(Date::EDateType mode=Date::DAY)const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  71. const StartInfo * getStartInfo(bool beforeRandomization = false)const;
  72. bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact; 2 - secondary skill
  73. //player
  74. const PlayerState * getPlayer(int color, bool verbose = true) const;
  75. int getResource(int Player, int which) const;
  76. bool isVisible(int3 pos) const;
  77. PlayerRelations::PlayerRelations getPlayerRelations(TPlayerColor color1, TPlayerColor color2) const;
  78. void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
  79. int getPlayerStatus(int player) const; //-1 if no such player
  80. int getCurrentPlayer() const; //player that currently makes move // TODO synchronous turns
  81. virtual int getLocalPlayer() const; //player that is currently owning given client (if not a client, then returns current player)
  82. const PlayerSettings * getPlayerSettings(int color) const;
  83. //armed object
  84. void getUpgradeInfo(const CArmedInstance *obj, int stackPos, UpgradeInfo &out)const;
  85. //hero
  86. const CGHeroInstance* getHero(int objid) const;
  87. const CGHeroInstance* getHeroWithSubid(int subid) const;
  88. int getHeroCount(int player, bool includeGarrisoned) const;
  89. bool getHeroInfo(const CGObjectInstance *hero, InfoAboutHero &dest) const;
  90. int getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
  91. int estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
  92. const CGHeroInstance* getSelectedHero(int player) const; //NULL if no hero is selected
  93. const CGHeroInstance* getSelectedHero() const; //of current (active) player
  94. //objects
  95. const CGObjectInstance* getObj(int objid, bool verbose = true) const;
  96. std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos)const;
  97. std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true)const;
  98. std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
  99. std::vector <std::string > getObjDescriptions(int3 pos)const; //returns descriptions of objects at pos in order from the lowest to the highest
  100. int getOwner(int heroID) const;
  101. const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //NULL if object has been removed (eg. killed)
  102. //map
  103. int3 guardingCreaturePosition (int3 pos) const;
  104. std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
  105. const CMapHeader * getMapHeader()const;
  106. int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
  107. const TerrainTile * getTile(int3 tile, bool verbose = true) const;
  108. bool isInTheMap(const int3 &pos) const;
  109. //town
  110. const CGTownInstance* getTown(int objid) const;
  111. int howManyTowns(int Player) const;
  112. const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
  113. std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
  114. std::string getTavernGossip(const CGObjectInstance * townOrTavern) const;
  115. int canBuildStructure(const CGTownInstance *t, int ID);//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
  116. std::set<int> getBuildingRequiments(const CGTownInstance *t, int ID);
  117. virtual bool getTownInfo(const CGObjectInstance *town, InfoAboutTown &dest) const;
  118. const CTown *getNativeTown(int color) const;
  119. //from gs
  120. const TeamState *getTeam(ui8 teamID) const;
  121. const TeamState *getPlayerTeam(ui8 color) const;
  122. std::set<int> getBuildingRequiments(const CGTownInstance *t, int ID) const;
  123. int canBuildStructure(const CGTownInstance *t, int ID) const;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
  124. };
  125. class DLL_LINKAGE CPlayerSpecificInfoCallback : public CGameInfoCallback
  126. {
  127. public:
  128. int howManyTowns() const;
  129. int howManyHeroes(bool includeGarrisoned = true) const;
  130. int3 getGrailPos(double &outKnownRatio);
  131. int getMyColor() const;
  132. std::vector <const CGTownInstance *> getTownsInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  133. int getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned=true) const;
  134. const CGTownInstance* getTownBySerial(int serialId) const; // serial id is [0, number of towns)
  135. const CGHeroInstance* getHeroBySerial(int serialId, bool includeGarrisoned=true) const; // serial id is [0, number of heroes)
  136. std::vector <const CGHeroInstance *> getHeroesInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  137. std::vector <const CGDwelling *> getMyDwellings() const; //returns all dwellings that belong to player
  138. std::vector <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player
  139. std::vector <QuestInfo> getMyQuests() const;
  140. int getResourceAmount(int type)const;
  141. TResources getResourceAmount() const;
  142. const std::vector< std::vector< std::vector<ui8> > > & getVisibilityMap()const; //returns visibility map
  143. const PlayerSettings * getPlayerSettings(int color) const;
  144. };
  145. class DLL_LINKAGE CPrivilagedInfoCallback : public CGameInfoCallback
  146. {
  147. public:
  148. CGameState * gameState ();
  149. void getFreeTiles (std::vector<int3> &tiles) const; //used for random spawns
  150. void getTilesInRange(boost::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int player=-1, int mode=0) const; //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only unrevealed
  151. void getAllTiles (boost::unordered_set<int3, ShashInt3> &tiles, int player=-1, int level=-1, int surface=0) const; //returns all tiles on given level (-1 - both levels, otherwise number of level); surface: 0 - land and water, 1 - only land, 2 - only water
  152. ui16 getRandomArt (int flags);
  153. ui16 getArtSync (ui32 rand, int flags); //synchronous
  154. void pickAllowedArtsSet(std::vector<const CArtifact*> &out); //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
  155. void erasePickedArt (si32 id);
  156. void getAllowedSpells(std::vector<ui16> &out, ui16 level);
  157. };
  158. class DLL_LINKAGE CNonConstInfoCallback : public CPrivilagedInfoCallback
  159. {
  160. public:
  161. PlayerState *getPlayer(TPlayerColor color, bool verbose = true);
  162. TeamState *getTeam(ui8 teamID);//get team by team ID
  163. TeamState *getPlayerTeam(TPlayerColor color);// get team by player color
  164. CGHeroInstance *getHero(int objid);
  165. CGTownInstance *getTown(int objid);
  166. TerrainTile * getTile(int3 pos);
  167. };
  168. class DLL_LINKAGE IGameEventRealizer
  169. {
  170. public:
  171. virtual void commitPackage(CPackForClient *pack) = 0;
  172. virtual void showInfoDialog(InfoWindow *iw);
  173. virtual void setObjProperty(int objid, int prop, si64 val);
  174. virtual void showInfoDialog(const std::string &msg, int player);
  175. };
  176. class DLL_LINKAGE IGameEventCallback : public IGameEventRealizer
  177. {
  178. public:
  179. virtual void changeSpells(int hid, bool give, const std::set<ui32> &spells)=0;
  180. virtual bool removeObject(int objid)=0;
  181. virtual void setBlockVis(int objid, bool bv)=0;
  182. virtual void setOwner(int objid, TPlayerColor owner)=0;
  183. virtual void setHoverName(int objid, MetaString * name)=0;
  184. virtual void changePrimSkill(int ID, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
  185. virtual void changeSecSkill(int ID, SecondarySkill::SecondarySkill which, int val, bool abs=false)=0;
  186. virtual void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback)=0;
  187. virtual ui32 showBlockingDialog(BlockingDialog *iw) =0; //synchronous version of above //TODO:
  188. virtual void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) =0; //cb will be called when player closes garrison window
  189. virtual void showThievesGuildWindow(int player, int requestingObjId) =0;
  190. virtual void giveResource(int player, Res::ERes which, int val)=0;
  191. virtual void giveCreatures(const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) =0;
  192. virtual void takeCreatures(int objid, const std::vector<CStackBasicDescriptor> &creatures) =0;
  193. virtual bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false) =0;
  194. virtual bool changeStackType(const StackLocation &sl, CCreature *c) =0;
  195. virtual bool insertNewStack(const StackLocation &sl, const CCreature *c, TQuantity count = -1) =0; //count -1 => moves whole stack
  196. virtual bool eraseStack(const StackLocation &sl, bool forceRemoval = false) =0;
  197. virtual bool swapStacks(const StackLocation &sl1, const StackLocation &sl2) =0;
  198. virtual bool addToSlot(const StackLocation &sl, const CCreature *c, TQuantity count) =0; //makes new stack or increases count of already existing
  199. virtual void tryJoiningArmy(const CArmedInstance *src, const CArmedInstance *dst, bool removeObjWhenFinished, bool allowMerging) =0; //merges army from src do dst or opens a garrison window
  200. virtual bool moveStack(const StackLocation &src, const StackLocation &dst, TQuantity count) = 0;
  201. virtual void giveHeroNewArtifact(const CGHeroInstance *h, const CArtifact *artType, int pos) = 0;
  202. virtual void giveHeroArtifact(const CGHeroInstance *h, const CArtifactInstance *a, int pos) = 0; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
  203. virtual void putArtifact(const ArtifactLocation &al, const CArtifactInstance *a) = 0;
  204. virtual void removeArtifact(const ArtifactLocation &al) = 0;
  205. virtual bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) = 0;
  206. virtual void showCompInfo(ShowInInfobox * comp)=0;
  207. virtual void heroVisitCastle(int obj, int heroID)=0;
  208. virtual void stopHeroVisitCastle(int obj, int heroID)=0;
  209. virtual 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)=0; //use hero=NULL for no hero
  210. virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false)=0; //if any of armies is hero, hero will be used
  211. virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, boost::function<void(BattleResult*)> cb = 0, bool creatureBank = false)=0; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
  212. virtual void setAmount(int objid, ui32 val)=0;
  213. virtual bool moveHero(si32 hid, int3 dst, ui8 instant, ui8 asker = 255)=0;
  214. virtual void giveHeroBonus(GiveBonus * bonus)=0;
  215. virtual void setMovePoints(SetMovePoints * smp)=0;
  216. virtual void setManaPoints(int hid, int val)=0;
  217. virtual void giveHero(int id, int player)=0;
  218. virtual void changeObjPos(int objid, int3 newPos, ui8 flags)=0;
  219. virtual void sendAndApply(CPackForClient * info)=0;
  220. virtual void heroExchange(si32 hero1, si32 hero2)=0; //when two heroes meet on adventure map
  221. virtual void addQuest(int player, QuestInfo & quest){};
  222. };
  223. /// Interface class for handling general game logic and actions
  224. class DLL_LINKAGE IGameCallback : public CPrivilagedInfoCallback, public IGameEventCallback
  225. {
  226. public:
  227. virtual ~IGameCallback(){};
  228. //do sth
  229. const CGObjectInstance *putNewObject(int ID, int subID, int3 pos);
  230. const CGCreature *putNewMonster(int creID, int count, int3 pos);
  231. friend struct CPack;
  232. friend struct CPackForClient;
  233. friend struct CPackForServer;
  234. };