ObstacleHandler.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * ObstacleHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include <vcmi/EntityService.h>
  12. #include <vcmi/Entity.h>
  13. #include "GameConstants.h"
  14. #include "IHandlerBase.h"
  15. #include "battle/BattleHex.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class DLL_LINKAGE ObstacleInfo : public EntityT<Obstacle>
  18. {
  19. public:
  20. ObstacleInfo(): obstacle(-1), width(0), height(0), isAbsoluteObstacle(false), iconIndex(0), isForegroundObstacle(false)
  21. {}
  22. ObstacleInfo(Obstacle obstacle, std::string identifier)
  23. : obstacle(obstacle), identifier(identifier), iconIndex(obstacle.getNum()), width(0), height(0), isAbsoluteObstacle(false), isForegroundObstacle(false)
  24. {
  25. }
  26. Obstacle obstacle;
  27. si32 iconIndex;
  28. std::string identifier;
  29. std::string appearSound, appearAnimation, animation;
  30. std::vector<TerrainId> allowedTerrains;
  31. std::vector<std::string> allowedSpecialBfields;
  32. bool isAbsoluteObstacle; //there may only one such obstacle in battle and its position is always the same
  33. bool isForegroundObstacle;
  34. si32 width, height; //how much space to the right and up is needed to place obstacle (affects only placement algorithm)
  35. std::vector<si16> blockedTiles; //offsets relative to obstacle position (that is its left bottom corner)
  36. int32_t getIndex() const override;
  37. int32_t getIconIndex() const override;
  38. std::string getJsonKey() const override;
  39. std::string getNameTranslated() const override;
  40. std::string getNameTextID() const override;
  41. void registerIcons(const IconRegistar & cb) const override;
  42. Obstacle getId() const override;
  43. std::vector<BattleHex> getBlocked(BattleHex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
  44. bool isAppropriate(const TerrainId terrainType, const BattleField & specialBattlefield) const;
  45. template <typename Handler> void serialize(Handler &h, const int version)
  46. {
  47. h & obstacle;
  48. h & iconIndex;
  49. h & identifier;
  50. h & animation;
  51. h & appearAnimation;
  52. h & appearSound;
  53. h & allowedTerrains;
  54. h & allowedSpecialBfields;
  55. h & isAbsoluteObstacle;
  56. h & isForegroundObstacle;
  57. h & width;
  58. h & height;
  59. h & blockedTiles;
  60. }
  61. };
  62. class DLL_LINKAGE ObstacleService : public EntityServiceT<Obstacle, ObstacleInfo>
  63. {
  64. public:
  65. };
  66. class ObstacleHandler: public CHandlerBase<Obstacle, ObstacleInfo, ObstacleInfo, ObstacleService>
  67. {
  68. public:
  69. ObstacleInfo * loadFromJson(const std::string & scope,
  70. const JsonNode & json,
  71. const std::string & identifier,
  72. size_t index) override;
  73. const std::vector<std::string> & getTypeNames() const override;
  74. std::vector<JsonNode> loadLegacyData() override;
  75. std::vector<bool> getDefaultAllowed() const override;
  76. template <typename Handler> void serialize(Handler & h, const int version)
  77. {
  78. h & objects;
  79. }
  80. };
  81. VCMI_LIB_NAMESPACE_END