IGameCallback.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * IGameCallback.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 <vcmi/Metatype.h>
  12. #include "CGameInfoCallback.h" // for CGameInfoCallback
  13. #include "networkPacks/ObjProperty.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. namespace vstd
  16. {
  17. class RNG;
  18. }
  19. struct SetMovePoints;
  20. struct GiveBonus;
  21. struct BlockingDialog;
  22. struct TeleportDialog;
  23. struct StackLocation;
  24. struct ArtifactLocation;
  25. struct BankConfig;
  26. struct BattleLayout;
  27. class CCreatureSet;
  28. class CStackBasicDescriptor;
  29. class CGCreature;
  30. class CSaveFile;
  31. class CLoadFile;
  32. class IObjectInterface;
  33. enum class EOpenWindowMode : uint8_t;
  34. namespace spells
  35. {
  36. class Caster;
  37. }
  38. namespace Rewardable
  39. {
  40. struct Configuration;
  41. }
  42. #if SCRIPTING_ENABLED
  43. namespace scripting
  44. {
  45. class Pool;
  46. }
  47. #endif
  48. class DLL_LINKAGE CPrivilegedInfoCallback : public CGameInfoCallback
  49. {
  50. public:
  51. CGameState *gameState();
  52. //used for random spawns
  53. void getFreeTiles(std::vector<int3> &tiles) const;
  54. //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only revealed
  55. void getTilesInRange(std::unordered_set<int3> & tiles,
  56. const int3 & pos,
  57. int radius,
  58. ETileVisibility mode,
  59. std::optional<PlayerColor> player = std::optional<PlayerColor>(),
  60. int3::EDistanceFormula formula = int3::DIST_2D) const;
  61. //returns all tiles on given level (-1 - both levels, otherwise number of level)
  62. void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player, int level, std::function<bool(const TerrainTile *)> filter) const;
  63. //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
  64. void pickAllowedArtsSet(std::vector<const CArtifact *> & out, vstd::RNG & rand);
  65. void getAllowedSpells(std::vector<SpellID> &out, std::optional<ui16> level = std::nullopt);
  66. void saveCommonState(CSaveFile &out) const; //stores GS and VLC
  67. void loadCommonState(CLoadFile &in); //loads GS and VLC
  68. };
  69. class DLL_LINKAGE IGameEventCallback
  70. {
  71. public:
  72. virtual void setObjPropertyValue(ObjectInstanceID objid, ObjProperty prop, int32_t value = 0) = 0;
  73. virtual void setBankObjectConfiguration(ObjectInstanceID objid, const BankConfig & configuration) = 0;
  74. virtual void setRewardableObjectConfiguration(ObjectInstanceID mapObjectID, const Rewardable::Configuration & configuration) = 0;
  75. virtual void setRewardableObjectConfiguration(ObjectInstanceID townInstanceID, BuildingID buildingID, const Rewardable::Configuration & configuration) = 0;
  76. virtual void setObjPropertyID(ObjectInstanceID objid, ObjProperty prop, ObjPropertyID identifier) = 0;
  77. virtual void showInfoDialog(InfoWindow * iw) = 0;
  78. virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells)=0;
  79. virtual void setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> spells, bool accepted)=0;
  80. virtual bool removeObject(const CGObjectInstance * obj, const PlayerColor & initiator) = 0;
  81. virtual void createBoat(const int3 & visitablePosition, BoatId type, PlayerColor initiator) = 0;
  82. virtual void setOwner(const CGObjectInstance * objid, PlayerColor owner)=0;
  83. virtual void giveExperience(const CGHeroInstance * hero, TExpType val) =0;
  84. virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill which, si64 val, bool abs=false)=0;
  85. virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0;
  86. virtual void showBlockingDialog(const IObjectInterface * caller, BlockingDialog *iw) =0;
  87. virtual void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) =0; //cb will be called when player closes garrison window
  88. virtual void showTeleportDialog(TeleportDialog *iw) =0;
  89. virtual void showObjectWindow(const CGObjectInstance * object, EOpenWindowMode window, const CGHeroInstance * visitor, bool addQuery) = 0;
  90. virtual void giveResource(PlayerColor player, GameResID which, int val)=0;
  91. virtual void giveResources(PlayerColor player, TResources resources)=0;
  92. virtual void giveCreatures(const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) =0;
  93. virtual void takeCreatures(ObjectInstanceID objid, const std::vector<CStackBasicDescriptor> &creatures) =0;
  94. virtual bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false) =0;
  95. virtual bool changeStackType(const StackLocation &sl, const CCreature *c) =0;
  96. virtual bool insertNewStack(const StackLocation &sl, const CCreature *c, TQuantity count = -1) =0; //count -1 => moves whole stack
  97. virtual bool eraseStack(const StackLocation &sl, bool forceRemoval = false) =0;
  98. virtual bool swapStacks(const StackLocation &sl1, const StackLocation &sl2) =0;
  99. virtual bool addToSlot(const StackLocation &sl, const CCreature *c, TQuantity count) =0; //makes new stack or increases count of already existing
  100. virtual void tryJoiningArmy(const CArmedInstance *src, const CArmedInstance *dst, bool removeObjWhenFinished, bool allowMerging) =0; //merges army from src do dst or opens a garrison window
  101. virtual bool moveStack(const StackLocation &src, const StackLocation &dst, TQuantity count) = 0;
  102. virtual void removeAfterVisit(const CGObjectInstance *object) = 0; //object will be destroyed when interaction is over. Do not call when interaction is not ongoing!
  103. virtual bool giveHeroNewArtifact(const CGHeroInstance * h, const ArtifactID & artId, const ArtifactPosition & pos) = 0;
  104. virtual bool giveHeroNewScroll(const CGHeroInstance * h, const SpellID & spellId, const ArtifactPosition & pos) = 0;
  105. virtual bool putArtifact(const ArtifactLocation & al, const ArtifactInstanceID & id, std::optional<bool> askAssemble = std::nullopt) = 0;
  106. virtual void removeArtifact(const ArtifactLocation& al) = 0;
  107. virtual bool moveArtifact(const PlayerColor & player, const ArtifactLocation & al1, const ArtifactLocation & al2) = 0;
  108. virtual void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
  109. virtual void visitCastleObjects(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
  110. virtual void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
  111. virtual void startBattle(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, const BattleLayout & layout, const CGTownInstance *town)=0; //use hero=nullptr for no hero
  112. virtual void startBattle(const CArmedInstance *army1, const CArmedInstance *army2)=0; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
  113. virtual bool moveHero(ObjectInstanceID hid, int3 dst, EMovementMode moveMove, bool transit = false, PlayerColor asker = PlayerColor::NEUTRAL)=0;
  114. virtual bool swapGarrisonOnSiege(ObjectInstanceID tid)=0;
  115. virtual void giveHeroBonus(GiveBonus * bonus)=0;
  116. virtual void setMovePoints(SetMovePoints * smp)=0;
  117. virtual void setMovePoints(ObjectInstanceID hid, int val, bool absolute)=0;
  118. virtual void setManaPoints(ObjectInstanceID hid, int val)=0;
  119. virtual void giveHero(ObjectInstanceID id, PlayerColor player, ObjectInstanceID boatId = ObjectInstanceID()) = 0;
  120. virtual void changeObjPos(ObjectInstanceID objid, int3 newPos, const PlayerColor & initiator)=0;
  121. virtual void sendAndApply(CPackForClient & pack) = 0;
  122. virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
  123. virtual void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, ETileVisibility mode) = 0;
  124. virtual void changeFogOfWar(const std::unordered_set<int3> &tiles, PlayerColor player, ETileVisibility mode) = 0;
  125. virtual void castSpell(const spells::Caster * caster, SpellID spellID, const int3 &pos) = 0;
  126. virtual vstd::RNG & getRandomGenerator() = 0;
  127. };
  128. class DLL_LINKAGE CNonConstInfoCallback : public CPrivilegedInfoCallback
  129. {
  130. public:
  131. //keep const version of callback accessible
  132. using CGameInfoCallback::getPlayerState;
  133. using CGameInfoCallback::getTeam;
  134. using CGameInfoCallback::getPlayerTeam;
  135. using CGameInfoCallback::getHero;
  136. using CGameInfoCallback::getTown;
  137. using CGameInfoCallback::getTile;
  138. using CGameInfoCallback::getArtInstance;
  139. using CGameInfoCallback::getObjInstance;
  140. using CGameInfoCallback::getArtSet;
  141. PlayerState * getPlayerState(const PlayerColor & color, bool verbose = true);
  142. TeamState * getTeam(const TeamID & teamID); //get team by team ID
  143. TeamState * getPlayerTeam(const PlayerColor & color); // get team by player color
  144. CGHeroInstance * getHero(const ObjectInstanceID & objid);
  145. CGTownInstance * getTown(const ObjectInstanceID & objid);
  146. TerrainTile * getTile(const int3 & pos);
  147. CArtifactInstance * getArtInstance(const ArtifactInstanceID & aid);
  148. CGObjectInstance * getObjInstance(const ObjectInstanceID & oid);
  149. CArmedInstance * getArmyInstance(const ObjectInstanceID & oid);
  150. CArtifactSet * getArtSet(const ArtifactLocation & loc);
  151. virtual void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) = 0;
  152. };
  153. /// Interface class for handling general game logic and actions
  154. class DLL_LINKAGE IGameCallback : public CPrivilegedInfoCallback, public IGameEventCallback
  155. {
  156. public:
  157. virtual ~IGameCallback(){};
  158. #if SCRIPTING_ENABLED
  159. virtual scripting::Pool * getGlobalContextPool() const = 0;
  160. #endif
  161. //get info
  162. virtual bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero);
  163. friend struct CPack;
  164. friend struct CPackForClient;
  165. friend struct CPackForServer;
  166. };
  167. VCMI_LIB_NAMESPACE_END