CCallback.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef CCALLBACK_H
  2. #define CCALLBACK_H
  3. #include "mapHandler.h"
  4. #include "tchar.h"
  5. class CGameState;
  6. class CPath;
  7. class CGObjectInstance;
  8. class SComponent;
  9. class IChosen;
  10. class CSelectableComponent;
  11. typedef struct lua_State lua_State;
  12. class ICallback
  13. {
  14. public:
  15. 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
  16. //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
  17. //get info
  18. virtual bool verifyPath(CPath * path, bool blockSea)=0;
  19. 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
  20. virtual PseudoV< PseudoV< PseudoV<unsigned char> > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const)
  21. virtual const CGHeroInstance * getHeroInfo(int player, int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID
  22. virtual int getResourceAmount(int type)=0;
  23. virtual int howManyHeroes()=0;
  24. virtual const CGTownInstance * getTownInfo(int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID
  25. virtual int howManyTowns()=0;
  26. virtual std::vector < std::string > getObjDescriptions(int3 pos)=0; //returns descriptions of objects at pos in order from the lowest to the highest
  27. virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)=0;
  28. virtual bool isVisible(int3 pos)=0;
  29. virtual int getMyColor()=0;
  30. virtual int getMySerial()=0;
  31. virtual int getHeroSerial(const CGHeroInstance * hero)=0;
  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 const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0;
  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. };
  39. struct HeroMoveDetails
  40. {
  41. int3 src, dst; //source and destination points
  42. CGHeroInstance * ho; //object instance of this hero
  43. int owner;
  44. bool successful;
  45. };
  46. class CCallback : public ICallback
  47. {
  48. private:
  49. void newTurn();
  50. CCallback(CGameState * GS, int Player):gs(GS),player(Player){};
  51. CGameState * gs;
  52. int lowestSpeed(CGHeroInstance * chi); //speed of the slowest stack
  53. int valMovePoints(CGHeroInstance * chi);
  54. bool isVisible(int3 pos, int Player);
  55. protected:
  56. int player;
  57. public:
  58. //commands
  59. 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
  60. //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
  61. void selectionMade(int selection, int asker);
  62. //get info
  63. bool verifyPath(CPath * path, bool blockSea);
  64. int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
  65. PseudoV< PseudoV< PseudoV<unsigned char> > > & getVisibilityMap(); //returns visibility map (TODO: make it const)
  66. const CGHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
  67. int getResourceAmount(int type);
  68. int howManyHeroes();
  69. const CGTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
  70. int howManyTowns();
  71. std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest
  72. std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true);
  73. bool isVisible(int3 pos);
  74. int getMyColor();
  75. int getHeroSerial(const CGHeroInstance * hero);
  76. int getMySerial();
  77. int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2);
  78. int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2);
  79. int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val);
  80. bool dismissHero(const CGHeroInstance * hero);
  81. const CCreatureSet* getGarrison(const CGObjectInstance *obj);
  82. bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2);
  83. //friends
  84. friend int _tmain(int argc, _TCHAR* argv[]);
  85. };
  86. class CScriptCallback
  87. {
  88. public:
  89. CGameState * gs;
  90. //get info
  91. static int3 getPos(CGObjectInstance * ob);
  92. int getHeroOwner(int heroID);
  93. int getSelectedHero();
  94. int getDate(int mode=0);
  95. //do sth
  96. static void changePrimSkill(int ID, int which, int val);
  97. void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components); //TODO: obslugiwac nulle
  98. void showSelDialog(int player, std::string text, std::vector<CSelectableComponent*>*components, IChosen * asker);
  99. void giveResource(int player, int which, int val);
  100. void showCompInfo(int player, SComponent * comp);
  101. void heroVisitCastle(CGObjectInstance * ob, int heroID);
  102. void stopHeroVisitCastle(CGObjectInstance * ob, int heroID);
  103. void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack
  104. //friends
  105. friend void initGameState(CGameInfo * cgi);
  106. };
  107. class CLuaCallback : public CScriptCallback
  108. {
  109. private:
  110. static void registerFuncs(lua_State * L);
  111. static int getPos(lua_State * L);//(CGObjectInstance * object);
  112. static int changePrimSkill(lua_State * L);//(int ID, int which, int val);
  113. static int getGnrlText(lua_State * L);//(int ID, int which, int val);
  114. static int getSelectedHero(lua_State * L);//()
  115. friend void initGameState(CGameInfo * cgi);
  116. };
  117. #endif //CCALLBACK_H