CCallback.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "lib/IGameCallback.h"
  12. #include "lib/CBattleCallback.h"
  13. /*
  14. * CCallback.h, part of VCMI engine
  15. *
  16. * Authors: listed in file AUTHORS in main folder
  17. *
  18. * License: GNU General Public License v2.0 or later
  19. * Full text of license available in license.txt file, in main folder
  20. *
  21. */
  22. class CGHeroInstance;
  23. class CGameState;
  24. struct CPath;
  25. class CGObjectInstance;
  26. class CArmedInstance;
  27. struct BattleAction;
  28. class CGTownInstance;
  29. struct lua_State;
  30. class CClient;
  31. class IShipyard;
  32. struct CGPathNode;
  33. struct CGPath;
  34. struct CPathsInfo;
  35. struct CPack;
  36. class IGameActionCallback
  37. {
  38. public:
  39. //hero
  40. virtual bool moveHero(const CGHeroInstance *h, int3 dst) =0; //dst must be free, neighbouring tile (this function can move hero only by one tile)
  41. virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses given hero; true - successfuly, false - not successfuly
  42. virtual void dig(const CGObjectInstance *hero)=0;
  43. virtual void castSpell(const CGHeroInstance *hero, int spellID, const int3 &pos = int3(-1, -1, -1))=0; //cast adventure map spell
  44. //town
  45. virtual void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)=0;
  46. virtual bool buildBuilding(const CGTownInstance *town, si32 buildingID)=0;
  47. virtual void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount, si32 level=-1)=0;
  48. virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made
  49. virtual void swapGarrisonHero(const CGTownInstance *town)=0;
  50. virtual void trade(const CGObjectInstance *market, int mode, int id1, int id2, int val1, const CGHeroInstance *hero = NULL)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
  51. virtual void selectionMade(int selection, int asker) =0;
  52. virtual int swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2)=0;//swaps creatures between two possibly different garrisons // TODO: AI-unsafe code - fix it!
  53. virtual int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2)=0;//joins first stack to the second (creatures must be same type)
  54. virtual int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2, int val)=0;//split creatures from the first stack
  55. virtual bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
  56. virtual bool assembleArtifacts(const CGHeroInstance * hero, ui16 artifactSlot, bool assemble, ui32 assembleTo)=0;
  57. virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0;
  58. virtual void endTurn()=0;
  59. 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)
  60. virtual void setFormation(const CGHeroInstance * hero, bool tight)=0;
  61. virtual void setSelection(const CArmedInstance * obj)=0;
  62. virtual void save(const std::string &fname) = 0;
  63. virtual void sendMessage(const std::string &mess) = 0;
  64. virtual void buildBoat(const IShipyard *obj) = 0;
  65. };
  66. class CCallback : public CPlayerSpecificInfoCallback, public IGameActionCallback, public CBattleCallback
  67. {
  68. private:
  69. CCallback(CGameState * GS, int Player, CClient *C);
  70. public:
  71. CClient *cl;
  72. //client-specific functionalities (pathfinding)
  73. virtual bool getPath(int3 src, int3 dest, const CGHeroInstance * hero, CPath &ret); //DEPRACATED!!!
  74. virtual const CGPathNode *getPathInfo(int3 tile); //uses main, client pathfinder info
  75. virtual bool getPath2(int3 dest, CGPath &ret); //uses main, client pathfinder info
  76. virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1);
  77. virtual void recalculatePaths(); //updates main, client pathfinder info (should be called when moving hero is over)
  78. void unregisterMyInterface(); //stops delivering information about game events to that player's interface -> can be called ONLY after victory/loss
  79. //commands
  80. bool moveHero(const CGHeroInstance *h, int3 dst); //dst must be free, neighbouring tile (this function can move hero only by one tile)
  81. bool teleportHero(const CGHeroInstance *who, const CGTownInstance *where);
  82. void selectionMade(int selection, int asker);
  83. int swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2);
  84. int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2); //first goes to the second
  85. int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2, int val);
  86. bool dismissHero(const CGHeroInstance * hero);
  87. bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2);
  88. bool assembleArtifacts(const CGHeroInstance * hero, ui16 artifactSlot, bool assemble, ui32 assembleTo);
  89. bool buildBuilding(const CGTownInstance *town, si32 buildingID);
  90. void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount, si32 level=-1);
  91. bool dismissCreature(const CArmedInstance *obj, int stackPos);
  92. bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1);
  93. void endTurn();
  94. void swapGarrisonHero(const CGTownInstance *town);
  95. void buyArtifact(const CGHeroInstance *hero, int aid);
  96. void trade(const CGObjectInstance *market, int mode, int id1, int id2, int val1, const CGHeroInstance *hero = NULL);
  97. void setFormation(const CGHeroInstance * hero, bool tight);
  98. void setSelection(const CArmedInstance * obj);
  99. void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero);
  100. void save(const std::string &fname);
  101. void sendMessage(const std::string &mess);
  102. void buildBoat(const IShipyard *obj);
  103. void dig(const CGObjectInstance *hero);
  104. void castSpell(const CGHeroInstance *hero, int spellID, const int3 &pos = int3(-1, -1, -1));
  105. //friends
  106. friend class CClient;
  107. };
  108. #endif // __CCALLBACK_H__