CGameInterface.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef __CGAMEINTERFACE_H__
  2. #define __CGAMEINTERFACE_H__
  3. #include "global.h"
  4. #include <set>
  5. #include <vector>
  6. #include "lib/BattleAction.h"
  7. #include "client/FunctionList.h"
  8. /*
  9. * CGameInterface.h, part of VCMI engine
  10. *
  11. * Authors: listed in file AUTHORS in main folder
  12. *
  13. * License: GNU General Public License v2.0 or later
  14. * Full text of license available in license.txt file, in main folder
  15. *
  16. */
  17. using namespace boost::logic;
  18. class CCallback;
  19. class IBattleCallback;
  20. class ICallback;
  21. class CGlobalAI;
  22. struct Component;
  23. class CSelectableComponent;
  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 BattleStacksRemoved;
  44. struct StackLocation;
  45. class CStackInstance;
  46. class CStack;
  47. class CCreature;
  48. class CLoadFile;
  49. class CSaveFile;
  50. typedef si32 TQuantity;
  51. template <typename Serializer> class CISer;
  52. template <typename Serializer> class COSer;
  53. struct ArtifactLocation;
  54. class CBattleGameInterface
  55. {
  56. public:
  57. bool human;
  58. int playerID;
  59. std::string dllName;
  60. virtual ~CBattleGameInterface() {};
  61. virtual void init(IBattleCallback * CB){};
  62. //battle call-ins
  63. virtual void actionFinished(const BattleAction *action){};//occurs AFTER every action taken by any stack or by the hero
  64. virtual void actionStarted(const BattleAction *action){};//occurs BEFORE every action taken by any stack or by the hero
  65. virtual BattleAction activeStack(const CStack * stack)=0; //called when it's turn of that stack
  66. virtual void battleAttack(const BattleAttack *ba){}; //called when stack is performing attack
  67. virtual void battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa){}; //called when stack receives damage (after battleAttack())
  68. virtual void battleEnd(const BattleResult *br){};
  69. virtual void battleResultsApplied(){}; //called when all effects of last battle are applied
  70. virtual void battleNewRoundFirst(int round){}; //called at the beginning of each turn before changes are applied;
  71. virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  72. virtual void battleStackMoved(const CStack * stack, THex dest, int distance, bool end){};
  73. virtual void battleSpellCast(const BattleSpellCast *sc){};
  74. virtual void battleStacksEffectsSet(const SetStackEffect & sse){};//called when a specific effect is set to stacks
  75. virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right
  76. virtual void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, si32 lifeDrainFrom){}; //called when stacks are healed / resurrected first element of pair - stack id, second - healed hp
  77. virtual void battleNewStackAppeared(const CStack * stack){}; //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
  78. virtual void battleObstaclesRemoved(const std::set<si32> & removedObstacles){}; //called when a certain set of obstacles is removed from batlefield; IDs of them are given
  79. virtual void battleCatapultAttacked(const CatapultAttack & ca){}; //called when catapult makes an attack
  80. virtual void battleStacksRemoved(const BattleStacksRemoved & bsr){}; //called when certain stack is completely removed from battlefield
  81. };
  82. class CGameInterface : public CBattleGameInterface
  83. {
  84. public:
  85. virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished
  86. //garrison operations
  87. virtual void stackChagedCount(const StackLocation &location, const TQuantity &change, bool isAbsolute){}; //if absolute, change is the new count; otherwise count was modified by adding change
  88. virtual void stackChangedType(const StackLocation &location, const CCreature &newType){}; //used eg. when upgrading creatures
  89. virtual void stacksErased(const StackLocation &location){}; //stack removed from previously filled slot
  90. virtual void stacksSwapped(const StackLocation &loc1, const StackLocation &loc2){};
  91. virtual void newStackInserted(const StackLocation &location, const CStackInstance &stack){}; //new stack inserted at given (previously empty position)
  92. virtual void stacksRebalanced(const StackLocation &src, const StackLocation &dst, TQuantity count){}; //moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  93. //virtual void garrisonChanged(const CGObjectInstance * obj){};
  94. //artifacts operations
  95. virtual void artifactPut(const ArtifactLocation &al){};
  96. virtual void artifactRemoved(const ArtifactLocation &al){};
  97. virtual void artifactAssembled(const ArtifactLocation &al){};
  98. virtual void artifactDisassembled(const ArtifactLocation &al){};
  99. virtual void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst){};
  100. virtual void heroCreated(const CGHeroInstance*){};
  101. virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)=0; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
  102. virtual void heroInGarrisonChange(const CGTownInstance *town){};
  103. //virtual void heroKilled(const CGHeroInstance*){};
  104. virtual void heroMoved(const TryMoveHero & details){};
  105. virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val){};
  106. virtual void heroSecondarySkillChanged(const CGHeroInstance * hero, int which, int val){};
  107. virtual void heroManaPointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after spell casts
  108. virtual void heroMovePointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after movement
  109. virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
  110. virtual void init(ICallback * CB){};
  111. virtual void receivedResource(int type, int val){};
  112. virtual void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID){};
  113. virtual void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level){}
  114. virtual void showShipyardDialog(const IShipyard *obj){} //obj may be town or shipyard; state: 0 - can buid, 1 - lack of resources, 2 - dest tile is blocked, 3 - no water
  115. virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel) = 0; //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
  116. virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd) = 0; //all stacks operations between these objects become allowed, interface has to call onEnd when done
  117. virtual void showPuzzleMap(){};
  118. virtual void showMarketWindow(const IMarket *market, const CGHeroInstance *visitor){};
  119. virtual void showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor){};
  120. virtual void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor){};
  121. virtual void showTavernWindow(const CGObjectInstance *townOrTavern){};
  122. virtual void advmapSpellCast(const CGHeroInstance * caster, int spellID){}; //called when a hero casts a spell
  123. virtual void tileHidden(const boost::unordered_set<int3, ShashInt3> &pos){};
  124. virtual void tileRevealed(const boost::unordered_set<int3, ShashInt3> &pos){};
  125. virtual void newObject(const CGObjectInstance * obj){}; //eg. ship built in shipyard
  126. virtual void availableArtifactsChanged(const CGBlackMarket *bm = NULL){}; //bm may be NULL, then artifacts are changed in the global pool (used by merchants in towns)
  127. virtual void yourTurn(){};
  128. virtual void centerView (int3 pos, int focusTime){};
  129. virtual void availableCreaturesChanged(const CGDwelling *town){};
  130. virtual void heroBonusChanged(const CGHeroInstance *hero, const Bonus &bonus, bool gain){};//if gain hero received bonus, else he lost it
  131. virtual void playerBonusChanged(const Bonus &bonus, bool gain){};//if gain hero received bonus, else he lost it
  132. virtual void requestRealized(PackageApplied *pa){};
  133. virtual void heroExchangeStarted(si32 hero1, si32 hero2){};
  134. virtual void objectPropertyChanged(const SetObjectProperty * sop){}; //eg. mine has been flagged
  135. virtual void objectRemoved(const CGObjectInstance *obj){}; //eg. collected resource, picked artifact, beaten hero
  136. virtual void playerBlocked(int reason){}; //reason: 0 - upcoming battle
  137. virtual void gameOver(ui8 player, bool victory){}; //player lost or won the game
  138. virtual void serialize(COSer<CSaveFile> &h, const int version){}; //saving
  139. virtual void serialize(CISer<CLoadFile> &h, const int version){}; //loading
  140. };
  141. class CAIHandler
  142. {
  143. public:
  144. static CGlobalAI * getNewAI(CCallback * cb, std::string dllname);
  145. static CBattleGameInterface * getNewBattleAI(CCallback * cb, std::string dllname);
  146. };
  147. class CGlobalAI : public CGameInterface // AI class (to derivate)
  148. {
  149. public:
  150. //CGlobalAI();
  151. virtual void yourTurn() OVERRIDE{};
  152. virtual void heroKilled(const CGHeroInstance*){};
  153. virtual void heroCreated(const CGHeroInstance*) OVERRIDE{};
  154. virtual void battleStackMoved(const CStack * stack, THex dest, int distance, bool end) OVERRIDE{};
  155. virtual void battleStackAttacking(int ID, int dest) {};
  156. virtual void battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa) OVERRIDE{};
  157. virtual BattleAction activeStack(const CStack * stack) OVERRIDE;
  158. };
  159. #endif // __CGAMEINTERFACE_H__