1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/lib/mapObjects/ObstacleSetHandler.h

140 lines
4.2 KiB
C++
Raw Normal View History

2024-04-04 21:39:01 +02:00
/*
* 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
{
2024-04-05 08:31:05 +02:00
INVALID = -1,
MOUNTAINS = 0,
2024-04-04 21:39:01 +02:00
TREES,
LAKES, // Inluding 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();
2024-04-04 21:39:01 +02:00
explicit ObstacleSet(EObstacleType type, TerrainId terrain);
void addObstacle(std::shared_ptr<const ObjectTemplate> obstacle);
void removeEmptyTemplates();
2024-04-04 21:39:01 +02:00
std::vector<std::shared_ptr<const ObjectTemplate>> getObstacles() const;
EObstacleType getType() const;
void setType(EObstacleType type);
2024-04-10 09:40:12 +02:00
std::set<TerrainId> getTerrains() const;
void setTerrain(TerrainId terrain);
2024-04-10 09:40:12 +02:00
void setTerrains(const std::set<TerrainId> & terrains);
void addTerrain(TerrainId terrain);
EMapLevel getLevel() const;
void setLevel(EMapLevel level);
std::set<EAlignment> getAlignments() const;
void addAlignment(EAlignment alignment);
std::set<FactionID> getFactions() const;
void addFaction(FactionID faction);
2024-04-04 21:39:01 +02:00
2024-04-05 08:31:05 +02:00
static EObstacleType typeFromString(const std::string &str);
std::string toString() const;
static EMapLevel levelFromString(const std::string &str);
si32 id;
2024-04-05 08:31:05 +02:00
2024-04-04 21:39:01 +02:00
private:
2024-04-12 14:53:07 +02:00
2024-04-04 21:39:01 +02:00
EObstacleType type;
EMapLevel level;
2024-04-12 14:53:07 +02:00
std::set<TerrainId> allowedTerrains; // Empty means all terrains
std::set<FactionID> allowedFactions; // Empty means all factions
std::set<EAlignment> allowedAlignments; // Empty means all alignments
2024-04-04 21:39:01 +02:00
std::vector<std::shared_ptr<const ObjectTemplate>> obstacles;
};
using TObstacleTypes = std::vector<std::shared_ptr<ObstacleSet>>;
2024-04-04 21:39:01 +02:00
class DLL_LINKAGE ObstacleSetFilter
{
public:
ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain, EMapLevel level, FactionID faction, EAlignment alignment);
ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain, EMapLevel level, FactionID faction, EAlignment alignment);
2024-04-04 21:39:01 +02:00
bool filter(const ObstacleSet &set) const;
void setType(ObstacleSet::EObstacleType type);
void setTypes(const std::vector<ObstacleSet::EObstacleType> & types);
2024-04-04 21:39:01 +02:00
std::vector<ObstacleSet::EObstacleType> getAllowedTypes() const;
TerrainId getTerrain() const;
void setAlignment(EAlignment alignment);
2024-04-04 21:39:01 +02:00
private:
std::vector<ObstacleSet::EObstacleType> allowedTypes;
FactionID faction;
EAlignment alignment;
// TODO: Filter by faction, surface/underground, etc.
2024-04-04 21:39:01 +02:00
const TerrainId terrain;
EMapLevel level;
2024-04-04 21:39:01 +02:00
};
// TODO: Instantiate ObstacleSetHandler
class DLL_LINKAGE ObstacleSetHandler : public IHandlerBase, boost::noncopyable
{
public:
ObstacleSetHandler() = default;
~ObstacleSetHandler() = default;
std::vector<JsonNode> 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<ObstacleSet> loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index);
2024-04-04 21:39:01 +02:00
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<const ObjectTemplate> tmpl);
2024-04-04 21:39:01 +02:00
void addObstacleSet(std::shared_ptr<ObstacleSet> set);
void afterLoadFinalization() override;
2024-04-04 21:39:01 +02:00
TObstacleTypes getObstacles(const ObstacleSetFilter &filter) const;
private:
std::vector< std::shared_ptr<ObstacleSet> > biomes;
// TODO: Serialize?
std::map<si32, std::shared_ptr<const ObjectTemplate>> obstacleTemplates;
// FIXME: Store pointers?
std::map<ObstacleSet::EObstacleType, std::vector<std::shared_ptr<ObstacleSet>>> obstacleSets;
2024-04-04 21:39:01 +02:00
};
VCMI_LIB_NAMESPACE_END