CGameInterface.h 4.1 KB

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