CCallback.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef CCALLBACK_H
  2. #define CCALLBACK_H
  3. #include "global.h"
  4. #ifdef _WIN32
  5. #include "tchar.h"
  6. #else
  7. #include "tchar_amigaos4.h"
  8. #endif
  9. #include "CGameState.h"
  10. class CGHeroInstance;
  11. class CGameState;
  12. struct CPath;
  13. class CGObjectInstance;
  14. class CArmedInstance;
  15. class SComponent;
  16. class IChosen;
  17. class CSelectableComponent;
  18. struct BattleAction;
  19. class CGTownInstance;
  20. struct StartInfo;
  21. class CStack;
  22. struct lua_State;
  23. class CClient;
  24. //structure gathering info about upgrade possibilites
  25. class ICallback
  26. {
  27. public:
  28. virtual bool moveHero(int ID, CPath * path, int idtype, int pathType=0)=0;//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
  29. //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
  30. virtual int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it!
  31. virtual int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//joins first stack tothe second (creatures must be same type)
  32. virtual int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val)=0;//split creatures from the first stack
  33. virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly
  34. virtual bool swapArifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
  35. virtual void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount)=0;
  36. virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0;
  37. virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made
  38. virtual void endTurn()=0;
  39. virtual void swapGarrisonHero(const CGTownInstance *town)=0;
  40. virtual void buyArtifact(const CGHeroInstance *hero, int aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
  41. virtual void trade(int mode, int id1, int id2, int val1)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
  42. virtual void setFormation(const CGHeroInstance * hero, bool loose)=0;
  43. //get info
  44. virtual bool verifyPath(CPath * path, bool blockSea)=0;
  45. virtual int getDate(int mode=0)=0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  46. virtual std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const)
  47. virtual const CGHeroInstance * getHeroInfo(int val, int mode=2)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID
  48. virtual int getResourceAmount(int type)=0;
  49. virtual int howManyHeroes()=0;
  50. virtual const CGTownInstance * getTownInfo(int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID
  51. virtual int howManyTowns()=0;
  52. virtual std::vector < std::string > getObjDescriptions(int3 pos)=0; //returns descriptions of objects at pos in order from the lowest to the highest
  53. virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)=0;
  54. virtual bool isVisible(int3 pos)=0;
  55. virtual int getMyColor()=0;
  56. virtual int getMySerial()=0;
  57. virtual int getHeroSerial(const CGHeroInstance * hero)=0;
  58. virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0;
  59. virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)=0;
  60. virtual const StartInfo * getStartInfo()=0;
  61. virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)=0;
  62. virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)=0;
  63. virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)=0;
  64. //battle
  65. virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
  66. virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield
  67. virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile
  68. virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID
  69. virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos
  70. virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack
  71. //virtual int battleMakeAction(BattleAction* action)=0;//perform action with an active stack (or custom action)
  72. virtual std::map<int, CStack> battleGetStacks()=0; //returns stacks on battlefield
  73. virtual CCreature battleGetCreature(int number)=0; //returns type of creature by given number of stack
  74. //virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible
  75. virtual std::vector<int> battleGetAvailableHexes(int ID)=0; //reutrns numbers of hexes reachable by creature with id ID
  76. virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller
  77. virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest
  78. };
  79. struct HeroMoveDetails
  80. {
  81. HeroMoveDetails(){};
  82. HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho);
  83. int3 src, dst; //source and destination points
  84. CGHeroInstance * ho; //object instance of this hero
  85. int owner;
  86. bool successful;
  87. };
  88. class CCallback : public ICallback
  89. {
  90. private:
  91. CCallback(CGameState * GS, int Player, CClient *C):gs(GS),player(Player),cl(C){};
  92. CGameState * gs;
  93. CClient *cl;
  94. bool isVisible(int3 pos, int Player);
  95. bool isVisible(CGObjectInstance *obj, int Player);
  96. protected:
  97. int player;
  98. public:
  99. //commands
  100. bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
  101. //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
  102. void selectionMade(int selection, int asker);
  103. int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2);
  104. int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); //first goes to the second
  105. int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val);
  106. bool dismissHero(const CGHeroInstance * hero);
  107. bool swapArifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2);
  108. bool buildBuilding(const CGTownInstance *town, si32 buildingID);
  109. void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount);
  110. bool dismissCreature(const CArmedInstance *obj, int stackPos);
  111. bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1);
  112. void endTurn();
  113. void swapGarrisonHero(const CGTownInstance *town);
  114. void buyArtifact(const CGHeroInstance *hero, int aid);
  115. void trade(int mode, int id1, int id2, int val1);
  116. void setFormation(const CGHeroInstance * hero, bool loose);
  117. //get info
  118. bool verifyPath(CPath * path, bool blockSea);
  119. int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  120. std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap(); //returns visibility map (TODO: make it const)
  121. const CGHeroInstance * getHeroInfo(int val, int mode=2); //mode = 0 -> val = serial; mode = 1 -> val = ID
  122. int getResourceAmount(int type);
  123. std::vector<si32> getResourceAmount();
  124. int howManyHeroes();
  125. const CGTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
  126. std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true);
  127. int howManyTowns();
  128. std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest
  129. std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true);
  130. bool isVisible(int3 pos);
  131. int getMyColor();
  132. int getHeroSerial(const CGHeroInstance * hero);
  133. int getMySerial();
  134. const CCreatureSet* getGarrison(const CGObjectInstance *obj);
  135. UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos);
  136. const StartInfo * getStartInfo();
  137. std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos);
  138. std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos);
  139. void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0);
  140. //battle
  141. int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
  142. int battleGetObstaclesAtTile(int tile); //returns bitfield
  143. int battleGetStack(int pos); //returns ID of stack on the tile
  144. CStack * battleGetStackByID(int ID); //returns stack info by given ID
  145. CStack * battleGetStackByPos(int pos); //returns stack info by given pos
  146. int battleGetPos(int stack); //returns position (tile ID) of stack
  147. //int battleMakeAction(BattleAction* action);//perform action with an active stack (or custom action)
  148. std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield
  149. CCreature battleGetCreature(int number); //returns type of creature by given number of stack
  150. //bool battleMoveCreature(int ID, int dest); //moves creature with id ID to dest if possible
  151. std::vector<int> battleGetAvailableHexes(int ID); //reutrns numbers of hexes reachable by creature with id ID
  152. bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller
  153. bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest
  154. //friends
  155. friend class CClient;
  156. #ifndef __GNUC__
  157. friend int _tmain(int argc, _TCHAR* argv[]);
  158. #else
  159. friend int main(int argc, char** argv);
  160. #endif
  161. };
  162. #endif //CCALLBACK_H