CCallback.h 4.5 KB

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