TerrainHandler.h 2.9 KB

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