CGameInterface.h 4.4 KB

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