CGameInfoCallback.h 9.1 KB

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