CGameInfoCallback.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * CGameInfoCallback.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "int3.h"
  12. #include "ResourceSet.h" // for Res::ERes
  13. #include "battle/CCallbackBase.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class Player;
  16. class Team;
  17. struct InfoWindow;
  18. struct PlayerSettings;
  19. struct CPackForClient;
  20. struct TerrainTile;
  21. struct PlayerState;
  22. class CTown;
  23. struct StartInfo;
  24. struct CPathsInfo;
  25. struct InfoAboutHero;
  26. struct InfoAboutTown;
  27. struct UpgradeInfo;
  28. struct SThievesGuildInfo;
  29. class CMapHeader;
  30. struct TeamState;
  31. struct QuestInfo;
  32. struct ShashInt3;
  33. class CGameState;
  34. class PathfinderConfig;
  35. class CArmedInstance;
  36. class CGObjectInstance;
  37. class CGHeroInstance;
  38. class CGDwelling;
  39. class CGTeleport;
  40. class CGTownInstance;
  41. class DLL_LINKAGE IGameInfoCallback
  42. {
  43. public:
  44. //TODO: all other public methods of CGameInfoCallback
  45. // //various
  46. virtual int getDate(Date::EDateType mode=Date::DAY) const = 0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  47. // const StartInfo * getStartInfo(bool beforeRandomization = false)const;
  48. virtual bool isAllowed(int32_t type, int32_t id) const = 0; //type: 0 - spell; 1- artifact; 2 - secondary skill
  49. //player
  50. virtual const Player * getPlayer(PlayerColor color) const = 0;
  51. // virtual int getResource(PlayerColor Player, Res::ERes which) const = 0;
  52. // bool isVisible(int3 pos) const;
  53. // PlayerRelations::PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const;
  54. // void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
  55. // EPlayerStatus::EStatus getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such player
  56. // PlayerColor getCurrentPlayer() const; //player that currently makes move // TODO synchronous turns
  57. virtual PlayerColor getLocalPlayer() const = 0; //player that is currently owning given client (if not a client, then returns current player)
  58. // const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  59. // //armed object
  60. // void getUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out)const;
  61. //hero
  62. virtual const CGHeroInstance * getHero(ObjectInstanceID objid) const = 0;
  63. virtual const CGHeroInstance * getHeroWithSubid(int subid) const = 0;
  64. // int getHeroCount(PlayerColor player, bool includeGarrisoned) const;
  65. // bool getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject = nullptr) const;
  66. // int32_t getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
  67. // int64_t estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
  68. // const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const;
  69. // const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const;
  70. // const CGObjectInstance * getArmyInstance(ObjectInstanceID oid) const;
  71. //objects
  72. virtual const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const = 0;
  73. // std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos) const;
  74. virtual std::vector<const CGObjectInstance *> getVisitableObjs(int3 pos, bool verbose = true) const = 0;
  75. // std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
  76. // const CGObjectInstance * getTopObj (int3 pos) const;
  77. // PlayerColor getOwner(ObjectInstanceID heroID) const;
  78. // const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //nullptr if object has been removed (eg. killed)
  79. //map
  80. // int3 guardingCreaturePosition (int3 pos) const;
  81. // std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
  82. // const CMapHeader * getMapHeader()const;
  83. // int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
  84. // const TerrainTile * getTile(int3 tile, bool verbose = true) const;
  85. // std::shared_ptr<boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const;
  86. // bool isInTheMap(const int3 &pos) const;
  87. // void getVisibleTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
  88. //town
  89. // const CGTownInstance* getTown(ObjectInstanceID objid) const;
  90. // int howManyTowns(PlayerColor Player) const;
  91. // const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
  92. // std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
  93. // std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
  94. // EBuildingState::EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID 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
  95. // virtual bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
  96. // const CTown *getNativeTown(PlayerColor color) const;
  97. //from gs
  98. // const TeamState *getTeam(TeamID teamID) const;
  99. // const TeamState *getPlayerTeam(PlayerColor color) const;
  100. // EBuildingState::EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID 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
  101. //teleport
  102. // std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const;
  103. // std::vector<ObjectInstanceID> getTeleportChannelEntraces(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  104. // std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  105. // ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  106. // bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  107. // bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  108. // bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  109. // bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const;
  110. };
  111. class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase, public IGameInfoCallback
  112. {
  113. protected:
  114. CGameState * gs;//todo: replace with protected const getter, only actual Server and Client objects should hold game state
  115. CGameInfoCallback();
  116. CGameInfoCallback(CGameState *GS, boost::optional<PlayerColor> Player);
  117. bool hasAccess(boost::optional<PlayerColor> playerId) const;
  118. bool canGetFullInfo(const CGObjectInstance *obj) const; //true we player owns obj or ally owns obj or privileged mode
  119. bool isOwnedOrVisited(const CGObjectInstance *obj) const;
  120. public:
  121. //various
  122. int getDate(Date::EDateType mode=Date::DAY)const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  123. virtual const StartInfo * getStartInfo(bool beforeRandomization = false)const;
  124. bool isAllowed(int32_t type, int32_t id) const override; //type: 0 - spell; 1- artifact; 2 - secondary skill
  125. //player
  126. const Player * getPlayer(PlayerColor color) const override;
  127. virtual const PlayerState * getPlayerState(PlayerColor color, bool verbose = true) const;
  128. virtual int getResource(PlayerColor Player, Res::ERes which) const;
  129. virtual PlayerRelations::PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const;
  130. virtual void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
  131. virtual EPlayerStatus::EStatus getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such player
  132. virtual PlayerColor getCurrentPlayer() const; //player that currently makes move // TODO synchronous turns
  133. PlayerColor getLocalPlayer() const override; //player that is currently owning given client (if not a client, then returns current player)
  134. virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  135. //map
  136. virtual bool isVisible(int3 pos, boost::optional<PlayerColor> Player) const;
  137. virtual bool isVisible(const CGObjectInstance *obj, boost::optional<PlayerColor> Player) const;
  138. virtual bool isVisible(const CGObjectInstance *obj) const;
  139. virtual bool isVisible(int3 pos) const;
  140. //armed object
  141. virtual void getUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out)const;
  142. //hero
  143. virtual const CGHeroInstance * getHero(ObjectInstanceID objid) const override;
  144. const CGHeroInstance * getHeroWithSubid(int subid) const override;
  145. virtual int getHeroCount(PlayerColor player, bool includeGarrisoned) const;
  146. virtual bool getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject = nullptr) const;
  147. virtual int32_t getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
  148. virtual int64_t estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
  149. virtual const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const;
  150. virtual const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const;
  151. //virtual const CGObjectInstance * getArmyInstance(ObjectInstanceID oid) const;
  152. //objects
  153. virtual const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const override;
  154. virtual std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos)const;
  155. virtual std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true) const override;
  156. virtual std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
  157. virtual const CGObjectInstance * getTopObj (int3 pos) const;
  158. virtual PlayerColor getOwner(ObjectInstanceID heroID) const;
  159. virtual const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //nullptr if object has been removed (eg. killed)
  160. //map
  161. virtual int3 guardingCreaturePosition (int3 pos) const;
  162. virtual std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
  163. virtual const CMapHeader * getMapHeader()const;
  164. virtual int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
  165. virtual const TerrainTile * getTile(int3 tile, bool verbose = true) const;
  166. virtual std::shared_ptr<const boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const;
  167. virtual bool isInTheMap(const int3 &pos) const;
  168. virtual void getVisibleTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
  169. virtual void calculatePaths(std::shared_ptr<PathfinderConfig> config);
  170. virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out);
  171. //town
  172. virtual const CGTownInstance* getTown(ObjectInstanceID objid) const;
  173. virtual int howManyTowns(PlayerColor Player) const;
  174. //virtual const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
  175. virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
  176. virtual std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
  177. virtual EBuildingState::EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID 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
  178. virtual bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
  179. virtual const CTown *getNativeTown(PlayerColor color) const;
  180. //from gs
  181. virtual const TeamState *getTeam(TeamID teamID) const;
  182. virtual const TeamState *getPlayerTeam(PlayerColor color) const;
  183. //virtual EBuildingState::EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID 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
  184. //teleport
  185. virtual std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const;
  186. virtual std::vector<ObjectInstanceID> getTeleportChannelEntraces(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  187. virtual std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  188. virtual ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  189. virtual bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  190. virtual bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  191. virtual bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  192. virtual bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const;
  193. };
  194. class DLL_LINKAGE CPlayerSpecificInfoCallback : public CGameInfoCallback
  195. {
  196. public:
  197. // keep player-specific override in scope
  198. using CGameInfoCallback::howManyTowns;
  199. virtual int howManyTowns() const;
  200. virtual int howManyHeroes(bool includeGarrisoned = true) const;
  201. virtual int3 getGrailPos(double *outKnownRatio);
  202. virtual boost::optional<PlayerColor> getMyColor() const;
  203. virtual std::vector <const CGTownInstance *> getTownsInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  204. virtual int getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned=true) const;
  205. virtual const CGTownInstance* getTownBySerial(int serialId) const; // serial id is [0, number of towns)
  206. virtual const CGHeroInstance* getHeroBySerial(int serialId, bool includeGarrisoned=true) const; // serial id is [0, number of heroes)
  207. virtual std::vector <const CGHeroInstance *> getHeroesInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  208. virtual std::vector <const CGDwelling *> getMyDwellings() const; //returns all dwellings that belong to player
  209. virtual std::vector <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player
  210. virtual std::vector <QuestInfo> getMyQuests() const;
  211. virtual int getResourceAmount(Res::ERes type) const;
  212. virtual TResources getResourceAmount() const;
  213. virtual std::shared_ptr<const boost::multi_array<ui8, 3>> getVisibilityMap() const; //returns visibility map
  214. //virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  215. };
  216. VCMI_LIB_NAMESPACE_END