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.
|
|
|
|
};
|
2024-05-07 07:15:00 +02:00
|
|
|
|
|
|
|
enum EMapLevel // TODO: Move somewhere to map definitions
|
|
|
|
{
|
|
|
|
ANY = -1,
|
|
|
|
SURFACE = 0,
|
|
|
|
UNDERGROUND = 1
|
|
|
|
};
|
|
|
|
|
2024-04-08 12:50:41 +02:00
|
|
|
ObstacleSet();
|
2024-04-04 21:39:01 +02:00
|
|
|
explicit ObstacleSet(EObstacleType type, TerrainId terrain);
|
|
|
|
|
|
|
|
void addObstacle(std::shared_ptr<const ObjectTemplate> obstacle);
|
2024-04-13 14:53:00 +02:00
|
|
|
void removeEmptyTemplates();
|
2024-04-04 21:39:01 +02:00
|
|
|
std::vector<std::shared_ptr<const ObjectTemplate>> getObstacles() const;
|
|
|
|
|
|
|
|
EObstacleType getType() const;
|
2024-04-08 12:50:41 +02:00
|
|
|
void setType(EObstacleType type);
|
|
|
|
|
2024-04-10 09:40:12 +02:00
|
|
|
std::set<TerrainId> getTerrains() const;
|
2024-04-08 12:50:41 +02:00
|
|
|
void setTerrain(TerrainId terrain);
|
2024-04-10 09:40:12 +02:00
|
|
|
void setTerrains(const std::set<TerrainId> & terrains);
|
|
|
|
void addTerrain(TerrainId terrain);
|
2024-05-07 07:15:00 +02:00
|
|
|
EMapLevel getLevel() const;
|
|
|
|
void setLevel(EMapLevel level);
|
2024-04-11 18:10:14 +02:00
|
|
|
std::set<EAlignment> getAlignments() const;
|
|
|
|
void addAlignment(EAlignment alignment);
|
2024-04-12 10:25:13 +02:00
|
|
|
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);
|
2024-04-08 12:50:41 +02:00
|
|
|
std::string toString() const;
|
2024-05-07 07:15:00 +02:00
|
|
|
static EMapLevel levelFromString(const std::string &str);
|
2024-04-08 12:50:41 +02:00
|
|
|
|
|
|
|
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;
|
2024-05-07 07:15:00 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2024-04-08 12:50:41 +02:00
|
|
|
typedef std::vector<std::shared_ptr<ObstacleSet>> TObstacleTypes;
|
2024-04-04 21:39:01 +02:00
|
|
|
|
|
|
|
class DLL_LINKAGE ObstacleSetFilter
|
|
|
|
{
|
|
|
|
public:
|
2024-05-07 07:15:00 +02:00
|
|
|
ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain, ObstacleSet::EMapLevel level, FactionID faction, EAlignment alignment);
|
|
|
|
ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain, ObstacleSet::EMapLevel level, FactionID faction, EAlignment alignment);
|
2024-04-04 21:39:01 +02:00
|
|
|
|
|
|
|
bool filter(const ObstacleSet &set) const;
|
|
|
|
|
2024-04-11 18:10:14 +02:00
|
|
|
void setType(ObstacleSet::EObstacleType type);
|
|
|
|
void setTypes(std::vector<ObstacleSet::EObstacleType> types);
|
2024-04-04 21:39:01 +02:00
|
|
|
std::vector<ObstacleSet::EObstacleType> getAllowedTypes() const;
|
|
|
|
TerrainId getTerrain() const;
|
|
|
|
|
2024-04-11 18:10:14 +02:00
|
|
|
void setAlignment(EAlignment alignment);
|
|
|
|
|
2024-04-04 21:39:01 +02:00
|
|
|
private:
|
|
|
|
std::vector<ObstacleSet::EObstacleType> allowedTypes;
|
2024-04-12 10:25:13 +02:00
|
|
|
FactionID faction;
|
2024-04-11 18:10:14 +02:00
|
|
|
EAlignment alignment;
|
|
|
|
// TODO: Filter by faction, surface/underground, etc.
|
2024-04-04 21:39:01 +02:00
|
|
|
const TerrainId terrain;
|
2024-05-07 07:15:00 +02:00
|
|
|
ObstacleSet::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;
|
|
|
|
|
2024-04-08 12:50:41 +02:00
|
|
|
std::vector<JsonNode> loadLegacyData() override;
|
|
|
|
virtual void loadObject(std::string scope, std::string name, const JsonNode & data) override;
|
|
|
|
virtual 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
|
2024-04-08 12:50:41 +02:00
|
|
|
void addTemplate(const std::string & scope, const std::string &name, std::shared_ptr<const ObjectTemplate> tmpl);
|
2024-04-04 21:39:01 +02:00
|
|
|
|
2024-04-08 12:50:41 +02:00
|
|
|
void addObstacleSet(std::shared_ptr<ObstacleSet> set);
|
2024-04-13 14:53:00 +02:00
|
|
|
|
|
|
|
void afterLoadFinalization() override;
|
2024-04-04 21:39:01 +02:00
|
|
|
|
|
|
|
TObstacleTypes getObstacles(const ObstacleSetFilter &filter) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2024-04-08 12:50:41 +02:00
|
|
|
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
|