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. #define ASSERT_IF_CALLED_WITH_PLAYER if(!getPlayerID()) {logGlobal->error(BOOST_CURRENT_FUNCTION); assert(0);}
  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. struct TurnTimerInfo;
  35. class CArmedInstance;
  36. class CGObjectInstance;
  37. class CGHeroInstance;
  38. class CGDwelling;
  39. class CGTeleport;
  40. class CGTownInstance;
  41. class DLL_LINKAGE IGameInfoCallback : boost::noncopyable
  42. {
  43. public:
  44. //TODO: all other public methods of CGameInfoCallback
  45. // //various
  46. virtual int getDate(Date 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 std::optional<PlayerColor> getPlayerID() const = 0;
  51. virtual const Player * getPlayer(PlayerColor color) const = 0;
  52. // virtual int getResource(PlayerColor Player, EGameResID which) const = 0;
  53. // bool isVisible(int3 pos) const;
  54. // PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const;
  55. // void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
  56. // EPlayerStatus getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such 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. //town
  87. // const CGTownInstance* getTown(ObjectInstanceID objid) const;
  88. // int howManyTowns(PlayerColor Player) const;
  89. // const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
  90. // std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
  91. // std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
  92. // 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
  93. // virtual bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
  94. //from gs
  95. // const TeamState *getTeam(TeamID teamID) const;
  96. // const TeamState *getPlayerTeam(PlayerColor color) const;
  97. // 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
  98. //teleport
  99. // std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const;
  100. // std::vector<ObjectInstanceID> getTeleportChannelEntraces(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  101. // std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  102. // ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  103. // bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  104. // bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  105. // bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  106. // bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const;
  107. };
  108. class DLL_LINKAGE CGameInfoCallback : public IGameInfoCallback
  109. {
  110. protected:
  111. CGameState * gs;//todo: replace with protected const getter, only actual Server and Client objects should hold game state
  112. CGameInfoCallback() = default;
  113. CGameInfoCallback(CGameState * GS);
  114. bool hasAccess(std::optional<PlayerColor> playerId) const;
  115. bool canGetFullInfo(const CGObjectInstance *obj) const; //true we player owns obj or ally owns obj or privileged mode
  116. bool isOwnedOrVisited(const CGObjectInstance *obj) const;
  117. public:
  118. //various
  119. int getDate(Date mode=Date::DAY)const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  120. virtual const StartInfo * getStartInfo(bool beforeRandomization = false)const;
  121. bool isAllowed(int32_t type, int32_t id) const override; //type: 0 - spell; 1- artifact; 2 - secondary skill
  122. //player
  123. std::optional<PlayerColor> getPlayerID() const override;
  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 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 getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such player
  130. virtual bool isPlayerMakingTurn(PlayerColor player) const; //player that currently makes move // TODO synchronous turns
  131. virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  132. virtual TurnTimerInfo getPlayerTurnTime(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 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 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::vector <const CGTownInstance *> getTownsInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  201. virtual int getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned=true) const;
  202. virtual const CGTownInstance* getTownBySerial(int serialId) const; // serial id is [0, number of towns)
  203. virtual const CGHeroInstance* getHeroBySerial(int serialId, bool includeGarrisoned=true) const; // serial id is [0, number of heroes)
  204. virtual std::vector <const CGHeroInstance *> getHeroesInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  205. virtual std::vector <const CGDwelling *> getMyDwellings() const; //returns all dwellings that belong to player
  206. virtual std::vector <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player
  207. virtual std::vector <QuestInfo> getMyQuests() const;
  208. virtual int getResourceAmount(GameResID type) const;
  209. virtual TResources getResourceAmount() const;
  210. virtual std::shared_ptr<const boost::multi_array<ui8, 3>> getVisibilityMap() const; //returns visibility map
  211. //virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  212. };
  213. VCMI_LIB_NAMESPACE_END