CGameInterface.h 5.6 KB

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