IGameCallback.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 "CRandomGenerator.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. struct SetMovePoints;
  16. struct GiveBonus;
  17. struct BlockingDialog;
  18. struct TeleportDialog;
  19. struct MetaString;
  20. struct StackLocation;
  21. struct ArtifactLocation;
  22. class CCreatureSet;
  23. class CStackBasicDescriptor;
  24. class CGCreature;
  25. struct ShashInt3;
  26. #if SCRIPTING_ENABLED
  27. namespace scripting
  28. {
  29. class Pool;
  30. }
  31. #endif
  32. class DLL_LINKAGE CPrivilegedInfoCallback : public CGameInfoCallback
  33. {
  34. public:
  35. enum class MapTerrainFilterMode
  36. {
  37. NONE = 0,
  38. LAND = 1,
  39. WATER = 2,
  40. LAND_CARTOGRAPHER = 3,
  41. UNDERGROUND_CARTOGRAPHER = 4
  42. };
  43. CGameState *gameState();
  44. //used for random spawns
  45. void getFreeTiles(std::vector<int3> &tiles) const;
  46. //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only revealed
  47. void getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles,
  48. const int3 & pos,
  49. int radious,
  50. boost::optional<PlayerColor> player = boost::optional<PlayerColor>(),
  51. int mode = 0,
  52. int3::EDistanceFormula formula = int3::DIST_2D) const;
  53. //returns all tiles on given level (-1 - both levels, otherwise number of level)
  54. void getAllTiles(std::unordered_set<int3, ShashInt3> &tiles, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(),
  55. int level = -1, MapTerrainFilterMode tileFilterMode = MapTerrainFilterMode::NONE) const;
  56. //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
  57. void pickAllowedArtsSet(std::vector<const CArtifact *> & out, CRandomGenerator & rand) const;
  58. void getAllowedSpells(std::vector<SpellID> &out, ui16 level);
  59. template<typename Saver>
  60. void saveCommonState(Saver &out) const; //stores GS and VLC
  61. template<typename Loader>
  62. void loadCommonState(Loader &in); //loads GS and VLC
  63. };
  64. class DLL_LINKAGE IGameEventCallback
  65. {
  66. public:
  67. virtual void setObjProperty(ObjectInstanceID objid, int prop, si64 val) = 0;
  68. virtual void showInfoDialog(InfoWindow * iw) = 0;
  69. virtual void showInfoDialog(const std::string & msg, PlayerColor player) = 0;
  70. virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells)=0;
  71. virtual bool removeObject(const CGObjectInstance * obj)=0;
  72. virtual void setOwner(const CGObjectInstance * objid, PlayerColor owner)=0;
  73. virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
  74. virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0;
  75. virtual void showBlockingDialog(BlockingDialog *iw) =0;
  76. virtual void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) =0; //cb will be called when player closes garrison window
  77. virtual void showTeleportDialog(TeleportDialog *iw) =0;
  78. virtual void showThievesGuildWindow(PlayerColor player, ObjectInstanceID requestingObjId) =0;
  79. virtual void giveResource(PlayerColor player, Res::ERes which, int val)=0;
  80. virtual void giveResources(PlayerColor player, TResources resources)=0;
  81. virtual void giveCreatures(const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) =0;
  82. virtual void takeCreatures(ObjectInstanceID objid, const std::vector<CStackBasicDescriptor> &creatures) =0;
  83. virtual bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false) =0;
  84. virtual bool changeStackType(const StackLocation &sl, const CCreature *c) =0;
  85. virtual bool insertNewStack(const StackLocation &sl, const CCreature *c, TQuantity count = -1) =0; //count -1 => moves whole stack
  86. virtual bool eraseStack(const StackLocation &sl, bool forceRemoval = false) =0;
  87. virtual bool swapStacks(const StackLocation &sl1, const StackLocation &sl2) =0;
  88. virtual bool addToSlot(const StackLocation &sl, const CCreature *c, TQuantity count) =0; //makes new stack or increases count of already existing
  89. 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
  90. virtual bool moveStack(const StackLocation &src, const StackLocation &dst, TQuantity count) = 0;
  91. virtual void removeAfterVisit(const CGObjectInstance *object) = 0; //object will be destroyed when interaction is over. Do not call when interaction is not ongoing!
  92. virtual void giveHeroNewArtifact(const CGHeroInstance *h, const CArtifact *artType, ArtifactPosition pos) = 0;
  93. virtual void giveHeroArtifact(const CGHeroInstance *h, const CArtifactInstance *a, ArtifactPosition pos) = 0; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
  94. virtual void putArtifact(const ArtifactLocation &al, const CArtifactInstance *a) = 0;
  95. virtual void removeArtifact(const ArtifactLocation &al) = 0;
  96. virtual bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) = 0;
  97. virtual void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
  98. virtual void visitCastleObjects(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
  99. virtual void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
  100. virtual void startBattlePrimary(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, const CGTownInstance *town = nullptr)=0; //use hero=nullptr for no hero
  101. virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, bool creatureBank = false)=0; //if any of armies is hero, hero will be used
  102. virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, bool creatureBank = false)=0; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
  103. virtual bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, bool transit = false, PlayerColor asker = PlayerColor::NEUTRAL)=0;
  104. virtual bool swapGarrisonOnSiege(ObjectInstanceID tid)=0;
  105. virtual void giveHeroBonus(GiveBonus * bonus)=0;
  106. virtual void setMovePoints(SetMovePoints * smp)=0;
  107. virtual void setManaPoints(ObjectInstanceID hid, int val)=0;
  108. virtual void giveHero(ObjectInstanceID id, PlayerColor player)=0;
  109. virtual void changeObjPos(ObjectInstanceID objid, int3 newPos)=0;
  110. virtual void sendAndApply(CPackForClient * pack) = 0;
  111. virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
  112. virtual void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) = 0;
  113. virtual void changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide) = 0;
  114. };
  115. class DLL_LINKAGE CNonConstInfoCallback : public CPrivilegedInfoCallback
  116. {
  117. public:
  118. //keep const version of callback accessible
  119. using CGameInfoCallback::getPlayerState;
  120. using CGameInfoCallback::getTeam;
  121. using CGameInfoCallback::getPlayerTeam;
  122. using CGameInfoCallback::getHero;
  123. using CGameInfoCallback::getTown;
  124. using CGameInfoCallback::getTile;
  125. using CGameInfoCallback::getArtInstance;
  126. using CGameInfoCallback::getObjInstance;
  127. PlayerState * getPlayerState(const PlayerColor & color, bool verbose = true);
  128. TeamState * getTeam(const TeamID & teamID); //get team by team ID
  129. TeamState * getPlayerTeam(const PlayerColor & color); // get team by player color
  130. CGHeroInstance * getHero(const ObjectInstanceID & objid);
  131. CGTownInstance * getTown(const ObjectInstanceID & objid);
  132. TerrainTile * getTile(const int3 & pos);
  133. CArtifactInstance * getArtInstance(const ArtifactInstanceID & aid);
  134. CGObjectInstance * getObjInstance(const ObjectInstanceID & oid);
  135. CArmedInstance * getArmyInstance(const ObjectInstanceID & oid);
  136. virtual void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) = 0;
  137. };
  138. /// Interface class for handling general game logic and actions
  139. class DLL_LINKAGE IGameCallback : public CPrivilegedInfoCallback, public IGameEventCallback
  140. {
  141. public:
  142. virtual ~IGameCallback(){};
  143. #if SCRIPTING_ENABLED
  144. virtual scripting::Pool * getGlobalContextPool() const = 0;
  145. #endif
  146. //get info
  147. virtual bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero);
  148. friend struct CPack;
  149. friend struct CPackForClient;
  150. friend struct CPackForServer;
  151. };
  152. VCMI_LIB_NAMESPACE_END