CGameInfoCallback.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 "ResourceSet.h" // for Res::ERes
  12. #include "battle/CPlayerBattleCallback.h"
  13. class CGObjectInstance;
  14. struct InfoWindow;
  15. struct PlayerSettings;
  16. struct CPackForClient;
  17. struct TerrainTile;
  18. struct PlayerState;
  19. class CTown;
  20. struct StartInfo;
  21. struct InfoAboutTown;
  22. struct UpgradeInfo;
  23. struct SThievesGuildInfo;
  24. class CGDwelling;
  25. class CGTeleport;
  26. class CMapHeader;
  27. struct TeamState;
  28. struct QuestInfo;
  29. class int3;
  30. struct ShashInt3;
  31. class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase
  32. {
  33. protected:
  34. CGameInfoCallback();
  35. CGameInfoCallback(CGameState *GS, boost::optional<PlayerColor> Player);
  36. bool hasAccess(boost::optional<PlayerColor> playerId) const;
  37. bool isVisible(int3 pos, boost::optional<PlayerColor> Player) const;
  38. bool isVisible(const CGObjectInstance *obj, boost::optional<PlayerColor> Player) const;
  39. bool isVisible(const CGObjectInstance *obj) const;
  40. bool canGetFullInfo(const CGObjectInstance *obj) const; //true we player owns obj or ally owns obj or privileged mode
  41. bool isOwnedOrVisited(const CGObjectInstance *obj) const;
  42. public:
  43. //various
  44. int getDate(Date::EDateType mode=Date::DAY)const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  45. const StartInfo * getStartInfo(bool beforeRandomization = false)const;
  46. bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact; 2 - secondary skill
  47. //player
  48. const PlayerState * getPlayer(PlayerColor color, bool verbose = true) const;
  49. int getResource(PlayerColor Player, Res::ERes which) const;
  50. bool isVisible(int3 pos) const;
  51. PlayerRelations::PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const;
  52. void getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj); //get thieves' guild info obtainable while visiting given object
  53. EPlayerStatus::EStatus getPlayerStatus(PlayerColor player, bool verbose = true) const; //-1 if no such player
  54. PlayerColor getCurrentPlayer() const; //player that currently makes move // TODO synchronous turns
  55. virtual PlayerColor getLocalPlayer() const; //player that is currently owning given client (if not a client, then returns current player)
  56. const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  57. //armed object
  58. void getUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out)const;
  59. //hero
  60. const CGHeroInstance* getHero(ObjectInstanceID objid) const;
  61. const CGHeroInstance* getHeroWithSubid(int subid) const;
  62. int getHeroCount(PlayerColor player, bool includeGarrisoned) const;
  63. bool getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject = nullptr) const;
  64. int getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const; //when called during battle, takes into account creatures' spell cost reduction
  65. int estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const; //estimates damage of given spell; returns 0 if spell causes no dmg
  66. const CArtifactInstance * getArtInstance(ArtifactInstanceID aid) const;
  67. const CGObjectInstance * getObjInstance(ObjectInstanceID oid) const;
  68. //objects
  69. const CGObjectInstance* getObj(ObjectInstanceID objid, bool verbose = true) const;
  70. std::vector <const CGObjectInstance * > getBlockingObjs(int3 pos)const;
  71. std::vector <const CGObjectInstance * > getVisitableObjs(int3 pos, bool verbose = true)const;
  72. std::vector <const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
  73. const CGObjectInstance * getTopObj (int3 pos) const;
  74. PlayerColor getOwner(ObjectInstanceID heroID) const;
  75. const CGObjectInstance *getObjByQuestIdentifier(int identifier) const; //nullptr if object has been removed (eg. killed)
  76. //map
  77. int3 guardingCreaturePosition (int3 pos) const;
  78. std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
  79. const CMapHeader * getMapHeader()const;
  80. int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
  81. const TerrainTile * getTile(int3 tile, bool verbose = true) const;
  82. std::shared_ptr<boost::multi_array<TerrainTile*, 3>> getAllVisibleTiles() const;
  83. bool isInTheMap(const int3 &pos) const;
  84. void getVisibleTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int3::EDistanceFormula distanceFormula = int3::DIST_2D) const;
  85. //town
  86. const CGTownInstance* getTown(ObjectInstanceID objid) const;
  87. int howManyTowns(PlayerColor Player) const;
  88. const CGTownInstance * getTownInfo(int val, bool mode)const; //mode = 0 -> val = player town serial; mode = 1 -> val = object id (serial)
  89. std::vector<const CGHeroInstance *> getAvailableHeroes(const CGObjectInstance * townOrTavern) const; //heroes that can be recruited
  90. std::string getTavernRumor(const CGObjectInstance * townOrTavern) const;
  91. EBuildingState::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
  92. virtual bool getTownInfo(const CGObjectInstance * town, InfoAboutTown & dest, const CGObjectInstance * selectedObject = nullptr) const;
  93. const CTown *getNativeTown(PlayerColor color) const;
  94. //from gs
  95. const TeamState *getTeam(TeamID teamID) const;
  96. const TeamState *getPlayerTeam(PlayerColor color) const;
  97. EBuildingState::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
  98. //teleport
  99. std::vector<ObjectInstanceID> getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const;
  100. std::vector<ObjectInstanceID> getTeleportChannelEntraces(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  101. std::vector<ObjectInstanceID> getTeleportChannelExits(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const;
  102. ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  103. bool isTeleportChannelImpassable(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  104. bool isTeleportChannelBidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  105. bool isTeleportChannelUnidirectional(TeleportChannelID id, PlayerColor player = PlayerColor::UNFLAGGABLE) const;
  106. bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor player) const;
  107. };
  108. class DLL_LINKAGE CPlayerSpecificInfoCallback : public CGameInfoCallback
  109. {
  110. public:
  111. int howManyTowns() const;
  112. int howManyHeroes(bool includeGarrisoned = true) const;
  113. int3 getGrailPos(double *outKnownRatio);
  114. boost::optional<PlayerColor> getMyColor() const;
  115. std::vector <const CGTownInstance *> getTownsInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  116. int getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned=true) const;
  117. const CGTownInstance* getTownBySerial(int serialId) const; // serial id is [0, number of towns)
  118. const CGHeroInstance* getHeroBySerial(int serialId, bool includeGarrisoned=true) const; // serial id is [0, number of heroes)
  119. std::vector <const CGHeroInstance *> getHeroesInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
  120. std::vector <const CGDwelling *> getMyDwellings() const; //returns all dwellings that belong to player
  121. std::vector <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player
  122. std::vector <QuestInfo> getMyQuests() const;
  123. int getResourceAmount(Res::ERes type) const;
  124. TResources getResourceAmount() const;
  125. const std::vector< std::vector< std::vector<ui8> > > & getVisibilityMap()const; //returns visibility map
  126. const PlayerSettings * getPlayerSettings(PlayerColor color) const;
  127. };
  128. class DLL_LINKAGE IGameEventRealizer
  129. {
  130. public:
  131. virtual void commitPackage(CPackForClient *pack) = 0;
  132. virtual void showInfoDialog(InfoWindow *iw);
  133. virtual void setObjProperty(ObjectInstanceID objid, int prop, si64 val);
  134. virtual void showInfoDialog(const std::string &msg, PlayerColor player);
  135. };