CGameInterface.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 ICallback;
  20. class CGlobalAI;
  21. class CGHeroInstance;
  22. class Component;
  23. class CSelectableComponent;
  24. struct HeroMoveDetails;
  25. class CGHeroInstance;
  26. class CGTownInstance;
  27. class CGObjectInstance;
  28. class CCreatureSet;
  29. class CArmedInstance;
  30. struct BattleResult;
  31. struct BattleAttack;
  32. struct BattleStackAttacked;
  33. struct SpellCasted;
  34. struct SetStackEffect;
  35. struct HeroBonus;
  36. struct PackageApplied;
  37. class CLoadFile;
  38. class CSaveFile;
  39. template <typename Serializer> class CISer;
  40. template <typename Serializer> class COSer;
  41. class CObstacle
  42. {
  43. int ID;
  44. int position;
  45. //TODO: add some kind of the blockmap
  46. };
  47. struct StackState
  48. {
  49. StackState(){attackBonus=defenseBonus=healthBonus=speedBonus=morale=luck=shotsLeft=currentHealth=0;};
  50. int attackBonus, defenseBonus, healthBonus, speedBonus;
  51. int currentHealth;
  52. int shotsLeft;
  53. std::set<int> effects; //IDs of spells affecting stack
  54. int morale, luck;
  55. };
  56. class CGameInterface
  57. {
  58. public:
  59. bool human;
  60. int playerID, serialID;
  61. std::string dllName;
  62. virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished
  63. virtual void garrisonChanged(const CGObjectInstance * obj){};
  64. virtual void heroArtifactSetChanged(const CGHeroInstance*hero){};
  65. virtual void heroCreated(const CGHeroInstance*){};
  66. 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
  67. virtual void heroInGarrisonChange(const CGTownInstance *town){};
  68. virtual void heroKilled(const CGHeroInstance*){};
  69. virtual void heroMoved(const HeroMoveDetails & details){};
  70. virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val){};
  71. virtual void heroManaPointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after spell casts
  72. virtual void heroMovePointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after movement
  73. virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
  74. virtual void init(ICallback * CB){};
  75. virtual void receivedResource(int type, int val){};
  76. virtual void showInfoDialog(const std::string &text, const std::vector<Component*> &components){};
  77. //virtual void showSelDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID){};
  78. //virtual void showYesNoDialog(const std::string &text, const std::vector<Component*> &components, ui32 askID){};
  79. virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, 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.
  80. virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd) = 0; //all stacks operations between these objects become allowed, interface has to call onEnd when done
  81. virtual void tileHidden(const std::set<int3> &pos){};
  82. virtual void tileRevealed(const std::set<int3> &pos){};
  83. virtual void yourTurn(){};
  84. virtual void availableCreaturesChanged(const CGTownInstance *town){};
  85. virtual void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain){};//if gain hero received bonus, else he lost it
  86. virtual void requestRealized(PackageApplied *pa){}
  87. virtual void serialize(COSer<CSaveFile> &h, const int version){}; //saving
  88. virtual void serialize(CISer<CLoadFile> &h, const int version){}; //loading
  89. //battle call-ins
  90. virtual void actionFinished(const BattleAction *action){};//occurs AFTER every action taken by any stack or by the hero
  91. virtual void actionStarted(const BattleAction *action){};//occurs BEFORE every action taken by any stack or by the hero
  92. virtual BattleAction activeStack(int stackID)=0; //called when it's turn of that stack
  93. virtual void battleAttack(BattleAttack *ba){}; //called when stack is performing attack
  94. virtual void battleStacksAttacked(std::set<BattleStackAttacked> & bsa){}; //called when stack receives damage (after battleAttack())
  95. virtual void battleEnd(BattleResult *br){};
  96. 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
  97. virtual void battleStackMoved(int ID, int dest, int distance, bool end){};
  98. virtual void battleSpellCasted(SpellCasted *sc){};
  99. virtual void battleStacksEffectsSet(SetStackEffect & sse){};//called when a specific effect is set to stacks
  100. 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
  101. virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles){}; //called when battlefield is prepared, prior the battle beginning
  102. };
  103. class CAIHandler
  104. {
  105. public:
  106. static CGlobalAI * getNewAI(CCallback * cb, std::string dllname);
  107. };
  108. class CGlobalAI : public CGameInterface // AI class (to derivate)
  109. {
  110. public:
  111. //CGlobalAI();
  112. virtual void yourTurn(){};
  113. virtual void heroKilled(const CGHeroInstance*){};
  114. virtual void heroCreated(const CGHeroInstance*){};
  115. virtual void battleStackMoved(int ID, int dest, int distance){};
  116. virtual void battleStackAttacking(int ID, int dest){};
  117. virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){};
  118. virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;};
  119. };
  120. #endif // __CGAMEINTERFACE_H__