TerrainHandler.h 2.9 KB

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