ObstacleSetHandler.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * ObstacleSetHandler.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 "../GameConstants.h"
  12. #include "../constants/EntityIdentifiers.h"
  13. #include "../IHandlerBase.h"
  14. #include "../json/JsonNode.h"
  15. #include "ObjectTemplate.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class DLL_LINKAGE ObstacleSet
  18. {
  19. public:
  20. // TODO: Create string constants for these
  21. enum EObstacleType
  22. {
  23. INVALID = -1,
  24. MOUNTAINS = 0,
  25. TREES,
  26. LAKES, // Inluding dry or lava lakes
  27. CRATERS, // Chasms, Canyons, etc.
  28. ROCKS,
  29. PLANTS, // Flowers, cacti, mushrooms, logs, shrubs, etc.
  30. STRUCTURES, // Buildings, ruins, etc.
  31. ANIMALS, // Living, or bones
  32. OTHER // Crystals, shipwrecks, barrels, etc.
  33. };
  34. ObstacleSet();
  35. explicit ObstacleSet(EObstacleType type, TerrainId terrain);
  36. void addObstacle(std::shared_ptr<const ObjectTemplate> obstacle);
  37. std::vector<std::shared_ptr<const ObjectTemplate>> getObstacles() const;
  38. EObstacleType getType() const;
  39. void setType(EObstacleType type);
  40. std::set<TerrainId> getTerrains() const;
  41. void setTerrain(TerrainId terrain);
  42. void setTerrains(const std::set<TerrainId> & terrains);
  43. void addTerrain(TerrainId terrain);
  44. std::set<EAlignment> getAlignments() const;
  45. void addAlignment(EAlignment alignment);
  46. std::set<FactionID> getFactions() const;
  47. void addFaction(FactionID faction);
  48. static EObstacleType typeFromString(const std::string &str);
  49. std::string toString() const;
  50. si32 id;
  51. private:
  52. EObstacleType type;
  53. std::set<TerrainId> allowedTerrains; // Empty means all terrains
  54. std::set<FactionID> allowedFactions; // Empty means all factions
  55. std::set<EAlignment> allowedAlignments; // Empty means all alignments
  56. std::vector<std::shared_ptr<const ObjectTemplate>> obstacles;
  57. };
  58. typedef std::vector<std::shared_ptr<ObstacleSet>> TObstacleTypes;
  59. class DLL_LINKAGE ObstacleSetFilter
  60. {
  61. public:
  62. ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain, FactionID faction, EAlignment alignment);
  63. ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain, FactionID faction, EAlignment alignment);
  64. bool filter(const ObstacleSet &set) const;
  65. void setType(ObstacleSet::EObstacleType type);
  66. void setTypes(std::vector<ObstacleSet::EObstacleType> types);
  67. std::vector<ObstacleSet::EObstacleType> getAllowedTypes() const;
  68. TerrainId getTerrain() const;
  69. void setAlignment(EAlignment alignment);
  70. private:
  71. std::vector<ObstacleSet::EObstacleType> allowedTypes;
  72. FactionID faction;
  73. EAlignment alignment;
  74. // TODO: Filter by faction, surface/underground, etc.
  75. const TerrainId terrain;
  76. };
  77. // TODO: Instantiate ObstacleSetHandler
  78. class DLL_LINKAGE ObstacleSetHandler : public IHandlerBase, boost::noncopyable
  79. {
  80. public:
  81. ObstacleSetHandler() = default;
  82. ~ObstacleSetHandler() = default;
  83. std::vector<JsonNode> loadLegacyData() override;
  84. virtual void loadObject(std::string scope, std::string name, const JsonNode & data) override;
  85. virtual void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
  86. std::shared_ptr<ObstacleSet> loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index);
  87. ObstacleSet::EObstacleType convertObstacleClass(MapObjectID id);
  88. // TODO: Populate obstacleSets with all the obstacle sets from the game data
  89. void addTemplate(const std::string & scope, const std::string &name, std::shared_ptr<const ObjectTemplate> tmpl);
  90. void addObstacleSet(std::shared_ptr<ObstacleSet> set);
  91. TObstacleTypes getObstacles(const ObstacleSetFilter &filter) const;
  92. private:
  93. std::vector< std::shared_ptr<ObstacleSet> > biomes;
  94. // TODO: Serialize?
  95. std::map<si32, std::shared_ptr<const ObjectTemplate>> obstacleTemplates;
  96. // FIXME: Store pointers?
  97. std::map<ObstacleSet::EObstacleType, std::vector<std::shared_ptr<ObstacleSet>>> obstacleSets;
  98. };
  99. VCMI_LIB_NAMESPACE_END