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