CGameInterface.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * CGameInterface.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 "battle/AutocombatPreferences.h"
  12. #include "IGameEventsReceiver.h"
  13. #include "spells/ViewSpellInt.h"
  14. class CBattleCallback;
  15. class CCallback;
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. using boost::logic::tribool;
  18. class Environment;
  19. class ICallback;
  20. class CGlobalAI;
  21. struct Component;
  22. struct TryMoveHero;
  23. class CGHeroInstance;
  24. class CGTownInstance;
  25. class CGObjectInstance;
  26. class CGBlackMarket;
  27. class CGDwelling;
  28. class CCreatureSet;
  29. class CArmedInstance;
  30. class IShipyard;
  31. class IMarket;
  32. class BattleAction;
  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 StackLocation;
  43. class CStackInstance;
  44. class CCommanderInstance;
  45. class CStack;
  46. class CCreature;
  47. class CLoadFile;
  48. class CSaveFile;
  49. class BinaryDeserializer;
  50. class BinarySerializer;
  51. class BattleStateInfo;
  52. struct ArtifactLocation;
  53. class BattleStateInfoForRetreat;
  54. #if SCRIPTING_ENABLED
  55. namespace scripting
  56. {
  57. class Module;
  58. }
  59. #endif
  60. using TTeleportExitsList = std::vector<std::pair<ObjectInstanceID, int3>>;
  61. class DLL_LINKAGE CBattleGameInterface : public IBattleEventsReceiver
  62. {
  63. public:
  64. bool human = false;
  65. PlayerColor playerID;
  66. std::string dllName;
  67. virtual ~CBattleGameInterface() {};
  68. virtual void initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB){};
  69. virtual void initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB, AutocombatPreferences autocombatPreferences){};
  70. //battle call-ins
  71. virtual void activeStack(const BattleID & battleID, const CStack * stack)=0; //called when it's turn of that stack
  72. virtual void yourTacticPhase(const BattleID & battleID, int distance)=0; //called when interface has opportunity to use Tactics skill -> use cb->battleMakeTacticAction from this function
  73. };
  74. /// Central class for managing human player / AI interface logic
  75. class DLL_LINKAGE CGameInterface : public CBattleGameInterface, public IGameEventsReceiver
  76. {
  77. public:
  78. virtual ~CGameInterface() = default;
  79. virtual void initGameInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CCallback> CB){};
  80. virtual void yourTurn(QueryID askID){}; //called AFTER playerStartsTurn(player)
  81. //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
  82. virtual void heroGotLevel(const CGHeroInstance *hero, PrimarySkill pskill, std::vector<SecondarySkill> &skills, QueryID queryID)=0;
  83. virtual void commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, QueryID queryID)=0;
  84. // Show a dialog, player must take decision. If selection then he has to choose between one of given components,
  85. // if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called
  86. // with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
  87. virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, QueryID askID, const int soundID, bool selection, bool cancel, bool safeToAutoaccept) = 0;
  88. // all stacks operations between these objects become allowed, interface has to call onEnd when done
  89. virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, QueryID queryID) = 0;
  90. virtual void showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID) = 0;
  91. virtual void showMapObjectSelectDialog(QueryID askID, const Component & icon, const MetaString & title, const MetaString & description, const std::vector<ObjectInstanceID> & objects) = 0;
  92. virtual void finish(){}; //if for some reason we want to end
  93. virtual void showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain){};
  94. virtual std::optional<BattleAction> makeSurrenderRetreatDecision(const BattleID & battleID, const BattleStateInfoForRetreat & battleState) = 0;
  95. };
  96. class DLL_LINKAGE CDynLibHandler
  97. {
  98. public:
  99. static std::shared_ptr<CGlobalAI> getNewAI(const std::string & dllname);
  100. static std::shared_ptr<CBattleGameInterface> getNewBattleAI(const std::string & dllname);
  101. #if SCRIPTING_ENABLED
  102. static std::shared_ptr<scripting::Module> getNewScriptingModule(const boost::filesystem::path & dllname);
  103. #endif
  104. };
  105. class DLL_LINKAGE CGlobalAI : public CGameInterface // AI class (to derivate)
  106. {
  107. public:
  108. std::shared_ptr<Environment> env;
  109. CGlobalAI();
  110. };
  111. //class to be inherited by adventure-only AIs, it cedes battle actions to given battle-AI
  112. class DLL_LINKAGE CAdventureAI : public CGlobalAI
  113. {
  114. public:
  115. CAdventureAI() = default;
  116. std::shared_ptr<CBattleGameInterface> battleAI;
  117. std::shared_ptr<CBattleCallback> cbc;
  118. virtual std::string getBattleAIName() const = 0; //has to return name of the battle AI to be used
  119. //battle interface
  120. void activeStack(const BattleID & battleID, const CStack * stack) override;
  121. void yourTacticPhase(const BattleID & battleID, int distance) override;
  122. void battleNewRound(const BattleID & battleID) override;
  123. void battleCatapultAttacked(const BattleID & battleID, const CatapultAttack & ca) override;
  124. void battleStart(const BattleID & battleID, const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, BattleSide side, bool replayAllowed) override;
  125. void battleStacksAttacked(const BattleID & battleID, const std::vector<BattleStackAttacked> & bsa, bool ranged) override;
  126. void actionStarted(const BattleID & battleID, const BattleAction &action) override;
  127. void battleNewRoundFirst(const BattleID & battleID) override;
  128. void actionFinished(const BattleID & battleID, const BattleAction &action) override;
  129. void battleStacksEffectsSet(const BattleID & battleID, const SetStackEffect & sse) override;
  130. void battleObstaclesChanged(const BattleID & battleID, const std::vector<ObstacleChanges> & obstacles) override;
  131. void battleStackMoved(const BattleID & battleID, const CStack * stack, std::vector<BattleHex> dest, int distance, bool teleport) override;
  132. void battleAttack(const BattleID & battleID, const BattleAttack *ba) override;
  133. void battleSpellCast(const BattleID & battleID, const BattleSpellCast *sc) override;
  134. void battleEnd(const BattleID & battleID, const BattleResult *br, QueryID queryID) override;
  135. void battleUnitsChanged(const BattleID & battleID, const std::vector<UnitChanges> & units) override;
  136. };
  137. VCMI_LIB_NAMESPACE_END