CGameInfoCallback.h 15 KB

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