CGameInterface.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #include "hch/CMusicHandler.h"
  9. /*
  10. * CGameInterface.h, part of VCMI engine
  11. *
  12. * Authors: listed in file AUTHORS in main folder
  13. *
  14. * License: GNU General Public License v2.0 or later
  15. * Full text of license available in license.txt file, in main folder
  16. *
  17. */
  18. using namespace boost::logic;
  19. class CCallback;
  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 CGDwelling;
  29. class CCreatureSet;
  30. class CArmedInstance;
  31. class IShipyard;
  32. struct BattleResult;
  33. struct BattleAttack;
  34. struct BattleStackAttacked;
  35. struct SpellCast;
  36. struct SetStackEffect;
  37. struct HeroBonus;
  38. struct PackageApplied;
  39. struct SetObjectProperty;
  40. struct CatapultAttack;
  41. struct BattleStacksRemoved;
  42. class CLoadFile;
  43. class CSaveFile;
  44. template <typename Serializer> class CISer;
  45. template <typename Serializer> class COSer;
  46. class CObstacle
  47. {
  48. int ID;
  49. int position;
  50. //TODO: add some kind of the blockmap
  51. };
  52. struct StackState
  53. {
  54. StackState(){attackBonus=defenseBonus=healthBonus=speedBonus=morale=luck=shotsLeft=currentHealth=0;};
  55. int attackBonus, defenseBonus, healthBonus, speedBonus;
  56. int currentHealth;
  57. int shotsLeft;
  58. std::set<int> effects; //IDs of spells affecting stack
  59. int morale, luck;
  60. int dmgMultiplier; //for ballista dmg bonus handling
  61. };
  62. class CGameInterface
  63. {
  64. public:
  65. bool human;
  66. int playerID, serialID;
  67. std::string dllName;
  68. virtual ~CGameInterface() {};
  69. virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished
  70. virtual void garrisonChanged(const CGObjectInstance * obj){};
  71. virtual void heroArtifactSetChanged(const CGHeroInstance*hero){};
  72. virtual void heroCreated(const CGHeroInstance*){};
  73. 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
  74. virtual void heroInGarrisonChange(const CGTownInstance *town){};
  75. //virtual void heroKilled(const CGHeroInstance*){};
  76. virtual void heroMoved(const TryMoveHero & details){};
  77. virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val){};
  78. virtual void heroManaPointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after spell casts
  79. virtual void heroMovePointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after movement
  80. virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
  81. virtual void init(ICallback * CB){};
  82. virtual void receivedResource(int type, int val){};
  83. virtual void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID){};
  84. virtual void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level){}
  85. 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
  86. 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.
  87. 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
  88. virtual void showPuzzleMap(){};
  89. virtual void tileHidden(const std::set<int3> &pos){};
  90. virtual void tileRevealed(const std::set<int3> &pos){};
  91. virtual void newObject(const CGObjectInstance * obj){}; //eg. ship built in shipyard
  92. virtual void yourTurn(){};
  93. virtual void centerView (int3 pos, int focusTime){};
  94. virtual void availableCreaturesChanged(const CGDwelling *town){};
  95. virtual void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain){};//if gain hero received bonus, else he lost it
  96. virtual void playerBonusChanged(const HeroBonus &bonus, bool gain){};//if gain hero received bonus, else he lost it
  97. virtual void requestRealized(PackageApplied *pa){};
  98. virtual void heroExchangeStarted(si32 hero1, si32 hero2){};
  99. virtual void objectPropertyChanged(const SetObjectProperty * sop){}; //eg. mine has been flagged
  100. virtual void objectRemoved(const CGObjectInstance *obj){}; //eg. collected resource, picked artifact, beaten hero
  101. virtual void playerBlocked(int reason){}; //reason: 0 - upcoming battle
  102. virtual void gameOver(ui8 player, bool victory){}; //player lost or won the game
  103. virtual void serialize(COSer<CSaveFile> &h, const int version){}; //saving
  104. virtual void serialize(CISer<CLoadFile> &h, const int version){}; //loading
  105. //battle call-ins
  106. virtual void actionFinished(const BattleAction *action){};//occurs AFTER every action taken by any stack or by the hero
  107. virtual void actionStarted(const BattleAction *action){};//occurs BEFORE every action taken by any stack or by the hero
  108. virtual BattleAction activeStack(int stackID)=0; //called when it's turn of that stack
  109. virtual void battleAttack(BattleAttack *ba){}; //called when stack is performing attack
  110. virtual void battleStacksAttacked(std::set<BattleStackAttacked> & bsa){}; //called when stack receives damage (after battleAttack())
  111. virtual void battleEnd(BattleResult *br){};
  112. virtual void battleResultsApplied(){}; //called when all effects of last battle are applied
  113. 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
  114. virtual void battleStackMoved(int ID, int dest, int distance, bool end){};
  115. virtual void battleSpellCast(SpellCast *sc){};
  116. virtual void battleStacksEffectsSet(SetStackEffect & sse){};//called when a specific effect is set to stacks
  117. virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right
  118. virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles){}; //called when battlefield is prepared, prior the battle beginning
  119. virtual void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks){}; //called when stacks are healed / resurrected first element of pair - stack id, second - healed hp
  120. virtual void battleNewStackAppeared(int stackID){}; //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
  121. virtual void battleObstaclesRemoved(const std::set<si32> & removedObstacles){}; //called when a certain set of obstacles is removed from batlefield; IDs of them are given
  122. virtual void battleCatapultAttacked(const CatapultAttack & ca){}; //called when catapult makes an attack
  123. virtual void battleStacksRemoved(const BattleStacksRemoved & bsr){}; //called when certain stack is completely removed from battlefield
  124. };
  125. class CAIHandler
  126. {
  127. public:
  128. static CGlobalAI * getNewAI(CCallback * cb, std::string dllname);
  129. };
  130. class CGlobalAI : public CGameInterface // AI class (to derivate)
  131. {
  132. public:
  133. //CGlobalAI();
  134. virtual void yourTurn(){};
  135. virtual void heroKilled(const CGHeroInstance*){};
  136. virtual void heroCreated(const CGHeroInstance*){};
  137. virtual void battleStackMoved(int ID, int dest, int distance){};
  138. virtual void battleStackAttacking(int ID, int dest){};
  139. virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){};
  140. virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;};
  141. };
  142. #endif // __CGAMEINTERFACE_H__