CGameInterface.h 5.6 KB

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