CGameInterface.h 4.4 KB

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