IGameActionCallback.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * IGameActionCallback.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 "../constants/EntityIdentifiers.h"
  12. #include "../networkPacks/TradeItem.h"
  13. #include "../int3.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. struct ArtifactLocation;
  16. class JsonNode;
  17. class IShipyard;
  18. class CGHeroInstance;
  19. class CGDwelling;
  20. class CGTownInstance;
  21. class CArmedInstance;
  22. class CGObjectInstance;
  23. enum class EMarketMode : int8_t;
  24. enum class EArmyFormation : int8_t;
  25. class IGameActionCallback
  26. {
  27. public:
  28. //hero
  29. virtual void moveHero(const CGHeroInstance *h, const std::vector<int3> & path, bool transit) =0; //moves hero alongside provided path
  30. virtual void moveHero(const CGHeroInstance *h, const int3 & destination, bool transit) =0; //moves hero alongside provided path
  31. virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses given hero; true - successfully, false - not successfully
  32. virtual void dig(const CGObjectInstance *hero)=0;
  33. virtual void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos = int3(-1, -1, -1))=0; //cast adventure map spell
  34. //town
  35. virtual void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero, const HeroTypeID & nextHero=HeroTypeID::NONE)=0;
  36. virtual bool buildBuilding(const CGTownInstance *town, BuildingID buildingID)=0;
  37. virtual bool visitTownBuilding(const CGTownInstance *town, BuildingID buildingID)=0;
  38. virtual void recruitCreatures(const CGDwelling *obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level=-1)=0;
  39. virtual bool upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID=CreatureID::NONE)=0; //if newID==-1 then best possible upgrade will be made
  40. virtual void spellResearch(const CGTownInstance *town, SpellID spellAtSlot, bool accepted)=0;
  41. virtual void swapGarrisonHero(const CGTownInstance *town)=0;
  42. virtual void trade(const ObjectInstanceID marketId, EMarketMode mode, TradeItemSell id1, TradeItemBuy id2, ui32 val1, const CGHeroInstance * hero)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
  43. virtual void trade(const ObjectInstanceID marketId, EMarketMode mode, const std::vector<TradeItemSell> & id1, const std::vector<TradeItemBuy> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero)=0;
  44. virtual int selectionMade(int selection, QueryID queryID) =0;
  45. virtual int sendQueryReply(std::optional<int32_t> reply, QueryID queryID) =0;
  46. virtual int swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)=0;//swaps creatures between two possibly different garrisons // TODO: AI-unsafe code - fix it!
  47. virtual int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)=0;//joins first stack to the second (creatures must be same type)
  48. virtual int mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2) =0; //first goes to the second
  49. virtual int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2, int val)=0;//split creatures from the first stack
  50. //virtual bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
  51. virtual bool swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2)=0;
  52. virtual void scrollBackpackArtifacts(ObjectInstanceID hero, bool left) = 0;
  53. virtual void sortBackpackArtifactsBySlot(const ObjectInstanceID hero) = 0;
  54. virtual void sortBackpackArtifactsByCost(const ObjectInstanceID hero) = 0;
  55. virtual void sortBackpackArtifactsByClass(const ObjectInstanceID hero) = 0;
  56. virtual void manageHeroCostume(ObjectInstanceID hero, size_t costumeIndex, bool saveCostume) = 0;
  57. virtual void assembleArtifacts(const ObjectInstanceID & heroID, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo)=0;
  58. virtual void eraseArtifactByClient(const ArtifactLocation & al)=0;
  59. virtual bool dismissCreature(const CArmedInstance *obj, SlotID stackPos)=0;
  60. virtual void saveLocalState(const JsonNode & data)=0;
  61. virtual void endTurn()=0;
  62. virtual void buyArtifact(const CGHeroInstance *hero, ArtifactID aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
  63. virtual void setFormation(const CGHeroInstance * hero, EArmyFormation mode)=0;
  64. virtual void save(const std::string &fname) = 0;
  65. virtual void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) = 0;
  66. virtual void gamePause(bool pause) = 0;
  67. virtual void buildBoat(const IShipyard *obj) = 0;
  68. // To implement high-level army management bulk actions
  69. virtual int bulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot) = 0;
  70. virtual int bulkSplitStack(ObjectInstanceID armyId, SlotID srcSlot, int howMany = 1) = 0;
  71. virtual int bulkSplitAndRebalanceStack(ObjectInstanceID armyId, SlotID srcSlot) = 0;
  72. virtual int bulkMergeStacks(ObjectInstanceID armyId, SlotID srcSlot) = 0;
  73. // Moves all artifacts from one hero to another
  74. virtual void bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap, bool equipped, bool backpack) = 0;
  75. };
  76. VCMI_LIB_NAMESPACE_END