CGameInterface.h 6.5 KB

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