ObstacleHandler.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/BattleHexArray.h"
  16. #include "filesystem/ResourcePath.h"
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. class DLL_LINKAGE ObstacleInfo : public EntityT<Obstacle>
  19. {
  20. public:
  21. ObstacleInfo(): obstacle(-1), width(0), height(0), isAbsoluteObstacle(false), iconIndex(0), isForegroundObstacle(false)
  22. {}
  23. ObstacleInfo(Obstacle obstacle, std::string identifier)
  24. : obstacle(obstacle), identifier(identifier), iconIndex(obstacle.getNum()), width(0), height(0), isAbsoluteObstacle(false), isForegroundObstacle(false)
  25. {
  26. }
  27. Obstacle obstacle;
  28. si32 iconIndex;
  29. std::string modScope;
  30. std::string identifier;
  31. AudioPath appearSound;
  32. AnimationPath appearAnimation;
  33. AnimationPath animation;
  34. std::vector<TerrainId> allowedTerrains;
  35. std::vector<std::string> allowedSpecialBfields;
  36. bool isAbsoluteObstacle; //there may only one such obstacle in battle and its position is always the same
  37. bool isForegroundObstacle;
  38. si32 width; //how much space to the right and up is needed to place obstacle (affects only placement algorithm)
  39. si32 height;
  40. std::vector<si16> blockedTiles; //offsets relative to obstacle position (that is its left bottom corner)
  41. int32_t getIndex() const override;
  42. int32_t getIconIndex() const override;
  43. std::string getJsonKey() const override;
  44. std::string getModScope() const override;
  45. std::string getNameTranslated() const override;
  46. std::string getNameTextID() const override;
  47. void registerIcons(const IconRegistar & cb) const override;
  48. Obstacle getId() const override;
  49. BattleHexArray getBlocked(const BattleHex & hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
  50. bool isAppropriate(const TerrainId terrainType, const BattleField & specialBattlefield) const;
  51. };
  52. class DLL_LINKAGE ObstacleService : public EntityServiceT<Obstacle, ObstacleInfo>
  53. {
  54. public:
  55. };
  56. class ObstacleHandler: public CHandlerBase<Obstacle, ObstacleInfo, ObstacleInfo, ObstacleService>
  57. {
  58. public:
  59. std::shared_ptr<ObstacleInfo> loadFromJson(const std::string & scope,
  60. const JsonNode & json,
  61. const std::string & identifier,
  62. size_t index) override;
  63. const std::vector<std::string> & getTypeNames() const override;
  64. std::vector<JsonNode> loadLegacyData() override;
  65. };
  66. VCMI_LIB_NAMESPACE_END