CGameInterface.h 4.8 KB

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