2
0

CGameInterface.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #pragma once
  2. #include "BattleAction.h"
  3. #include "IGameEventsReceiver.h"
  4. #include "CGameStateFwd.h"
  5. #include "spells/ViewSpellInt.h"
  6. #include "mapObjects/CObjectHandler.h"
  7. /*
  8. * CGameInterface.h, part of VCMI engine
  9. *
  10. * Authors: listed in file AUTHORS in main folder
  11. *
  12. * License: GNU General Public License v2.0 or later
  13. * Full text of license available in license.txt file, in main folder
  14. *
  15. */
  16. using boost::logic::tribool;
  17. class CCallback;
  18. class CBattleCallback;
  19. class ICallback;
  20. class CGlobalAI;
  21. struct Component;
  22. class CSelectableComponent;
  23. struct TryMoveHero;
  24. class CGHeroInstance;
  25. class CGTownInstance;
  26. class CGObjectInstance;
  27. class CGBlackMarket;
  28. class CGDwelling;
  29. class CCreatureSet;
  30. class CArmedInstance;
  31. class IShipyard;
  32. class IMarket;
  33. struct BattleResult;
  34. struct BattleAttack;
  35. struct BattleStackAttacked;
  36. struct BattleSpellCast;
  37. struct SetStackEffect;
  38. struct Bonus;
  39. struct PackageApplied;
  40. struct SetObjectProperty;
  41. struct CatapultAttack;
  42. struct BattleStacksRemoved;
  43. struct StackLocation;
  44. class CStackInstance;
  45. class CCommanderInstance;
  46. class CStack;
  47. struct CPathsInfo;
  48. class CCreature;
  49. class CLoadFile;
  50. class CSaveFile;
  51. class BinaryDeserializer;
  52. class BinarySerializer;
  53. struct ArtifactLocation;
  54. class CScriptingModule;
  55. class DLL_LINKAGE CBattleGameInterface : public IBattleEventsReceiver
  56. {
  57. public:
  58. bool human;
  59. PlayerColor playerID;
  60. std::string dllName;
  61. virtual ~CBattleGameInterface() {};
  62. virtual void init(std::shared_ptr<CBattleCallback> CB){};
  63. //battle call-ins
  64. virtual BattleAction activeStack(const CStack * stack)=0; //called when it's turn of that stack
  65. virtual void yourTacticPhase(int distance){}; //called when interface has opportunity to use Tactics skill -> use cb->battleMakeTacticAction from this function
  66. virtual void saveGame(BinarySerializer & h, const int version);
  67. virtual void loadGame(BinaryDeserializer & h, const int version);
  68. };
  69. /// Central class for managing human player / AI interface logic
  70. class DLL_LINKAGE CGameInterface : public CBattleGameInterface, public IGameEventsReceiver
  71. {
  72. public:
  73. virtual ~CGameInterface() = default;
  74. virtual void init(std::shared_ptr<CCallback> CB){};
  75. virtual void yourTurn(){}; //called AFTER playerStartsTurn(player)
  76. //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
  77. virtual void heroGotLevel(const CGHeroInstance *hero, PrimarySkill::PrimarySkill pskill, std::vector<SecondarySkill> &skills, QueryID queryID)=0;
  78. virtual void commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, QueryID queryID)=0;
  79. // Show a dialog, player must take decision. If selection then he has to choose between one of given components,
  80. // if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called
  81. // with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
  82. virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, QueryID askID, const int soundID, bool selection, bool cancel) = 0;
  83. // all stacks operations between these objects become allowed, interface has to call onEnd when done
  84. virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, QueryID queryID) = 0;
  85. virtual void showTeleportDialog(TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID) = 0;
  86. virtual void finish(){}; //if for some reason we want to end
  87. virtual void showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositions){};
  88. };
  89. class DLL_LINKAGE CDynLibHandler
  90. {
  91. public:
  92. static std::shared_ptr<CGlobalAI> getNewAI(std::string dllname);
  93. static std::shared_ptr<CBattleGameInterface> getNewBattleAI(std::string dllname);
  94. static std::shared_ptr<CScriptingModule> getNewScriptingModule(std::string dllname);
  95. };
  96. class DLL_LINKAGE CGlobalAI : public CGameInterface // AI class (to derivate)
  97. {
  98. public:
  99. CGlobalAI();
  100. virtual BattleAction activeStack(const CStack * stack) override;
  101. };
  102. //class to be inherited by adventure-only AIs, it cedes battle actions to given battle-AI
  103. class DLL_LINKAGE CAdventureAI : public CGlobalAI
  104. {
  105. public:
  106. CAdventureAI() {};
  107. std::shared_ptr<CBattleGameInterface> battleAI;
  108. std::shared_ptr<CBattleCallback> cbc;
  109. virtual std::string getBattleAIName() const = 0; //has to return name of the battle AI to be used
  110. //battle interface
  111. virtual BattleAction activeStack(const CStack * stack) override;
  112. virtual void yourTacticPhase(int distance) override;
  113. virtual void battleNewRound(int round) override;
  114. virtual void battleCatapultAttacked(const CatapultAttack & ca) override;
  115. virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side) override;
  116. virtual void battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa) override;
  117. virtual void actionStarted(const BattleAction &action) override;
  118. virtual void battleNewRoundFirst(int round) override;
  119. virtual void actionFinished(const BattleAction &action) override;
  120. virtual void battleStacksEffectsSet(const SetStackEffect & sse) override;
  121. //virtual void battleTriggerEffect(const BattleTriggerEffect & bte);
  122. virtual void battleStacksRemoved(const BattleStacksRemoved & bsr) override;
  123. virtual void battleObstaclesRemoved(const std::set<si32> & removedObstacles) override;
  124. virtual void battleNewStackAppeared(const CStack * stack) override;
  125. virtual void battleStackMoved(const CStack * stack, std::vector<BattleHex> dest, int distance) override;
  126. virtual void battleAttack(const BattleAttack *ba) override;
  127. virtual void battleSpellCast(const BattleSpellCast *sc) override;
  128. virtual void battleEnd(const BattleResult *br) override;
  129. virtual void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, bool tentHeal, si32 lifeDrainFrom) override;
  130. virtual void saveGame(BinarySerializer & h, const int version) override; //saving
  131. virtual void loadGame(BinaryDeserializer & h, const int version) override; //loading
  132. };