CGameInfoCallback.h 15 KB

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