TerrainHandler.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. VCMI_LIB_NAMESPACE_BEGIN
  17. struct DLL_LINKAGE TerrainPaletteAnimation
  18. {
  19. /// index of first color to cycle
  20. int32_t start;
  21. /// total numbers of colors to cycle
  22. int32_t length;
  23. template <typename Handler> void serialize(Handler& h, const int version)
  24. {
  25. h & start;
  26. h & length;
  27. }
  28. };
  29. class DLL_LINKAGE TerrainType : public EntityT<TerrainId>
  30. {
  31. friend class TerrainTypeHandler;
  32. std::string identifier;
  33. std::string modScope;
  34. TerrainId id;
  35. ui8 passabilityType;
  36. enum PassabilityType : ui8
  37. {
  38. LAND = 1,
  39. WATER = 2,
  40. SURFACE = 4,
  41. SUBTERRANEAN = 8,
  42. ROCK = 16
  43. };
  44. public:
  45. int32_t getIndex() const override { return id.getNum(); }
  46. int32_t getIconIndex() const override { return 0; }
  47. std::string getJsonKey() const override;
  48. void registerIcons(const IconRegistar & cb) const override {}
  49. TerrainId getId() const override { return id;}
  50. void updateFrom(const JsonNode & data) {};
  51. std::string getNameTextID() const override;
  52. std::string getNameTranslated() const override;
  53. std::vector<BattleField> battleFields;
  54. std::vector<TerrainId> prohibitTransitions;
  55. ColorRGBA minimapBlocked;
  56. ColorRGBA minimapUnblocked;
  57. std::string shortIdentifier;
  58. std::string musicFilename;
  59. std::string tilesFilename;
  60. std::string terrainViewPatterns;
  61. std::string horseSound;
  62. std::string horseSoundPenalty;
  63. std::vector<TerrainPaletteAnimation> paletteAnimation;
  64. TerrainId rockTerrain;
  65. RiverId river;
  66. int moveCost;
  67. bool transitionRequired;
  68. TerrainType() = default;
  69. bool isLand() const;
  70. bool isWater() const;
  71. bool isPassable() const;
  72. bool isSurface() const;
  73. bool isUnderground() const;
  74. bool isTransitionRequired() const;
  75. bool isSurfaceCartographerCompatible() const;
  76. bool isUndergroundCartographerCompatible() 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