CCallback.h 10 KB

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