CGameInterface.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 CBattleGameInterface : public IBattleEventsReceiver
  52. {
  53. public:
  54. bool human;
  55. int playerID;
  56. std::string dllName;
  57. virtual ~CBattleGameInterface() {};
  58. virtual void init(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. };
  63. /// Central class for managing human player / AI interface logic
  64. class CGameInterface : public CBattleGameInterface, public IGameEventsReceiver
  65. {
  66. public:
  67. virtual void init(CCallback * CB){};
  68. virtual void yourTurn(){}; //called AFTER playerStartsTurn(player)
  69. //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
  70. virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, int queryID)=0;
  71. virtual void commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, int queryID)=0;
  72. // Show a dialog, player must take decision. If selection then he has to choose between one of given components,
  73. // if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called
  74. // with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
  75. virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel) = 0;
  76. // all stacks operations between these objects become allowed, interface has to call onEnd when done
  77. virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, int queryID) = 0;
  78. virtual void serialize(COSer<CSaveFile> &h, const int version){}; //saving
  79. virtual void serialize(CISer<CLoadFile> &h, const int version){}; //loading
  80. virtual void finish(){}; //if for some reason we want to end
  81. };
  82. class DLL_LINKAGE CDynLibHandler
  83. {
  84. public:
  85. static CGlobalAI * getNewAI(std::string dllname);
  86. static CBattleGameInterface * getNewBattleAI(std::string dllname);
  87. static 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() : battleAI(NULL), cbc(NULL) {};
  100. CAdventureAI(const std::string &BattleAIName) : battleAIName(BattleAIName), battleAI(NULL), cbc(NULL) {};
  101. std::string battleAIName;
  102. CBattleGameInterface *battleAI;
  103. CBattleCallback *cbc;
  104. //battle interface
  105. virtual BattleAction activeStack(const CStack * stack);
  106. virtual void yourTacticPhase(int distance);
  107. virtual void battleNewRound(int round);
  108. virtual void battleCatapultAttacked(const CatapultAttack & ca);
  109. virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side);
  110. virtual void battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa);
  111. virtual void actionStarted(const BattleAction *action);
  112. virtual void battleNewRoundFirst(int round);
  113. virtual void actionFinished(const BattleAction *action);
  114. virtual void battleStacksEffectsSet(const SetStackEffect & sse);
  115. //virtual void battleTriggerEffect(const BattleTriggerEffect & bte);
  116. virtual void battleStacksRemoved(const BattleStacksRemoved & bsr);
  117. virtual void battleObstaclesRemoved(const std::set<si32> & removedObstacles);
  118. virtual void battleNewStackAppeared(const CStack * stack);
  119. virtual void battleStackMoved(const CStack * stack, std::vector<BattleHex> dest, int distance);
  120. virtual void battleAttack(const BattleAttack *ba);
  121. virtual void battleSpellCast(const BattleSpellCast *sc);
  122. virtual void battleEnd(const BattleResult *br);
  123. virtual void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, bool tentHeal, si32 lifeDrainFrom);
  124. };