CCallback.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef CCALLBACK_H
  2. #define CCALLBACK_H
  3. #include "global.h"
  4. #include "tchar.h"
  5. #include <set>
  6. class CGHeroInstance;
  7. class CGameState;
  8. struct CPath;
  9. class CGObjectInstance;
  10. class CArmedInstance;
  11. class SComponent;
  12. class IChosen;
  13. class CSelectableComponent;
  14. struct BattleAction;
  15. class CGTownInstance;
  16. struct StartInfo;
  17. class CStack;
  18. struct lua_State;
  19. class CClient;
  20. //structure gathering info about upgrade possibilites
  21. struct UpgradeInfo
  22. {
  23. int oldID; //creature to be upgraded
  24. std::vector<int> newID; //possible upgrades
  25. std::vector<std::set<std::pair<int,int> > > cost; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>
  26. UpgradeInfo(){oldID = -1;};
  27. };
  28. class ICallback
  29. {
  30. public:
  31. 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
  32. //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
  33. 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!
  34. virtual int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//joins first stack tothe second (creatures must be same type)
  35. virtual int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val)=0;//split creatures from the first stack
  36. virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly
  37. virtual bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2)=0; //swaps artifacts between two given heroes
  38. virtual void recruitCreatures(const CGObjectInstance *obj, int ID, int amount)=0;
  39. virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0;
  40. virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made
  41. virtual void endTurn()=0;
  42. //get info
  43. virtual bool verifyPath(CPath * path, bool blockSea)=0;
  44. 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
  45. virtual std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const)
  46. virtual const CGHeroInstance * getHeroInfo(int player, int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID
  47. virtual int getResourceAmount(int type)=0;
  48. virtual int howManyHeroes()=0;
  49. virtual const CGTownInstance * getTownInfo(int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID
  50. virtual int howManyTowns()=0;
  51. virtual std::vector < std::string > getObjDescriptions(int3 pos)=0; //returns descriptions of objects at pos in order from the lowest to the highest
  52. virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)=0;
  53. virtual bool isVisible(int3 pos)=0;
  54. virtual int getMyColor()=0;
  55. virtual int getMySerial()=0;
  56. virtual int getHeroSerial(const CGHeroInstance * hero)=0;
  57. virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0;
  58. virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)=0;
  59. virtual const StartInfo * getStartInfo()=0;
  60. //battle
  61. 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
  62. virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield
  63. virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile
  64. virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID
  65. virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos
  66. virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack
  67. //virtual int battleMakeAction(BattleAction* action)=0;//perform action with an active stack (or custom action)
  68. virtual std::map<int, CStack> battleGetStacks()=0; //returns stacks on battlefield
  69. virtual CCreature battleGetCreature(int number)=0; //returns type of creature by given number of stack
  70. //virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible
  71. virtual std::vector<int> battleGetAvailableHexes(int ID)=0; //reutrns numbers of hexes reachable by creature with id ID
  72. virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller
  73. };
  74. struct HeroMoveDetails
  75. {
  76. HeroMoveDetails(){};
  77. HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho);
  78. int3 src, dst; //source and destination points
  79. CGHeroInstance * ho; //object instance of this hero
  80. int owner;
  81. bool successful;
  82. };
  83. class CCallback : public ICallback
  84. {
  85. private:
  86. CCallback(CGameState * GS, int Player, CClient *C):gs(GS),player(Player),cl(C){};
  87. CGameState * gs;
  88. CClient *cl;
  89. bool isVisible(int3 pos, int Player);
  90. protected:
  91. int player;
  92. public:
  93. //commands
  94. 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
  95. //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
  96. void selectionMade(int selection, int asker);
  97. int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2);
  98. int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); //first goes to the second
  99. int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val);
  100. bool dismissHero(const CGHeroInstance * hero);
  101. bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2);
  102. bool buildBuilding(const CGTownInstance *town, int buildingID);
  103. void recruitCreatures(const CGObjectInstance *obj, int ID, int amount);
  104. bool dismissCreature(const CArmedInstance *obj, int stackPos);
  105. bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1);
  106. void endTurn();
  107. //get info
  108. bool verifyPath(CPath * path, bool blockSea);
  109. int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  110. std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap(); //returns visibility map (TODO: make it const)
  111. const CGHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
  112. int getResourceAmount(int type);
  113. std::vector<int> getResourceAmount();
  114. int howManyHeroes();
  115. const CGTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
  116. std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true);
  117. int howManyTowns();
  118. std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest
  119. std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true);
  120. bool isVisible(int3 pos);
  121. int getMyColor();
  122. int getHeroSerial(const CGHeroInstance * hero);
  123. int getMySerial();
  124. const CCreatureSet* getGarrison(const CGObjectInstance *obj);
  125. UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos);
  126. virtual const StartInfo * getStartInfo();
  127. //battle
  128. 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
  129. int battleGetObstaclesAtTile(int tile); //returns bitfield
  130. int battleGetStack(int pos); //returns ID of stack on the tile
  131. CStack * battleGetStackByID(int ID); //returns stack info by given ID
  132. CStack * battleGetStackByPos(int pos); //returns stack info by given pos
  133. int battleGetPos(int stack); //returns position (tile ID) of stack
  134. //int battleMakeAction(BattleAction* action);//perform action with an active stack (or custom action)
  135. std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield
  136. CCreature battleGetCreature(int number); //returns type of creature by given number of stack
  137. //bool battleMoveCreature(int ID, int dest); //moves creature with id ID to dest if possible
  138. std::vector<int> battleGetAvailableHexes(int ID); //reutrns numbers of hexes reachable by creature with id ID
  139. bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller
  140. //friends
  141. friend class CClient;
  142. };
  143. #endif //CCALLBACK_H