CGameInfoCallback.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 "IGameInfoCallback.h"
  12. #include "../int3.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. struct PlayerSettings;
  15. struct TerrainTile;
  16. struct InfoAboutHero;
  17. struct InfoAboutTown;
  18. struct SThievesGuildInfo;
  19. struct TeamState;
  20. struct TurnTimerInfo;
  21. struct ArtifactLocation;
  22. class IGameSettings;
  23. class PlayerState;
  24. class UpgradeInfo;
  25. class CMapHeader;
  26. class CGameState;
  27. class PathfinderConfig;
  28. class CArtifactSet;
  29. class CArmedInstance;
  30. class CGTeleport;
  31. class CGTownInstance;
  32. class IMarket;
  33. #if SCRIPTING_ENABLED
  34. namespace scripting
  35. {
  36. class Pool;
  37. }
  38. #endif
  39. namespace vstd
  40. {
  41. class RNG;
  42. }
  43. class DLL_LINKAGE CGameInfoCallback : public IGameInfoCallback
  44. {
  45. protected:
  46. bool hasAccess(std::optional<PlayerColor> playerId) const;
  47. bool canGetFullInfo(const CGObjectInstance *obj) const; //true we player owns obj or ally owns obj or privileged mode
  48. bool isOwnedOrVisited(const CGObjectInstance *obj) const;
  49. public:
  50. virtual CGameState & gameState() = 0;
  51. virtual const CGameState & gameState() const = 0;
  52. //various
  53. 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
  54. const StartInfo * getStartInfo() const override;
  55. const StartInfo * getInitialStartInfo() const override;
  56. bool isAllowed(SpellID id) const override;
  57. bool isAllowed(ArtifactID id) const override;
  58. bool isAllowed(SecondarySkill id) const override;
  59. const IGameSettings & getSettings() const;
  60. //player
  61. std::optional<PlayerColor> getPlayerID() const override;
  62. const Player * getPlayer(PlayerColor color) const override;
  63. virtual const PlayerState * getPlayerState(PlayerColor color, bool verbose = true) const;
  64. virtual int getResource(PlayerColor Player, GameResID which) const;
  65. virtual PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const;
  66. virtual void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
  67. virtual EPlayerStatus getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such player
  68. virtual bool isPlayerMakingTurn(PlayerColor player) const; //player that currently makes move // TODO synchronous turns
  69. virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  70. virtual TurnTimerInfo getPlayerTurnTime(PlayerColor color) const;
  71. //map
  72. virtual bool isVisible(int3 pos, const std::optional<PlayerColor> & Player) const;
  73. virtual bool isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & Player) const;
  74. virtual bool isVisible(const CGObjectInstance * obj) const;
  75. virtual bool isVisible(int3 pos) const;
  76. //armed object
  77. virtual void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out) const;
  78. //hero
  79. const CGHeroInstance * getHero(ObjectInstanceID objid) const override;
  80. virtual int getHeroCount(PlayerColor player, bool includeGarrisoned) const;
  81. virtual bool getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject = nullptr) const;
  82. virtual int32_t getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
  83. virtual int64_t estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
  84. virtual const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const;
  85. virtual const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const;
  86. virtual const CArtifactSet * getArtSet(const ArtifactLocation & loc) const;
  87. //virtual const CGObjectInstance * getArmyInstance(ObjectInstanceID oid) const;
  88. //objects
  89. const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const override;
  90. virtual std::vector<const CGObjectInstance *> getBlockingObjs(int3 pos) const;
  91. std::vector<const CGObjectInstance *> getVisitableObjs(int3 pos, bool verbose = true) const override;
  92. std::vector<const CGObjectInstance *> getAllVisitableObjs() const;
  93. virtual std::vector<const CGObjectInstance *> getFlaggableObjects(int3 pos) const;
  94. virtual const CGObjectInstance * getTopObj(int3 pos) const;
  95. virtual PlayerColor getOwner(ObjectInstanceID heroID) const;
  96. virtual const IMarket * getMarket(ObjectInstanceID objid) const;
  97. //map
  98. virtual int3 guardingCreaturePosition (int3 pos) const;
  99. virtual std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
  100. virtual bool isTileGuardedUnchecked(int3 tile) const;
  101. virtual const CMapHeader * getMapHeader()const;
  102. virtual int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
  103. virtual const TerrainTile * getTile(int3 tile, bool verbose = true) const;
  104. virtual const TerrainTile * getTileUnchecked(int3 tile) const;
  105. virtual bool isInTheMap(const int3 &pos) const;
  106. virtual void getVisibleTilesInRange(std::unordered_set<int3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
  107. virtual void calculatePaths(const std::shared_ptr<PathfinderConfig> & config) const;
  108. virtual EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const;
  109. //town
  110. virtual const CGTownInstance* getTown(ObjectInstanceID objid) const;
  111. virtual int howManyTowns(PlayerColor Player) const;
  112. //virtual const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
  113. virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
  114. virtual std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
  115. 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
  116. virtual bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
  117. //from gs
  118. virtual const TeamState *getTeam(TeamID teamID) const;
  119. virtual const TeamState *getPlayerTeam(PlayerColor color) const;
  120. //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
  121. //teleport
  122. virtual std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const;
  123. virtual std::vector<ObjectInstanceID> getTeleportChannelEntrances(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  124. virtual std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  125. virtual ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  126. virtual bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  127. virtual bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  128. virtual bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  129. virtual bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const;
  130. //used for random spawns
  131. void getFreeTiles(std::vector<int3> &tiles) const;
  132. //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only revealed
  133. void getTilesInRange(std::unordered_set<int3> & tiles,
  134. const int3 & pos,
  135. int radius,
  136. ETileVisibility mode,
  137. std::optional<PlayerColor> player = std::optional<PlayerColor>(),
  138. int3::EDistanceFormula formula = int3::DIST_2D) const;
  139. //returns all tiles on given level (-1 - both levels, otherwise number of level)
  140. void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player, int level, std::function<bool(const TerrainTile *)> filter) const;
  141. //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
  142. void pickAllowedArtsSet(std::vector<ArtifactID> & out, vstd::RNG & rand);
  143. void getAllowedSpells(std::vector<SpellID> &out, std::optional<ui16> level = std::nullopt);
  144. #if SCRIPTING_ENABLED
  145. virtual scripting::Pool * getGlobalContextPool() const;
  146. #endif
  147. };
  148. VCMI_LIB_NAMESPACE_END