IGameCallback.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #pragma once
  2. #include "CGameInfoCallback.h" // for CGameInfoCallback
  3. #include "CRandomGenerator.h"
  4. /*
  5. * IGameCallback.h, part of VCMI engine
  6. *
  7. * Authors: listed in file AUTHORS in main folder
  8. *
  9. * License: GNU General Public License v2.0 or later
  10. * Full text of license available in license.txt file, in main folder
  11. *
  12. */
  13. struct SetMovePoints;
  14. struct GiveBonus;
  15. struct BlockingDialog;
  16. struct TeleportDialog;
  17. struct MetaString;
  18. struct ShowInInfobox;
  19. struct StackLocation;
  20. struct ArtifactLocation;
  21. class CCreatureSet;
  22. class CStackBasicDescriptor;
  23. class CGCreature;
  24. struct ShashInt3;
  25. class DLL_LINKAGE CPrivilagedInfoCallback : public CGameInfoCallback
  26. {
  27. public:
  28. CGameState * gameState();
  29. void getFreeTiles (std::vector<int3> &tiles) const; //used for random spawns
  30. void getTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), int mode = 0, bool patrolDistance = false) const; //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only unrevealed
  31. void getAllTiles (std::unordered_set<int3, ShashInt3> &tiles, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), int level=-1, int surface=0) const; //returns all tiles on given level (-1 - both levels, otherwise number of level); surface: 0 - land and water, 1 - only land, 2 - only water
  32. void pickAllowedArtsSet(std::vector<const CArtifact*> &out, CRandomGenerator & rand); //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
  33. void getAllowedSpells(std::vector<SpellID> &out, ui16 level);
  34. template<typename Saver>
  35. void saveCommonState(Saver &out) const; //stores GS and VLC
  36. template<typename Loader>
  37. void loadCommonState(Loader &in); //loads GS and VLC
  38. };
  39. class DLL_LINKAGE IGameEventCallback : public IGameEventRealizer
  40. {
  41. public:
  42. virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells)=0;
  43. virtual bool removeObject(const CGObjectInstance * obj)=0;
  44. virtual void setBlockVis(ObjectInstanceID objid, bool bv)=0;
  45. virtual void setOwner(const CGObjectInstance * objid, PlayerColor owner)=0;
  46. virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
  47. virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0;
  48. virtual void showBlockingDialog(BlockingDialog *iw) =0;
  49. virtual void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) =0; //cb will be called when player closes garrison window
  50. virtual void showTeleportDialog(TeleportDialog *iw) =0;
  51. virtual void showThievesGuildWindow(PlayerColor player, ObjectInstanceID requestingObjId) =0;
  52. virtual void giveResource(PlayerColor player, Res::ERes which, int val)=0;
  53. virtual void giveResources(PlayerColor player, TResources resources)=0;
  54. virtual void giveCreatures(const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) =0;
  55. virtual void takeCreatures(ObjectInstanceID objid, const std::vector<CStackBasicDescriptor> &creatures) =0;
  56. virtual bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false) =0;
  57. virtual bool changeStackType(const StackLocation &sl, const CCreature *c) =0;
  58. virtual bool insertNewStack(const StackLocation &sl, const CCreature *c, TQuantity count = -1) =0; //count -1 => moves whole stack
  59. virtual bool eraseStack(const StackLocation &sl, bool forceRemoval = false) =0;
  60. virtual bool swapStacks(const StackLocation &sl1, const StackLocation &sl2) =0;
  61. virtual bool addToSlot(const StackLocation &sl, const CCreature *c, TQuantity count) =0; //makes new stack or increases count of already existing
  62. 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
  63. virtual bool moveStack(const StackLocation &src, const StackLocation &dst, TQuantity count) = 0;
  64. virtual void removeAfterVisit(const CGObjectInstance *object) = 0; //object will be destroyed when interaction is over. Do not call when interaction is not ongoing!
  65. virtual void giveHeroNewArtifact(const CGHeroInstance *h, const CArtifact *artType, ArtifactPosition pos) = 0;
  66. 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
  67. virtual void putArtifact(const ArtifactLocation &al, const CArtifactInstance *a) = 0;
  68. virtual void removeArtifact(const ArtifactLocation &al) = 0;
  69. virtual bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) = 0;
  70. virtual void synchronizeArtifactHandlerLists() = 0;
  71. virtual void showCompInfo(ShowInInfobox * comp)=0;
  72. virtual void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
  73. virtual void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
  74. 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
  75. 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
  76. 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
  77. virtual void setAmount(ObjectInstanceID objid, ui32 val)=0;
  78. virtual bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, bool transit = false, PlayerColor asker = PlayerColor::NEUTRAL)=0;
  79. virtual void giveHeroBonus(GiveBonus * bonus)=0;
  80. virtual void setMovePoints(SetMovePoints * smp)=0;
  81. virtual void setManaPoints(ObjectInstanceID hid, int val)=0;
  82. virtual void giveHero(ObjectInstanceID id, PlayerColor player)=0;
  83. virtual void changeObjPos(ObjectInstanceID objid, int3 newPos, ui8 flags)=0;
  84. virtual void sendAndApply(CPackForClient * info)=0;
  85. virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
  86. virtual void addQuest(int player, QuestInfo & quest){};
  87. virtual void changeFogOfWar(int3 center, ui32 radius, PlayerColor player, bool hide) = 0;
  88. virtual void changeFogOfWar(std::unordered_set<int3, ShashInt3> &tiles, PlayerColor player, bool hide) = 0;
  89. };
  90. class DLL_LINKAGE CNonConstInfoCallback : public CPrivilagedInfoCallback
  91. {
  92. public:
  93. PlayerState *getPlayer(PlayerColor color, bool verbose = true);
  94. TeamState *getTeam(TeamID teamID);//get team by team ID
  95. TeamState *getPlayerTeam(PlayerColor color);// get team by player color
  96. CGHeroInstance *getHero(ObjectInstanceID objid);
  97. CGTownInstance *getTown(ObjectInstanceID objid);
  98. TerrainTile * getTile(int3 pos);
  99. CArtifactInstance * getArtInstance(ArtifactInstanceID aid);
  100. CGObjectInstance * getObjInstance(ObjectInstanceID oid);
  101. };
  102. /// Interface class for handling general game logic and actions
  103. class DLL_LINKAGE IGameCallback : public CPrivilagedInfoCallback, public IGameEventCallback
  104. {
  105. public:
  106. virtual ~IGameCallback(){};
  107. //do sth
  108. const CGObjectInstance *putNewObject(Obj ID, int subID, int3 pos);
  109. const CGCreature *putNewMonster(CreatureID creID, int count, int3 pos);
  110. //get info
  111. virtual bool isVisitCoveredByAnotherQuery(const CGObjectInstance *obj, const CGHeroInstance *hero);
  112. friend struct CPack;
  113. friend struct CPackForClient;
  114. friend struct CPackForServer;
  115. };