CGameInterface.h 5.5 KB

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