/* * ObstacleSetHandler.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * */ #pragma once #include "../GameConstants.h" #include "../constants/EntityIdentifiers.h" #include "../IHandlerBase.h" #include "../json/JsonNode.h" #include "ObjectTemplate.h" VCMI_LIB_NAMESPACE_BEGIN class DLL_LINKAGE ObstacleSet { public: // TODO: Create string constants for these enum EObstacleType { INVALID = -1, MOUNTAINS = 0, TREES, LAKES, // Including dry or lava lakes CRATERS, // Chasms, Canyons, etc. ROCKS, PLANTS, // Flowers, cacti, mushrooms, logs, shrubs, etc. STRUCTURES, // Buildings, ruins, etc. ANIMALS, // Living, or bones OTHER // Crystals, shipwrecks, barrels, etc. }; ObstacleSet(); explicit ObstacleSet(EObstacleType type, TerrainId terrain); void addObstacle(std::shared_ptr obstacle); void removeEmptyTemplates(); std::vector> getObstacles() const; EObstacleType getType() const; void setType(EObstacleType type); std::set getTerrains() const; void setTerrain(TerrainId terrain); void setTerrains(const std::set & terrains); void addTerrain(TerrainId terrain); EMapLevel getLevel() const; void setLevel(EMapLevel level); std::set getAlignments() const; void addAlignment(EAlignment alignment); std::set getFactions() const; void addFaction(FactionID faction); static EObstacleType typeFromString(const std::string &str); std::string toString() const; static EMapLevel levelFromString(const std::string &str); si32 id; private: EObstacleType type; EMapLevel level; std::set allowedTerrains; // Empty means all terrains std::set allowedFactions; // Empty means all factions std::set allowedAlignments; // Empty means all alignments std::vector> obstacles; }; using TObstacleTypes = std::vector>; class DLL_LINKAGE ObstacleSetFilter { public: ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain, EMapLevel level, FactionID faction, EAlignment alignment); ObstacleSetFilter(std::vector allowedTypes, TerrainId terrain, EMapLevel level, FactionID faction, EAlignment alignment); bool filter(const ObstacleSet &set) const; void setType(ObstacleSet::EObstacleType type); void setTypes(const std::vector & types); std::vector getAllowedTypes() const; TerrainId getTerrain() const; void setAlignment(EAlignment alignment); private: std::vector allowedTypes; FactionID faction; EAlignment alignment; // TODO: Filter by faction, surface/underground, etc. const TerrainId terrain; EMapLevel level; }; // TODO: Instantiate ObstacleSetHandler class DLL_LINKAGE ObstacleSetHandler : public IHandlerBase, boost::noncopyable { public: ObstacleSetHandler() = default; ~ObstacleSetHandler() = default; std::vector loadLegacyData() override; void loadObject(std::string scope, std::string name, const JsonNode & data) override; void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override; std::shared_ptr loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index); ObstacleSet::EObstacleType convertObstacleClass(MapObjectID id); // TODO: Populate obstacleSets with all the obstacle sets from the game data void addTemplate(const std::string & scope, const std::string &name, std::shared_ptr tmpl); void addObstacleSet(std::shared_ptr set); void afterLoadFinalization() override; TObstacleTypes getObstacles(const ObstacleSetFilter &filter) const; private: std::vector< std::shared_ptr > biomes; // TODO: Serialize? std::map> obstacleTemplates; // FIXME: Store pointers? std::map>> obstacleSets; }; VCMI_LIB_NAMESPACE_END