TerrainHandler.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. class DLL_LINKAGE TerrainType : public EntityT<TerrainId>
  18. {
  19. friend class TerrainTypeHandler;
  20. std::string identifier;
  21. std::string modScope;
  22. TerrainId id;
  23. ui8 passabilityType;
  24. public:
  25. int32_t getIndex() const override { return id.getNum(); }
  26. int32_t getIconIndex() const override { return 0; }
  27. std::string getJsonKey() const override;
  28. void registerIcons(const IconRegistar & cb) const override {}
  29. TerrainId getId() const override { return id;}
  30. void updateFrom(const JsonNode & data) {};
  31. std::string getNameTextID() const override;
  32. std::string getNameTranslated() const override;
  33. enum PassabilityType : ui8
  34. {
  35. LAND = 1,
  36. WATER = 2,
  37. SURFACE = 4,
  38. SUBTERRANEAN = 8,
  39. ROCK = 16
  40. };
  41. std::vector<BattleField> battleFields;
  42. std::vector<TerrainId> prohibitTransitions;
  43. ColorRGBA minimapBlocked;
  44. ColorRGBA minimapUnblocked;
  45. std::string shortIdentifier;
  46. std::string musicFilename;
  47. std::string tilesFilename;
  48. std::string terrainViewPatterns;
  49. std::string horseSound;
  50. std::string horseSoundPenalty;
  51. TerrainId rockTerrain;
  52. RiverId river;
  53. int moveCost;
  54. bool transitionRequired;
  55. TerrainType() = default;
  56. bool isLand() const;
  57. bool isWater() const;
  58. bool isPassable() const;
  59. bool isSurface() const;
  60. bool isUnderground() const;
  61. bool isTransitionRequired() const;
  62. bool isSurfaceCartographerCompatible() const;
  63. bool isUndergroundCartographerCompatible() const;
  64. template <typename Handler> void serialize(Handler &h, const int version)
  65. {
  66. h & battleFields;
  67. h & prohibitTransitions;
  68. h & minimapBlocked;
  69. h & minimapUnblocked;
  70. h & modScope;
  71. h & identifier;
  72. h & musicFilename;
  73. h & tilesFilename;
  74. h & shortIdentifier;
  75. h & terrainViewPatterns;
  76. h & rockTerrain;
  77. h & river;
  78. h & id;
  79. h & moveCost;
  80. h & horseSound;
  81. h & horseSoundPenalty;
  82. h & passabilityType;
  83. h & transitionRequired;
  84. }
  85. };
  86. class DLL_LINKAGE TerrainTypeService : public EntityServiceT<TerrainId, TerrainType>
  87. {
  88. public:
  89. };
  90. class DLL_LINKAGE TerrainTypeHandler : public CHandlerBase<TerrainId, TerrainType, TerrainType, TerrainTypeService>
  91. {
  92. public:
  93. virtual TerrainType * loadFromJson(
  94. const std::string & scope,
  95. const JsonNode & json,
  96. const std::string & identifier,
  97. size_t index) override;
  98. virtual const std::vector<std::string> & getTypeNames() const override;
  99. virtual std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
  100. virtual std::vector<bool> getDefaultAllowed() const override;
  101. template <typename Handler> void serialize(Handler & h, const int version)
  102. {
  103. h & objects;
  104. }
  105. };
  106. VCMI_LIB_NAMESPACE_END