TerrainHandler.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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)
  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. std::vector<MapLayerId> allowedLayers;
  38. enum PassabilityType : ui8
  39. {
  40. //LAND = 1,
  41. WATER = 2,
  42. //SURFACE = 4,
  43. //SUBTERRANEAN = 8,
  44. ROCK = 16
  45. };
  46. public:
  47. int32_t getIndex() const override { return id.getNum(); }
  48. int32_t getIconIndex() const override { return 0; }
  49. std::string getJsonKey() const override;
  50. std::string getModScope() const override;
  51. void registerIcons(const IconRegistar & cb) const override {}
  52. TerrainId getId() const override { return id;}
  53. void updateFrom(const JsonNode & data) {};
  54. std::string getNameTextID() const override;
  55. std::string getNameTranslated() const override;
  56. std::vector<BattleField> battleFields;
  57. std::vector<TerrainId> prohibitTransitions;
  58. ColorRGBA minimapBlocked;
  59. ColorRGBA minimapUnblocked;
  60. std::string shortIdentifier;
  61. std::vector<AudioPath> musicFilename;
  62. AnimationPath tilesFilename;
  63. std::string terrainViewPatterns;
  64. AudioPath horseSound;
  65. AudioPath horseSoundPenalty;
  66. std::vector<TerrainPaletteAnimation> paletteAnimation;
  67. TerrainId rockTerrain;
  68. RiverId river;
  69. int moveCost;
  70. bool transitionRequired;
  71. TerrainType() = default;
  72. inline bool isLand() const;
  73. inline bool isWater() const;
  74. inline bool isRock() const;
  75. inline bool isPassable() const;
  76. inline bool isSurface() const;
  77. inline bool isUnderground() const;
  78. inline std::vector<MapLayerId> layersAllowed() const;
  79. bool isTransitionRequired() const;
  80. };
  81. class DLL_LINKAGE TerrainTypeService : public EntityServiceT<TerrainId, TerrainType>
  82. {
  83. public:
  84. };
  85. class DLL_LINKAGE TerrainTypeHandler : public CHandlerBase<TerrainId, TerrainType, TerrainType, TerrainTypeService>
  86. {
  87. public:
  88. std::shared_ptr<TerrainType> loadFromJson(
  89. const std::string & scope,
  90. const JsonNode & json,
  91. const std::string & identifier,
  92. size_t index) override;
  93. const std::vector<std::string> & getTypeNames() const override;
  94. std::vector<JsonNode> loadLegacyData() override;
  95. };
  96. inline bool TerrainType::isLand() const
  97. {
  98. return !isWater();
  99. }
  100. inline bool TerrainType::isWater() const
  101. {
  102. return passabilityType & PassabilityType::WATER;
  103. }
  104. inline bool TerrainType::isRock() const
  105. {
  106. return passabilityType & PassabilityType::ROCK;
  107. }
  108. inline bool TerrainType::isPassable() const
  109. {
  110. return !isRock();
  111. }
  112. inline bool TerrainType::isSurface() const
  113. {
  114. return vstd::contains(allowedLayers, MapLayerId::SURFACE);
  115. }
  116. inline bool TerrainType::isUnderground() const
  117. {
  118. return vstd::contains(allowedLayers, MapLayerId::UNDERGROUND);
  119. }
  120. inline std::vector<MapLayerId> TerrainType::layersAllowed() const
  121. {
  122. return allowedLayers;
  123. }
  124. VCMI_LIB_NAMESPACE_END