TerrainHandler.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * TerrainHandler.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 "Color.h"
  16. #include "filesystem/ResourcePath.h"
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. struct DLL_LINKAGE TerrainPaletteAnimation
  19. {
  20. /// index of first color to cycle
  21. int32_t start;
  22. /// total numbers of colors to cycle
  23. int32_t length;
  24. template <typename Handler> void serialize(Handler& h, const int version)
  25. {
  26. h & start;
  27. h & length;
  28. }
  29. };
  30. class DLL_LINKAGE TerrainType : public EntityT<TerrainId>
  31. {
  32. friend class TerrainTypeHandler;
  33. std::string identifier;
  34. std::string modScope;
  35. TerrainId id;
  36. ui8 passabilityType;
  37. enum PassabilityType : ui8
  38. {
  39. //LAND = 1,
  40. WATER = 2,
  41. SURFACE = 4,
  42. SUBTERRANEAN = 8,
  43. ROCK = 16
  44. };
  45. public:
  46. int32_t getIndex() const override { return id.getNum(); }
  47. int32_t getIconIndex() const override { return 0; }
  48. std::string getJsonKey() const override;
  49. void registerIcons(const IconRegistar & cb) const override {}
  50. TerrainId getId() const override { return id;}
  51. void updateFrom(const JsonNode & data) {};
  52. std::string getNameTextID() const override;
  53. std::string getNameTranslated() const override;
  54. std::vector<BattleField> battleFields;
  55. std::vector<TerrainId> prohibitTransitions;
  56. ColorRGBA minimapBlocked;
  57. ColorRGBA minimapUnblocked;
  58. std::string shortIdentifier;
  59. AudioPath musicFilename;
  60. AnimationPath tilesFilename;
  61. std::string terrainViewPatterns;
  62. AudioPath horseSound;
  63. AudioPath horseSoundPenalty;
  64. std::vector<TerrainPaletteAnimation> paletteAnimation;
  65. TerrainId rockTerrain;
  66. RiverId river;
  67. int moveCost;
  68. bool transitionRequired;
  69. TerrainType() = default;
  70. bool isLand() const;
  71. bool isWater() const;
  72. bool isRock() const;
  73. bool isPassable() const;
  74. bool isSurface() const;
  75. bool isUnderground() const;
  76. bool isTransitionRequired() const;
  77. };
  78. class DLL_LINKAGE TerrainTypeService : public EntityServiceT<TerrainId, TerrainType>
  79. {
  80. public:
  81. };
  82. class DLL_LINKAGE TerrainTypeHandler : public CHandlerBase<TerrainId, TerrainType, TerrainType, TerrainTypeService>
  83. {
  84. public:
  85. virtual TerrainType * loadFromJson(
  86. const std::string & scope,
  87. const JsonNode & json,
  88. const std::string & identifier,
  89. size_t index) override;
  90. virtual const std::vector<std::string> & getTypeNames() const override;
  91. virtual std::vector<JsonNode> loadLegacyData() override;
  92. virtual std::vector<bool> getDefaultAllowed() const override;
  93. };
  94. VCMI_LIB_NAMESPACE_END