1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* 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<const ObjectTemplate> obstacle);
void removeEmptyTemplates();
std::vector<std::shared_ptr<const ObjectTemplate>> getObstacles() const;
EObstacleType getType() const;
void setType(EObstacleType type);
std::set<TerrainId> getTerrains() const;
void setTerrain(TerrainId terrain);
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);
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<TerrainId> allowedTerrains; // Empty means all terrains
std::set<FactionID> allowedFactions; // Empty means all factions
std::set<EAlignment> allowedAlignments; // Empty means all alignments
std::vector<std::shared_ptr<const ObjectTemplate>> obstacles;
};
using TObstacleTypes = std::vector<std::shared_ptr<ObstacleSet>>;
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);
bool filter(const ObstacleSet &set) const;
void setType(ObstacleSet::EObstacleType type);
void setTypes(const std::vector<ObstacleSet::EObstacleType> & types);
std::vector<ObstacleSet::EObstacleType> getAllowedTypes() const;
TerrainId getTerrain() const;
void setAlignment(EAlignment alignment);
private:
std::vector<ObstacleSet::EObstacleType> 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<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);
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);
void addObstacleSet(std::shared_ptr<ObstacleSet> set);
void afterLoadFinalization() override;
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;
};
VCMI_LIB_NAMESPACE_END
|