IGameInfoCallback.h 7.6 KB

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