CGameInterface.h 6.1 KB

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