IGameInfoCallback.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * IGameInfoCallback.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 "../constants/EntityIdentifiers.h"
  12. #include "../constants/Enumerations.h"
  13. #include "../int3.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. struct StartInfo;
  16. class CGHeroInstance;
  17. class CGObjectInstance;
  18. struct PlayerSettings;
  19. struct TerrainTile;
  20. struct InfoAboutHero;
  21. struct InfoAboutTown;
  22. struct TeamState;
  23. struct TurnTimerInfo;
  24. struct ArtifactLocation;
  25. class IGameSettings;
  26. class PlayerState;
  27. class UpgradeInfo;
  28. class CMapHeader;
  29. class CGameState;
  30. class PathfinderConfig;
  31. class CArtifactSet;
  32. class CArmedInstance;
  33. class CGTeleport;
  34. class CGTownInstance;
  35. class IMarket;
  36. using FowTilesType = std::set<int3>;
  37. #if SCRIPTING_ENABLED
  38. namespace scripting
  39. {
  40. class Pool;
  41. }
  42. #endif
  43. namespace vstd
  44. {
  45. class RNG;
  46. }
  47. /// Provide interfaces through which map objects can access game state data
  48. /// TODO: currently it is also used as Environment::GameCb. Consider separating these two interfaces
  49. class DLL_LINKAGE IGameInfoCallback : boost::noncopyable
  50. {
  51. public:
  52. ~IGameInfoCallback() = default;
  53. /// Access underlying non-const gamestate
  54. /// TODO: remove ASAP
  55. virtual CGameState & gameState() = 0;
  56. /// Access underlying gamestate
  57. /// TODO: remove
  58. virtual const CGameState & gameState() const = 0;
  59. /// Returns current date:
  60. /// DAY - number of days since start of the game (1..inf)
  61. /// DAY_OF_WEEK - number of days since start of the week (1..7)
  62. /// WEEK - number of week within month (1..4)
  63. /// MONTH - current month (1..inf)
  64. /// DAY_OF_MONTH - number of day within current month, (1..28)
  65. virtual int getDate(Date mode=Date::DAY) const = 0;
  66. /// Return pointer to static map header for current map
  67. virtual const CMapHeader * getMapHeader() const = 0;
  68. /// Returns post-randomized startin information on current game
  69. virtual const StartInfo * getStartInfo() const = 0;
  70. /// Returns true if corresponding spell is allowed, and not banned in map settings
  71. virtual bool isAllowed(SpellID id) const = 0;
  72. /// Returns true if corresponding artifact is allowed, and not banned in map settings
  73. virtual bool isAllowed(ArtifactID id) const = 0;
  74. /// Returns true if corresponding secondary skill is allowed, and not banned in map settings
  75. virtual bool isAllowed(SecondarySkill id) const = 0;
  76. /// Returns true if specified tile is visible for specific player. Player must be valid
  77. virtual bool isVisibleFor(int3 pos, PlayerColor player) const = 0;
  78. /// Returns true if specified object is visible for specific player. Player must be valid
  79. virtual bool isVisibleFor(const CGObjectInstance * obj, PlayerColor player) const = 0;
  80. //// Returns game settings for current map
  81. virtual const IGameSettings & getSettings() const = 0;
  82. /// Returns dimesions for current map. 'z' coordinate indicates number of level (2 for maps with underground layer)
  83. virtual int3 getMapSize() const = 0;
  84. /// Returns true if tile with specified position exists within map
  85. virtual bool isInTheMap(const int3 &pos) const = 0;
  86. /// Returns pointer to specified team. Team must be valid
  87. virtual const TeamState * getTeam(TeamID teamID) const = 0;
  88. /// Returns pointer to specified team. Player must be valid. Players without belong to a team with single member
  89. virtual const TeamState * getPlayerTeam(PlayerColor color) const = 0;
  90. /// Returns current state of a specific player. Player must be valid
  91. virtual const PlayerState * getPlayerState(PlayerColor color, bool verbose = true) const = 0;
  92. /// Returns starting settings of a specified player. Player must be valid
  93. virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const = 0;
  94. /// Returns relations (allies, enemies, etc) of two specified, valid players
  95. virtual PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const = 0;
  96. /// Returns number of wandering heroes or wandering and garrisoned heroes for specified player
  97. virtual int getHeroCount(PlayerColor player, bool includeGarrisoned) const = 0;
  98. /// Returns in-game status if specified player. Player must be valid
  99. virtual EPlayerStatus getPlayerStatus(PlayerColor player, bool verbose = true) const = 0;
  100. /// Returns amount of resource of a specific type owned by a specified player
  101. virtual int getResource(PlayerColor Player, GameResID which) const = 0;
  102. /// Returns pointer to hero using provided object ID. Returns null on failure
  103. virtual const CGHeroInstance * getHero(ObjectInstanceID objid) const = 0;
  104. /// Returns pointer to town using provided object ID. Returns null on failure
  105. virtual const CGTownInstance * getTown(ObjectInstanceID objid) const = 0;
  106. /// Returns pointer to object using provided object ID. Returns null on failure
  107. virtual const CGObjectInstance * getObj(ObjectInstanceID objid, bool verbose = true) const = 0;
  108. /// Returns pointer to object using provided object ID. Returns null on failure
  109. virtual const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const = 0;
  110. /// Returns pointer to artifact using provided object ID. Returns null on failure
  111. virtual const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const = 0;
  112. /// Returns pointer to specified tile or nullptr on error
  113. virtual const TerrainTile * getTile(int3 tile, bool verbose = true) const = 0;
  114. /// Returns pointer to specified tile without checking for permissions. Avoid its usage!
  115. virtual const TerrainTile * getTileUnchecked(int3 tile) const = 0;
  116. /// Returns pointer to top-most object on specified tile, or nullptr on error
  117. virtual const CGObjectInstance * getTopObj(int3 pos) const = 0;
  118. /// Returns whether it is possible to dig for Grail on specified tile
  119. virtual EDiggingStatus getTileDigStatus(int3 tile, bool verbose = true) const = 0;
  120. /// Calculates pathfinding data into specified pathfinder config
  121. virtual void calculatePaths(const std::shared_ptr<PathfinderConfig> & config) const = 0;
  122. /// Returns position of creature that guards specified tile, or invalid tile if there are no guards
  123. virtual int3 guardingCreaturePosition (int3 pos) const = 0;
  124. /// Return true if src tile is visitable from dst tile
  125. virtual bool checkForVisitableDir(const int3 & src, const int3 & dst) const = 0;
  126. /// Returns all wandering monsters that guard specified tile
  127. virtual std::vector<const CGObjectInstance *> getGuardingCreatures (int3 pos) const = 0;
  128. /// Returns if tile is guarded by wandering monsters without checking whether player has access to the tile. AVOID USAGE.
  129. virtual bool isTileGuardedUnchecked(int3 tile) const = 0;
  130. /// Returns all tiles within specified range with specific tile visibility mode
  131. virtual void getTilesInRange(FowTilesType & tiles, const int3 & pos, int radius, ETileVisibility mode, std::optional<PlayerColor> player = std::optional<PlayerColor>(), int3::EDistanceFormula formula = int3::DIST_2D) const = 0;
  132. /// returns all tiles on given level (-1 - both levels, otherwise number of level)
  133. virtual void getAllTiles(FowTilesType &tiles, std::optional<PlayerColor> player, int level, const std::function<bool(const TerrainTile *)> & filter) const = 0;
  134. virtual std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const = 0;
  135. virtual std::vector<ObjectInstanceID> getTeleportChannelEntrances(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const = 0;
  136. virtual std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const = 0;
  137. virtual bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const = 0;
  138. virtual bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const = 0;
  139. virtual bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const = 0;
  140. virtual bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const = 0;
  141. #if SCRIPTING_ENABLED
  142. virtual scripting::Pool * getGlobalContextPool() const = 0;
  143. #endif
  144. };
  145. VCMI_LIB_NAMESPACE_END