CGameInterface.h 4.2 KB

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