CGameInterface.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. int attackBonus, defenseBonus, healthBonus, speedBonus;
  36. int currentHealth;
  37. int shotsLeft;
  38. std::set<int> effects;
  39. int morale, luck;
  40. };
  41. class CGameInterface
  42. {
  43. public:
  44. bool human;
  45. int playerID, serialID;
  46. virtual void init(ICallback * CB)=0{};
  47. virtual void yourTurn()=0{};
  48. virtual void heroKilled(const CGHeroInstance*)=0{};
  49. virtual void heroCreated(const CGHeroInstance*)=0{};
  50. virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)=0{};
  51. virtual void heroMoved(const HeroMoveDetails & details)=0{};
  52. virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
  53. virtual void tileRevealed(int3 pos){};
  54. virtual void tileHidden(int3 pos){};
  55. virtual void receivedResource(int type, int val){};
  56. virtual void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)=0{};
  57. virtual void garrisonChanged(const CGObjectInstance * obj){};
  58. virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished
  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(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner){};
  67. virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)=0;
  68. //
  69. };
  70. class CAIHandler
  71. {
  72. public:
  73. static CGlobalAI * getNewAI(CCallback * cb, std::string dllname);
  74. };
  75. class CGlobalAI : public CGameInterface // AI class (to derivate)
  76. {
  77. public:
  78. //CGlobalAI();
  79. virtual void yourTurn(){};
  80. virtual void heroKilled(const CGHeroInstance*){};
  81. virtual void heroCreated(const CGHeroInstance*){};
  82. virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){};
  83. virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;};
  84. };
  85. #endif //CGAMEINTERFACE_H