CCallback.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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" //XXX this is mingw header are we need this for something? for 'true'
  8. //support of unicode we should use ICU or some boost wraper areound it
  9. //(boost using this lib during compilation i dont know what for exactly)
  10. #endif
  11. #include "CGameState.h"
  12. class CGHeroInstance;
  13. class CGameState;
  14. struct CPath;
  15. class CGObjectInstance;
  16. class CArmedInstance;
  17. class SComponent;
  18. class IChosen;
  19. class CSelectableComponent;
  20. struct BattleAction;
  21. class CGTownInstance;
  22. struct StartInfo;
  23. class CStack;
  24. struct lua_State;
  25. class CClient;
  26. //structure gathering info about upgrade possibilites
  27. class ICallback
  28. {
  29. public:
  30. 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
  31. //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
  32. 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!
  33. virtual int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//joins first stack tothe second (creatures must be same type)
  34. virtual int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val)=0;//split creatures from the first stack
  35. virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly
  36. virtual bool swapArifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
  37. virtual void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount)=0;
  38. virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0;
  39. virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made
  40. virtual void endTurn()=0;
  41. virtual void swapGarrisonHero(const CGTownInstance *town)=0;
  42. 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)
  43. virtual void trade(int mode, int id1, int id2, int val1)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
  44. virtual void setFormation(const CGHeroInstance * hero, bool tight)=0;
  45. virtual void setSelection(const CArmedInstance * obj)=0;
  46. virtual void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero)=0;
  47. //get info
  48. virtual bool verifyPath(CPath * path, bool blockSea)const =0;
  49. virtual int getDate(int mode=0)const =0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  50. virtual std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap()const =0; //returns visibility map (TODO: make it const)
  51. virtual const CGHeroInstance * getHeroInfo(int val, int mode=2)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
  52. virtual int getResourceAmount(int type)const =0;
  53. virtual int howManyHeroes()const =0;
  54. virtual const CGTownInstance * getTownInfo(int val, bool mode)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
  55. virtual int howManyTowns()const =0;
  56. virtual std::vector < std::string > getObjDescriptions(int3 pos)const =0; //returns descriptions of objects at pos in order from the lowest to the highest
  57. virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)const =0;
  58. virtual bool isVisible(int3 pos)const =0;
  59. virtual int getMyColor()const =0;
  60. virtual int getMySerial()const =0;
  61. virtual int getHeroSerial(const CGHeroInstance * hero)const =0;
  62. virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)const =0;
  63. virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)const =0;
  64. virtual const StartInfo * getStartInfo()const =0;
  65. virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0;
  66. virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)const =0;
  67. virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)const =0;
  68. virtual std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const =0;
  69. virtual int3 getMapSize() const =0; //returns size of map - z is 1 for one - level map and 2 for two level map
  70. virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const =0; //heroes that can be recruited
  71. //battle
  72. 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
  73. virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield
  74. virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile
  75. virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID
  76. virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos
  77. virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack
  78. virtual int battleMakeAction(BattleAction* action)=0;//for casting spells by hero - DO NOT use it for moving active stack
  79. virtual std::map<int, CStack> battleGetStacks()=0; //returns stacks on battlefield
  80. virtual std::vector<CStack> battleGetStackQueue()=0; //returns vector of stack in order of their move sequence
  81. virtual CCreature battleGetCreature(int number)=0; //returns type of creature by given number of stack
  82. //virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible
  83. virtual std::vector<int> battleGetAvailableHexes(int ID)=0; //reutrns numbers of hexes reachable by creature with id ID
  84. virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller
  85. virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest
  86. };
  87. struct HeroMoveDetails
  88. {
  89. HeroMoveDetails(){};
  90. HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho);
  91. int3 src, dst; //source and destination points
  92. CGHeroInstance * ho; //object instance of this hero
  93. int owner, style; //style: 0 - normal move, 1 - teleport, 2 - instant jump
  94. bool successful;
  95. };
  96. class CCallback : public ICallback
  97. {
  98. private:
  99. CCallback(CGameState * GS, int Player, CClient *C):gs(GS), cl(C), player(Player){};
  100. CGameState * gs;
  101. CClient *cl;
  102. bool isVisible(int3 pos, int Player) const;
  103. bool isVisible(CGObjectInstance *obj, int Player) const;
  104. protected:
  105. int player;
  106. public:
  107. //commands
  108. 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
  109. //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
  110. void selectionMade(int selection, int asker);
  111. int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2);
  112. int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); //first goes to the second
  113. int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val);
  114. bool dismissHero(const CGHeroInstance * hero);
  115. bool swapArifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2);
  116. bool buildBuilding(const CGTownInstance *town, si32 buildingID);
  117. void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount);
  118. bool dismissCreature(const CArmedInstance *obj, int stackPos);
  119. bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1);
  120. void endTurn();
  121. void swapGarrisonHero(const CGTownInstance *town);
  122. void buyArtifact(const CGHeroInstance *hero, int aid);
  123. void trade(int mode, int id1, int id2, int val1);
  124. void setFormation(const CGHeroInstance * hero, bool tight);
  125. void setSelection(const CArmedInstance * obj);
  126. void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero);
  127. //get info
  128. bool verifyPath(CPath * path, bool blockSea) const;
  129. int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  130. std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap() const; //returns visibility map (TODO: make it const)
  131. const CGHeroInstance * getHeroInfo(int val, int mode=2) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
  132. int getResourceAmount(int type) const;
  133. std::vector<si32> getResourceAmount() const;
  134. int howManyHeroes() const;
  135. const CGTownInstance * getTownInfo(int val, bool mode) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
  136. std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true) const;
  137. int howManyTowns()const;
  138. std::vector < std::string > getObjDescriptions(int3 pos) const; //returns descriptions of objects at pos in order from the lowest to the highest
  139. std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true) const;
  140. bool isVisible(int3 pos) const;
  141. int getMyColor() const;
  142. int getHeroSerial(const CGHeroInstance * hero) const;
  143. int getMySerial() const;
  144. const CCreatureSet* getGarrison(const CGObjectInstance *obj) const;
  145. UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos) const;
  146. const StartInfo * getStartInfo() const;
  147. std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos) const;
  148. std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos) const;
  149. void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0) const;
  150. std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
  151. int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
  152. std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const; //heroes that can be recruited
  153. //battle
  154. 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
  155. int battleGetObstaclesAtTile(int tile); //returns bitfield
  156. int battleGetStack(int pos); //returns ID of stack on the tile
  157. CStack * battleGetStackByID(int ID); //returns stack info by given ID
  158. CStack * battleGetStackByPos(int pos); //returns stack info by given pos
  159. int battleGetPos(int stack); //returns position (tile ID) of stack
  160. int battleMakeAction(BattleAction* action);//for casting spells by hero - DO NOT use it for moving active stack
  161. std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield
  162. std::vector<CStack> battleGetStackQueue(); //returns vector of stack in order of their move sequence
  163. CCreature battleGetCreature(int number); //returns type of creature by given number of stack
  164. std::vector<int> battleGetAvailableHexes(int ID); //reutrns numbers of hexes reachable by creature with id ID
  165. bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller
  166. bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest
  167. //XXX hmmm _tmain on _GNUC_ wtf?
  168. //friends
  169. friend class CClient;
  170. #ifndef __GNUC__
  171. friend int _tmain(int argc, _TCHAR* argv[]);
  172. #else
  173. friend int main(int argc, char** argv);
  174. #endif
  175. };
  176. #endif // __CCALLBACK_H__