TerrainHandler.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 isPassable() const;
  73. bool isSurface() const;
  74. bool isUnderground() const;
  75. bool isTransitionRequired() const;
  76. bool isSurfaceCartographerCompatible() const;
  77. bool isUndergroundCartographerCompatible() const;
  78. template <typename Handler> void serialize(Handler &h, const int version)
  79. {
  80. h & battleFields;
  81. h & prohibitTransitions;
  82. h & minimapBlocked;
  83. h & minimapUnblocked;
  84. h & modScope;
  85. h & identifier;
  86. h & musicFilename;
  87. h & tilesFilename;
  88. h & shortIdentifier;
  89. h & terrainViewPatterns;
  90. h & rockTerrain;
  91. h & river;
  92. h & paletteAnimation;
  93. h & id;
  94. h & moveCost;
  95. h & horseSound;
  96. h & horseSoundPenalty;
  97. h & passabilityType;
  98. h & transitionRequired;
  99. }
  100. };
  101. class DLL_LINKAGE TerrainTypeService : public EntityServiceT<TerrainId, TerrainType>
  102. {
  103. public:
  104. };
  105. class DLL_LINKAGE TerrainTypeHandler : public CHandlerBase<TerrainId, TerrainType, TerrainType, TerrainTypeService>
  106. {
  107. public:
  108. virtual TerrainType * loadFromJson(
  109. const std::string & scope,
  110. const JsonNode & json,
  111. const std::string & identifier,
  112. size_t index) override;
  113. virtual const std::vector<std::string> & getTypeNames() const override;
  114. virtual std::vector<JsonNode> loadLegacyData() override;
  115. virtual std::vector<bool> getDefaultAllowed() const override;
  116. template <typename Handler> void serialize(Handler & h, const int version)
  117. {
  118. h & objects;
  119. }
  120. };
  121. VCMI_LIB_NAMESPACE_END