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

320 lines
8.4 KiB
C++
Raw Normal View History

/*
* CRmgTemplate.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 "../int3.h"
#include "../GameConstants.h"
#include "../ResourceSet.h"
#include "ObjectInfo.h"
2024-09-14 08:41:00 +02:00
#include "ObjectConfig.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
class JsonSerializeFormat;
struct CompoundMapObjectID;
enum class ETemplateZoneType
{
PLAYER_START,
CPU_START,
TREASURE,
JUNCTION,
WATER
};
namespace EWaterContent // Not enum class, because it's used in method RandomMapTab::setMapGenOptions
{ // defined in client\lobby\RandomMapTab.cpp and probably in other similar places
enum EWaterContent // as an argument of CToggleGroup::setSelected(int id) from \client\widgets\Buttons.cpp
2022-12-14 02:37:11 +02:00
{
RANDOM = -1,
NONE,
NORMAL,
ISLANDS
};
}
namespace EMonsterStrength // used as int in monster generation procedure and in map description for the generated random map
2022-12-14 02:37:11 +02:00
{
enum EMonsterStrength
{
ZONE_NONE = -3,
RANDOM = -2,
2022-12-14 02:37:11 +02:00
ZONE_WEAK = -1,
ZONE_NORMAL = 0,
ZONE_STRONG = 1,
GLOBAL_WEAK = 2,
GLOBAL_NORMAL = 3,
GLOBAL_STRONG = 4
};
}
class DLL_LINKAGE CTreasureInfo
{
public:
ui32 min;
ui32 max;
ui16 density;
CTreasureInfo();
CTreasureInfo(ui32 min, ui32 max, ui16 density);
bool operator ==(const CTreasureInfo & other) const;
void serializeJson(JsonSerializeFormat & handler);
};
2023-07-07 16:32:17 +02:00
namespace rmg
{
2023-07-07 16:32:17 +02:00
enum class EConnectionType
{
2023-07-07 16:32:17 +02:00
GUARDED = 0, //default
FICTIVE,
REPULSIVE,
2024-07-29 20:36:23 +02:00
WIDE,
FORCE_PORTAL
2023-07-07 16:32:17 +02:00
};
2023-07-07 16:32:17 +02:00
enum class ERoadOption
{
2023-07-07 16:32:17 +02:00
ROAD_TRUE,
ROAD_FALSE,
ROAD_RANDOM
};
class DLL_LINKAGE ZoneConnection
{
public:
ZoneConnection();
TRmgTemplateZoneId getZoneA() const;
TRmgTemplateZoneId getZoneB() const;
TRmgTemplateZoneId getOtherZoneId(TRmgTemplateZoneId id) const;
int getGuardStrength() const;
2023-07-07 16:32:17 +02:00
rmg::EConnectionType getConnectionType() const;
rmg::ERoadOption getRoadOption() const;
void serializeJson(JsonSerializeFormat & handler);
friend bool operator==(const ZoneConnection &, const ZoneConnection &);
private:
TRmgTemplateZoneId zoneA;
TRmgTemplateZoneId zoneB;
int guardStrength;
2023-07-07 16:32:17 +02:00
rmg::EConnectionType connectionType;
rmg::ERoadOption hasRoad;
};
class DLL_LINKAGE ZoneOptions
{
public:
static const TRmgTemplateZoneId NO_ZONE;
class DLL_LINKAGE CTownInfo
{
public:
CTownInfo();
int getTownCount() const;
int getCastleCount() const;
int getTownDensity() const;
int getCastleDensity() const;
void serializeJson(JsonSerializeFormat & handler);
private:
int townCount;
int castleCount;
int townDensity;
int castleDensity;
// TODO: Copy from another zone once its randomized
TRmgTemplateZoneId sourceZone = NO_ZONE;
};
ZoneOptions();
TRmgTemplateZoneId getId() const;
void setId(TRmgTemplateZoneId value);
ETemplateZoneType getType() const;
void setType(ETemplateZoneType value);
int getSize() const;
void setSize(int value);
2023-04-16 19:42:56 +02:00
std::optional<int> getOwner() const;
std::set<TerrainId> getTerrainTypes() const;
2022-09-29 11:44:46 +02:00
void setTerrainTypes(const std::set<TerrainId> & value);
std::set<TerrainId> getDefaultTerrainTypes() const;
const CTownInfo & getPlayerTowns() const;
const CTownInfo & getNeutralTowns() const;
std::set<FactionID> getDefaultTownTypes() const;
std::set<FactionID> getTownTypes() const;
std::set<FactionID> getMonsterTypes() const;
void setTownTypes(const std::set<FactionID> & value);
void setMonsterTypes(const std::set<FactionID> & value);
void setMinesInfo(const std::map<TResource, ui16> & value);
std::map<TResource, ui16> getMinesInfo() const;
void setTreasureInfo(const std::vector<CTreasureInfo> & value);
void addTreasureInfo(const CTreasureInfo & value);
std::vector<CTreasureInfo> getTreasureInfo() const;
ui32 getMaxTreasureValue() const;
2023-03-28 17:13:24 +02:00
void recalculateMaxTreasureValue();
TRmgTemplateZoneId getMinesLikeZone() const;
TRmgTemplateZoneId getTerrainTypeLikeZone() const;
TRmgTemplateZoneId getTreasureLikeZone() const;
void addConnection(const ZoneConnection & connection);
std::vector<ZoneConnection> getConnections() const;
std::vector<TRmgTemplateZoneId> getConnectedZoneIds() const;
void serializeJson(JsonSerializeFormat & handler);
2023-05-21 00:13:45 +02:00
EMonsterStrength::EMonsterStrength monsterStrength;
bool areTownsSameType() const;
bool isMatchTerrainToTown() const;
// Get a group of configured objects
const std::vector<CompoundMapObjectID> & getBannedObjects() const;
const std::vector<ObjectConfig::EObjectCategory> & getBannedObjectCategories() const;
const std::vector<ObjectInfo> & getConfiguredObjects() const;
// Copy whole custom object config from another zone
ObjectConfig getCustomObjects() const;
void setCustomObjects(const ObjectConfig & value);
TRmgTemplateZoneId getCustomObjectsLikeZone() const;
protected:
TRmgTemplateZoneId id;
ETemplateZoneType type;
int size;
ui32 maxTreasureValue;
2023-04-16 19:42:56 +02:00
std::optional<int> owner;
ObjectConfig objectConfig;
CTownInfo playerTowns;
CTownInfo neutralTowns;
bool matchTerrainToTown;
2022-09-29 11:44:46 +02:00
std::set<TerrainId> terrainTypes;
std::set<TerrainId> bannedTerrains;
bool townsAreSameType;
std::set<FactionID> townTypes;
std::set<FactionID> bannedTownTypes;
std::set<FactionID> monsterTypes;
std::set<FactionID> bannedMonsters;
std::map<TResource, ui16> mines; //obligatory mines to spawn in this zone
std::vector<CTreasureInfo> treasureInfo;
std::vector<TRmgTemplateZoneId> connectedZoneIds; //list of adjacent zone ids
std::vector<ZoneConnection> connectionDetails; //list of connections linked to that zone
TRmgTemplateZoneId minesLikeZone;
TRmgTemplateZoneId terrainTypeLikeZone;
TRmgTemplateZoneId treasureLikeZone;
TRmgTemplateZoneId customObjectsLikeZone;
};
}
/// The CRmgTemplate describes a random map template.
class DLL_LINKAGE CRmgTemplate : boost::noncopyable
{
public:
using Zones = std::map<TRmgTemplateZoneId, std::shared_ptr<rmg::ZoneOptions>>;
class DLL_LINKAGE CPlayerCountRange
{
public:
void addRange(int lower, int upper);
void addNumber(int value);
bool isInRange(int count) const;
std::set<int> getNumbers() const;
std::string toString() const;
void fromString(const std::string & value);
int maxValue() const;
int minValue() const;
private:
std::vector<std::pair<int, int> > range;
};
CRmgTemplate();
~CRmgTemplate();
bool matchesSize(const int3 & value) const;
bool isWaterContentAllowed(EWaterContent::EWaterContent waterContent) const;
const std::set<EWaterContent::EWaterContent> & getWaterContentAllowed() const;
void setId(const std::string & value);
2022-12-14 02:37:11 +02:00
void setName(const std::string & value);
const std::string & getId() const;
const std::string & getName() const;
const std::string & getDescription() const;
const CPlayerCountRange & getPlayers() const;
const CPlayerCountRange & getHumanPlayers() const;
2022-12-14 02:37:11 +02:00
std::pair<int3, int3> getMapSizes() const;
const Zones & getZones() const;
const JsonNode & getMapSettings() const;
const std::vector<rmg::ZoneConnection> & getConnectedZoneIds() const;
void validate() const; /// Tests template on validity and throws exception on failure
void serializeJson(JsonSerializeFormat & handler);
void afterLoad();
private:
std::string id;
std::string name;
std::string description;
int3 minSize;
int3 maxSize;
CPlayerCountRange players;
CPlayerCountRange humanPlayers;
Zones zones;
std::vector<rmg::ZoneConnection> connectedZoneIds;
std::set<EWaterContent::EWaterContent> allowedWaterContent;
std::unique_ptr<JsonNode> mapSettings;
2023-03-19 10:51:37 +02:00
std::set<TerrainId> inheritTerrainType(std::shared_ptr<rmg::ZoneOptions> zone, uint32_t iteration = 0);
std::map<TResource, ui16> inheritMineTypes(std::shared_ptr<rmg::ZoneOptions> zone, uint32_t iteration = 0);
std::vector<CTreasureInfo> inheritTreasureInfo(std::shared_ptr<rmg::ZoneOptions> zone, uint32_t iteration = 0);
// TODO: Copy custom object settings
// TODO: Copy town type after source town is actually randomized
void serializeSize(JsonSerializeFormat & handler, int3 & value, const std::string & fieldName);
void serializePlayers(JsonSerializeFormat & handler, CPlayerCountRange & value, const std::string & fieldName);
template<typename T>
T inheritZoneProperty(std::shared_ptr<rmg::ZoneOptions> zone,
T (rmg::ZoneOptions::*getter)() const,
void (rmg::ZoneOptions::*setter)(const T&),
TRmgTemplateZoneId (rmg::ZoneOptions::*inheritFrom)() const,
const std::string& propertyString,
uint32_t iteration = 0);
};
VCMI_LIB_NAMESPACE_END