CGameInterface.h 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef CGAMEINTERFACE_H
  2. #define CGAMEINTERFACE_H
  3. #include "global.h"
  4. #include <set>
  5. #include <vector>
  6. BOOST_TRIBOOL_THIRD_STATE(outOfRange)
  7. using namespace boost::logic;
  8. class CCallback;
  9. class ICallback;
  10. class CGlobalAI;
  11. class CGHeroInstance;
  12. class CSelectableComponent;
  13. struct HeroMoveDetails;
  14. class CGHeroInstance;
  15. class CGTownInstance;
  16. class CGObjectInstance;
  17. class CCreatureSet;
  18. class CArmedInstance;
  19. class CObstacle
  20. {
  21. int ID;
  22. int position;
  23. //TODO: add some kind of the blockmap
  24. };
  25. struct BattleAction
  26. {
  27. bool side; //who made this action: false - left, true - right player
  28. int stackNumber;//stack ID, -1 left hero, -2 right hero,
  29. int actionType; // 0 = Cancel BattleAction 1 = Hero cast a spell 2 = Walk 3 = Defend 4 = Retreat from the battle 5 = Surrender 6 = Walk and Attack 7 = Shoot 8 = Wait 9 = Catapult 10 = Monster casts a spell (i.e. Faerie Dragons)
  30. int destinationTile;
  31. int additionalInfo; // e.g. spell number if type is 1 || 10
  32. };
  33. struct StackState
  34. {
  35. StackState(){attackBonus=defenseBonus=healthBonus=speedBonus=morale=luck=shotsLeft=currentHealth=0;};
  36. int attackBonus, defenseBonus, healthBonus, speedBonus;
  37. int currentHealth;
  38. int shotsLeft;
  39. std::set<int> effects;
  40. int morale, luck;
  41. };
  42. class CGameInterface
  43. {
  44. public:
  45. bool human;
  46. int playerID, serialID;
  47. virtual void init(ICallback * CB)=0{};
  48. virtual void yourTurn()=0{};
  49. virtual void heroKilled(const CGHeroInstance*)=0{};
  50. virtual void heroCreated(const CGHeroInstance*)=0{};
  51. virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)=0{};
  52. virtual void heroMoved(const HeroMoveDetails & details)=0{};
  53. virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
  54. virtual void tileRevealed(int3 pos){};
  55. virtual void tileHidden(int3 pos){};
  56. virtual void receivedResource(int type, int val){};
  57. virtual void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)=0{};
  58. virtual void garrisonChanged(const CGObjectInstance * obj){};
  59. virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished
  60. //battle call-ins
  61. 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
  62. virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles){}; //called when battlefield is prepared, prior the battle beginning
  63. 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
  64. virtual void actionStarted(BattleAction action){};//occurs BEFORE every action taken by any stack or by the hero
  65. virtual void actionFinished(BattleAction action){};//occurs AFTER 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 battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner){};
  68. virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)=0;
  69. virtual void battleStackAttacking(int ID, int dest)=0;
  70. virtual void battleStackIsAttacked(int ID)=0;
  71. virtual void battleStackKilled(int ID)=0;
  72. //
  73. };
  74. class CAIHandler
  75. {
  76. public:
  77. static CGlobalAI * getNewAI(CCallback * cb, std::string dllname);
  78. };
  79. class CGlobalAI : public CGameInterface // AI class (to derivate)
  80. {
  81. public:
  82. //CGlobalAI();
  83. virtual void yourTurn(){};
  84. virtual void heroKilled(const CGHeroInstance*){};
  85. virtual void heroCreated(const CGHeroInstance*){};
  86. virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){};
  87. virtual void battleStackAttacking(int ID, int dest){};
  88. virtual void battleStackIsAttacked(int ID){};
  89. virtual void battleStackKilled(int ID){};
  90. virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;};
  91. };
  92. #endif //CGAMEINTERFACE_H