TerrainHandler.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. 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. std::string getModScope() const override;
  50. void registerIcons(const IconRegistar & cb) const override {}
  51. TerrainId getId() const override { return id;}
  52. void updateFrom(const JsonNode & data) {};
  53. std::string getNameTextID() const override;
  54. std::string getNameTranslated() const override;
  55. std::vector<BattleField> battleFields;
  56. std::vector<TerrainId> prohibitTransitions;
  57. ColorRGBA minimapBlocked;
  58. ColorRGBA minimapUnblocked;
  59. std::string shortIdentifier;
  60. std::vector<AudioPath> musicFilename;
  61. AnimationPath tilesFilename;
  62. std::string terrainViewPatterns;
  63. AudioPath horseSound;
  64. AudioPath horseSoundPenalty;
  65. std::vector<TerrainPaletteAnimation> paletteAnimation;
  66. TerrainId rockTerrain;
  67. RiverId river;
  68. int moveCost;
  69. bool transitionRequired;
  70. TerrainType() = default;
  71. inline bool isLand() const;
  72. inline bool isWater() const;
  73. inline bool isRock() const;
  74. inline bool isPassable() const;
  75. inline bool isSurface() const;
  76. inline bool isUnderground() const;
  77. bool isTransitionRequired() const;
  78. };
  79. class DLL_LINKAGE TerrainTypeService : public EntityServiceT<TerrainId, TerrainType>
  80. {
  81. public:
  82. };
  83. class DLL_LINKAGE TerrainTypeHandler : public CHandlerBase<TerrainId, TerrainType, TerrainType, TerrainTypeService>
  84. {
  85. public:
  86. std::shared_ptr<TerrainType> loadFromJson(
  87. const std::string & scope,
  88. const JsonNode & json,
  89. const std::string & identifier,
  90. size_t index) override;
  91. const std::vector<std::string> & getTypeNames() const override;
  92. std::vector<JsonNode> loadLegacyData() override;
  93. };
  94. inline bool TerrainType::isLand() const
  95. {
  96. return !isWater();
  97. }
  98. inline bool TerrainType::isWater() const
  99. {
  100. return passabilityType & PassabilityType::WATER;
  101. }
  102. inline bool TerrainType::isRock() const
  103. {
  104. return passabilityType & PassabilityType::ROCK;
  105. }
  106. inline bool TerrainType::isPassable() const
  107. {
  108. return !isRock();
  109. }
  110. inline bool TerrainType::isSurface() const
  111. {
  112. return passabilityType & PassabilityType::SURFACE;
  113. }
  114. inline bool TerrainType::isUnderground() const
  115. {
  116. return passabilityType & PassabilityType::SUBTERRANEAN;
  117. }
  118. VCMI_LIB_NAMESPACE_END