CGameInfoCallback.h 15 KB

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