1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

It is now possible to define game settings in rmg template

This commit is contained in:
Ivan Savenko 2024-09-04 18:18:10 +00:00
parent 8225eb454e
commit ff8d36c350
8 changed files with 40 additions and 5 deletions

View File

@ -131,6 +131,13 @@
"description" : "Maximal size of the map, e.g. 'm+u' or '120x120x1",
"type": "string"
},
"settings" : {
"description" : "List of changed game settings by template",
"type" : "object",
"additionalProperties" : {
"type" : "object"
}
},
"name" : {
"description" : "Optional name - useful to have several template variations with same name",
"type": "string"

View File

@ -25,6 +25,15 @@
///Optional parameter allowing to prohibit some water modes. All modes are allowed if parameter is not specified
"allowedWaterContent" : ["none", "normal", "islands"]
/// List of game settings that were overriden by this template. See config/gameConfig.json in vcmi install directory for possible values
/// Settings defined here will always override any settings from vcmi or from mods
"settings" : {
"heroes" : {
"perPlayerOnMapCap" : 1
}
}
},
/// List of named zones, see below for format description
"zones" :

View File

@ -36,9 +36,6 @@ class DLL_LINKAGE GameSettings final : public IGameSettings, boost::noncopyable
// converts all existing overrides into a single json node for serialization
JsonNode getAllOverrides() const;
// loads all overrides from provided json node, for deserialization
void loadOverrides(const JsonNode &);
public:
GameSettings();
~GameSettings();
@ -51,6 +48,9 @@ public:
/// undefined behavior if setting was already overriden (TODO: decide which approach is better - replace or append)
void addOverride(EGameSettings option, const JsonNode & input);
// loads all overrides from provided json node, for deserialization
void loadOverrides(const JsonNode &);
JsonNode getFullConfig() const override;
const JsonNode & getValue(EGameSettings option) const override;

View File

@ -795,5 +795,9 @@ void CMap::overrideGameSetting(EGameSettings option, const JsonNode & input)
return gameSettings->addOverride(option, input);
}
void CMap::overrideGameSettings(const JsonNode & input)
{
return gameSettings->loadOverrides(input);
}
VCMI_LIB_NAMESPACE_END

View File

@ -180,6 +180,7 @@ public:
std::vector<const CArtifact *> townMerchantArtifacts;
std::vector<TradeItemBuy> townUniversitySkills;
void overrideGameSettings(const JsonNode & input);
void overrideGameSetting(EGameSettings option, const JsonNode & input);
const IGameSettings & getSettings() const;

View File

@ -455,6 +455,7 @@ void CMapGenerator::addHeaderInfo()
addPlayerInfo();
m.waterMap = (mapGenOptions.getWaterContent() != EWaterContent::EWaterContent::NONE);
m.banWaterContent();
m.overrideGameSettings(mapGenOptions.getMapTemplate()->getMapSettings());
}
int CMapGenerator::getNextMonlithIndex()

View File

@ -501,9 +501,12 @@ void ZoneConnection::serializeJson(JsonSerializeFormat & handler)
using namespace rmg;//todo: remove
CRmgTemplate::~CRmgTemplate() = default;
CRmgTemplate::CRmgTemplate()
: minSize(72, 72, 2),
maxSize(72, 72, 2)
maxSize(72, 72, 2),
mapSettings(std::make_unique<JsonNode>())
{
}
@ -694,6 +697,8 @@ void CRmgTemplate::serializeJson(JsonSerializeFormat & handler)
serializePlayers(handler, players, "players");
serializePlayers(handler, humanPlayers, "humans"); // TODO: Rename this parameter
*mapSettings = handler.getCurrent()["settings"];
{
auto connectionsData = handler.enterArray("connections");
connectionsData.serializeStruct(connectedZoneIds);
@ -749,6 +754,11 @@ void CRmgTemplate::serializeJson(JsonSerializeFormat & handler)
}
}
const JsonNode & CRmgTemplate::getMapSettings() const
{
return *mapSettings;
}
std::set<TerrainId> CRmgTemplate::inheritTerrainType(std::shared_ptr<ZoneOptions> zone, uint32_t iteration /* = 0 */)
{
if (iteration >= 50)

View File

@ -216,7 +216,7 @@ protected:
}
/// The CRmgTemplate describes a random map template.
class DLL_LINKAGE CRmgTemplate
class DLL_LINKAGE CRmgTemplate : boost::noncopyable
{
public:
using Zones = std::map<TRmgTemplateZoneId, std::shared_ptr<rmg::ZoneOptions>>;
@ -240,6 +240,7 @@ public:
};
CRmgTemplate();
~CRmgTemplate();
bool matchesSize(const int3 & value) const;
bool isWaterContentAllowed(EWaterContent::EWaterContent waterContent) const;
@ -255,6 +256,7 @@ public:
const CPlayerCountRange & getHumanPlayers() const;
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
@ -273,6 +275,7 @@ private:
Zones zones;
std::vector<rmg::ZoneConnection> connectedZoneIds;
std::set<EWaterContent::EWaterContent> allowedWaterContent;
std::unique_ptr<JsonNode> mapSettings;
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);