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