CGameInterface.h 5.2 KB

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