CGameInfoCallback.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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(SpellID id) const = 0;
  51. virtual bool isAllowed(ArtifactID id) const = 0;
  52. virtual bool isAllowed(SecondarySkill id) const = 0;
  53. //player
  54. virtual std::optional<PlayerColor> getPlayerID() const = 0;
  55. virtual const Player * getPlayer(PlayerColor color) const = 0;
  56. // virtual int getResource(PlayerColor Player, EGameResID which) const = 0;
  57. // bool isVisible(int3 pos) const;
  58. // PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const;
  59. // void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
  60. // EPlayerStatus getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such player
  61. // const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  62. // //armed object
  63. // void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out)const;
  64. //hero
  65. virtual const CGHeroInstance * getHero(ObjectInstanceID objid) const = 0;
  66. virtual const CGHeroInstance * getHeroWithSubid(int subid) const = 0;
  67. // int getHeroCount(PlayerColor player, bool includeGarrisoned) const;
  68. // bool getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject = nullptr) const;
  69. // int32_t getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
  70. // int64_t estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
  71. // const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const;
  72. // const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const;
  73. // const CGObjectInstance * getArmyInstance(ObjectInstanceID oid) const;
  74. //objects
  75. virtual const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const = 0;
  76. // std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos) const;
  77. virtual std::vector<const CGObjectInstance *> getVisitableObjs(int3 pos, bool verbose = true) const = 0;
  78. // std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
  79. // const CGObjectInstance * getTopObj (int3 pos) const;
  80. // PlayerColor getOwner(ObjectInstanceID heroID) const;
  81. //map
  82. // int3 guardingCreaturePosition (int3 pos) const;
  83. // std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
  84. // const CMapHeader * getMapHeader()const;
  85. // int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
  86. // const TerrainTile * getTile(int3 tile, bool verbose = true) const;
  87. // std::shared_ptr<boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const;
  88. // bool isInTheMap(const int3 &pos) const;
  89. //town
  90. // const CGTownInstance* getTown(ObjectInstanceID objid) const;
  91. // int howManyTowns(PlayerColor Player) const;
  92. // const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
  93. // std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
  94. // std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
  95. // 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
  96. // virtual bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
  97. //from gs
  98. // const TeamState *getTeam(TeamID teamID) const;
  99. // const TeamState *getPlayerTeam(PlayerColor color) const;
  100. // 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 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);
  117. bool hasAccess(std::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 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(SpellID id) const override;
  125. bool isAllowed(ArtifactID id) const override;
  126. bool isAllowed(SecondarySkill id) const override;
  127. //player
  128. std::optional<PlayerColor> getPlayerID() const override;
  129. const Player * getPlayer(PlayerColor color) const override;
  130. virtual const PlayerState * getPlayerState(PlayerColor color, bool verbose = true) const;
  131. virtual int getResource(PlayerColor Player, GameResID which) const;
  132. virtual PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const;
  133. virtual void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
  134. virtual EPlayerStatus getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such player
  135. virtual bool isPlayerMakingTurn(PlayerColor player) const; //player that currently makes move // TODO synchronous turns
  136. virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  137. virtual TurnTimerInfo getPlayerTurnTime(PlayerColor color) const;
  138. //map
  139. virtual bool isVisible(int3 pos, const std::optional<PlayerColor> & Player) const;
  140. virtual bool isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & Player) const;
  141. virtual bool isVisible(const CGObjectInstance * obj) const;
  142. virtual bool isVisible(int3 pos) const;
  143. //armed object
  144. virtual void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out)const;
  145. //hero
  146. virtual const CGHeroInstance * getHero(ObjectInstanceID objid) const override;
  147. const CGHeroInstance * getHeroWithSubid(int subid) const override;
  148. virtual int getHeroCount(PlayerColor player, bool includeGarrisoned) const;
  149. virtual bool getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject = nullptr) const;
  150. virtual int32_t getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
  151. virtual int64_t estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
  152. virtual const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const;
  153. virtual const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const;
  154. virtual const CArtifactSet * getArtSet(const ArtifactLocation & loc) const;
  155. //virtual const CGObjectInstance * getArmyInstance(ObjectInstanceID oid) const;
  156. //objects
  157. virtual const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const override;
  158. virtual std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos)const;
  159. virtual std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true) const override;
  160. virtual std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
  161. virtual const CGObjectInstance * getTopObj (int3 pos) const;
  162. virtual PlayerColor getOwner(ObjectInstanceID heroID) const;
  163. //map
  164. virtual int3 guardingCreaturePosition (int3 pos) const;
  165. virtual std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
  166. virtual const CMapHeader * getMapHeader()const;
  167. virtual int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
  168. virtual const TerrainTile * getTile(int3 tile, bool verbose = true) const;
  169. virtual const TerrainTile * getTileForDimensionDoor(int3 tile, const CGHeroInstance * castingHero) const;
  170. virtual std::shared_ptr<const boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const;
  171. virtual bool isInTheMap(const int3 &pos) const;
  172. virtual void getVisibleTilesInRange(std::unordered_set<int3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
  173. virtual void calculatePaths(const std::shared_ptr<PathfinderConfig> & config);
  174. virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out);
  175. virtual EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const;
  176. //town
  177. virtual const CGTownInstance* getTown(ObjectInstanceID objid) const;
  178. virtual int howManyTowns(PlayerColor Player) const;
  179. //virtual const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
  180. virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
  181. virtual std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
  182. 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
  183. virtual bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
  184. //from gs
  185. virtual const TeamState *getTeam(TeamID teamID) const;
  186. virtual const TeamState *getPlayerTeam(PlayerColor color) const;
  187. //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
  188. //teleport
  189. virtual std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const;
  190. virtual std::vector<ObjectInstanceID> getTeleportChannelEntraces(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  191. virtual std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  192. virtual ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  193. virtual bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  194. virtual bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  195. virtual bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  196. virtual bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const;
  197. };
  198. class DLL_LINKAGE CPlayerSpecificInfoCallback : public CGameInfoCallback
  199. {
  200. public:
  201. // keep player-specific override in scope
  202. using CGameInfoCallback::howManyTowns;
  203. virtual int howManyTowns() const;
  204. virtual int howManyHeroes(bool includeGarrisoned = true) const;
  205. virtual int3 getGrailPos(double *outKnownRatio);
  206. virtual std::vector <const CGTownInstance *> getTownsInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  207. virtual int getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned=true) const;
  208. virtual const CGTownInstance* getTownBySerial(int serialId) const; // serial id is [0, number of towns)
  209. virtual const CGHeroInstance* getHeroBySerial(int serialId, bool includeGarrisoned=true) const; // serial id is [0, number of heroes)
  210. virtual std::vector <const CGHeroInstance *> getHeroesInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  211. virtual std::vector <const CGDwelling *> getMyDwellings() const; //returns all dwellings that belong to player
  212. virtual std::vector <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player
  213. virtual std::vector <QuestInfo> getMyQuests() const;
  214. virtual int getResourceAmount(GameResID type) const;
  215. virtual TResources getResourceAmount() const;
  216. };
  217. VCMI_LIB_NAMESPACE_END