2
0

ObstacleHandler.h 2.5 KB

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