2013-08-17 15:46:48 +03:00
|
|
|
/*
|
|
|
|
* CRmgTemplate.cpp, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
2018-03-09 20:11:20 +02:00
|
|
|
#include <vstd/ContainerUtils.h>
|
2022-06-05 08:02:58 +02:00
|
|
|
#include <boost/bimap.hpp>
|
2013-08-17 15:46:48 +03:00
|
|
|
#include "CRmgTemplate.h"
|
2023-06-17 19:09:38 +02:00
|
|
|
#include "Functions.h"
|
2024-09-14 08:41:00 +02:00
|
|
|
|
2023-01-09 01:17:37 +02:00
|
|
|
#include "../TerrainHandler.h"
|
2024-07-21 12:49:40 +02:00
|
|
|
#include "../VCMI_Lib.h"
|
2023-08-19 23:22:31 +02:00
|
|
|
#include "../constants/StringConstants.h"
|
2024-07-21 12:49:40 +02:00
|
|
|
#include "../entities/faction/CTownHandler.h"
|
|
|
|
#include "../modding/ModScope.h"
|
|
|
|
#include "../serializer/JsonSerializeFormat.h"
|
2018-03-09 20:11:20 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
si32 decodeZoneId(const std::string & json)
|
|
|
|
{
|
|
|
|
return boost::lexical_cast<si32>(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string encodeZoneId(si32 id)
|
|
|
|
{
|
2023-02-11 18:05:02 +02:00
|
|
|
return std::to_string(id);
|
2018-03-09 20:11:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CTreasureInfo::CTreasureInfo()
|
|
|
|
: min(0),
|
|
|
|
max(0),
|
|
|
|
density(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-31 11:25:39 +02:00
|
|
|
CTreasureInfo::CTreasureInfo(ui32 imin, ui32 imax, ui16 idensity)
|
|
|
|
: min(imin), max(imax), density(idensity)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
bool CTreasureInfo::operator==(const CTreasureInfo & other) const
|
|
|
|
{
|
|
|
|
return (min == other.min) && (max == other.max) && (density == other.density);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTreasureInfo::serializeJson(JsonSerializeFormat & handler)
|
|
|
|
{
|
|
|
|
handler.serializeInt("min", min, 0);
|
|
|
|
handler.serializeInt("max", max, 0);
|
|
|
|
handler.serializeInt("density", density, 0);
|
|
|
|
}
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
namespace rmg
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
const TRmgTemplateZoneId ZoneOptions::NO_ZONE = -1;
|
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
ZoneOptions::CTownInfo::CTownInfo()
|
|
|
|
: townCount(0),
|
|
|
|
castleCount(0),
|
|
|
|
townDensity(0),
|
|
|
|
castleDensity(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int ZoneOptions::CTownInfo::getTownCount() const
|
|
|
|
{
|
|
|
|
return townCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ZoneOptions::CTownInfo::getCastleCount() const
|
|
|
|
{
|
|
|
|
return castleCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ZoneOptions::CTownInfo::getTownDensity() const
|
|
|
|
{
|
|
|
|
return townDensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ZoneOptions::CTownInfo::getCastleDensity() const
|
|
|
|
{
|
|
|
|
return castleDensity;
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void ZoneOptions::CTownInfo::serializeJson(JsonSerializeFormat & handler)
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
handler.serializeInt("towns", townCount, 0);
|
|
|
|
handler.serializeInt("castles", castleCount, 0);
|
|
|
|
handler.serializeInt("townDensity", townDensity, 0);
|
|
|
|
handler.serializeInt("castleDensity", castleDensity, 0);
|
2024-08-21 20:16:41 +02:00
|
|
|
handler.serializeInt("sourceZone", sourceZone, NO_ZONE);
|
2018-03-05 16:05:17 +02:00
|
|
|
}
|
|
|
|
|
2023-02-11 18:05:02 +02:00
|
|
|
ZoneOptions::ZoneOptions():
|
|
|
|
id(0),
|
2018-03-05 16:05:17 +02:00
|
|
|
type(ETemplateZoneType::PLAYER_START),
|
|
|
|
size(1),
|
2023-03-27 17:29:46 +02:00
|
|
|
maxTreasureValue(0),
|
2023-04-16 19:42:56 +02:00
|
|
|
owner(std::nullopt),
|
2018-03-05 16:05:17 +02:00
|
|
|
matchTerrainToTown(true),
|
|
|
|
townsAreSameType(false),
|
2023-05-21 00:13:45 +02:00
|
|
|
monsterStrength(EMonsterStrength::ZONE_NORMAL),
|
2018-03-09 20:11:20 +02:00
|
|
|
minesLikeZone(NO_ZONE),
|
|
|
|
terrainTypeLikeZone(NO_ZONE),
|
|
|
|
treasureLikeZone(NO_ZONE)
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TRmgTemplateZoneId ZoneOptions::getId() const
|
|
|
|
{
|
|
|
|
return id;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
void ZoneOptions::setId(TRmgTemplateZoneId value)
|
|
|
|
{
|
|
|
|
if(value <= 0)
|
2023-08-20 22:45:41 +02:00
|
|
|
throw std::runtime_error(boost::str(boost::format("Zone %d id should be greater than 0.") % id));
|
2018-03-05 16:05:17 +02:00
|
|
|
id = value;
|
|
|
|
}
|
|
|
|
|
2023-05-20 13:29:55 +02:00
|
|
|
ETemplateZoneType ZoneOptions::getType() const
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
2022-05-31 11:25:39 +02:00
|
|
|
|
2023-05-20 13:29:55 +02:00
|
|
|
void ZoneOptions::setType(ETemplateZoneType value)
|
2022-05-31 11:25:39 +02:00
|
|
|
{
|
|
|
|
type = value;
|
|
|
|
}
|
2018-03-05 16:05:17 +02:00
|
|
|
|
|
|
|
int ZoneOptions::getSize() const
|
|
|
|
{
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoneOptions::setSize(int value)
|
|
|
|
{
|
|
|
|
size = value;
|
|
|
|
}
|
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
std::optional<int> ZoneOptions::getOwner() const
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
|
|
|
return owner;
|
|
|
|
}
|
|
|
|
|
2024-08-24 20:18:36 +02:00
|
|
|
std::set<TerrainId> ZoneOptions::getTerrainTypes() const
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
2023-07-06 17:30:23 +02:00
|
|
|
if (terrainTypes.empty())
|
|
|
|
{
|
|
|
|
return vstd::difference(getDefaultTerrainTypes(), bannedTerrains);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return terrainTypes;
|
|
|
|
}
|
2018-03-05 16:05:17 +02:00
|
|
|
}
|
|
|
|
|
2022-09-29 11:44:46 +02:00
|
|
|
void ZoneOptions::setTerrainTypes(const std::set<TerrainId> & value)
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
|
|
|
terrainTypes = value;
|
|
|
|
}
|
|
|
|
|
2023-07-06 17:30:23 +02:00
|
|
|
std::set<TerrainId> ZoneOptions::getDefaultTerrainTypes() const
|
|
|
|
{
|
|
|
|
std::set<TerrainId> terrains;
|
2024-05-17 00:05:51 +02:00
|
|
|
for(const auto & terrain : VLC->terrainTypeHandler->objects)
|
2023-07-06 17:30:23 +02:00
|
|
|
{
|
|
|
|
if (terrain->isLand() && terrain->isPassable())
|
|
|
|
{
|
|
|
|
terrains.insert(terrain->getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return terrains;
|
|
|
|
}
|
|
|
|
|
2023-04-09 17:26:32 +02:00
|
|
|
std::set<FactionID> ZoneOptions::getDefaultTownTypes() const
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
2023-11-05 15:24:26 +02:00
|
|
|
return VLC->townh->getDefaultAllowed();
|
2018-03-05 16:05:17 +02:00
|
|
|
}
|
|
|
|
|
2024-08-24 20:18:36 +02:00
|
|
|
std::set<FactionID> ZoneOptions::getTownTypes() const
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
2023-07-02 11:41:47 +02:00
|
|
|
if (townTypes.empty())
|
|
|
|
{
|
|
|
|
//Assume that all towns are allowed, unless banned
|
|
|
|
return vstd::difference(getDefaultTownTypes(), bannedTownTypes);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return vstd::difference(townTypes, bannedTownTypes);
|
|
|
|
}
|
2018-03-05 16:05:17 +02:00
|
|
|
}
|
|
|
|
|
2023-04-09 17:26:32 +02:00
|
|
|
void ZoneOptions::setTownTypes(const std::set<FactionID> & value)
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
|
|
|
townTypes = value;
|
|
|
|
}
|
|
|
|
|
2023-04-09 17:26:32 +02:00
|
|
|
void ZoneOptions::setMonsterTypes(const std::set<FactionID> & value)
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
|
|
|
monsterTypes = value;
|
|
|
|
}
|
|
|
|
|
2024-08-24 20:18:36 +02:00
|
|
|
std::set<FactionID> ZoneOptions::getMonsterTypes() const
|
2022-08-09 07:54:32 +02:00
|
|
|
{
|
2023-07-06 17:30:23 +02:00
|
|
|
return vstd::difference(monsterTypes, bannedMonsters);
|
2022-08-09 07:54:32 +02:00
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void ZoneOptions::setMinesInfo(const std::map<TResource, ui16> & value)
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
mines = value;
|
2018-03-05 16:05:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::map<TResource, ui16> ZoneOptions::getMinesInfo() const
|
|
|
|
{
|
|
|
|
return mines;
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void ZoneOptions::setTreasureInfo(const std::vector<CTreasureInfo> & value)
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
treasureInfo = value;
|
2023-03-28 17:13:24 +02:00
|
|
|
recalculateMaxTreasureValue();
|
|
|
|
}
|
2023-03-27 17:29:46 +02:00
|
|
|
|
2023-03-28 17:13:24 +02:00
|
|
|
void ZoneOptions::recalculateMaxTreasureValue()
|
|
|
|
{
|
2023-03-27 17:29:46 +02:00
|
|
|
maxTreasureValue = 0;
|
2023-03-28 17:13:24 +02:00
|
|
|
for (const auto& ti : treasureInfo)
|
2023-03-27 17:29:46 +02:00
|
|
|
{
|
|
|
|
vstd::amax(maxTreasureValue, ti.max);
|
|
|
|
}
|
2018-03-05 16:05:17 +02:00
|
|
|
}
|
2022-05-31 11:25:39 +02:00
|
|
|
|
|
|
|
void ZoneOptions::addTreasureInfo(const CTreasureInfo & value)
|
|
|
|
{
|
|
|
|
treasureInfo.push_back(value);
|
2023-03-27 17:29:46 +02:00
|
|
|
vstd::amax(maxTreasureValue, value.max);
|
2022-05-31 11:25:39 +02:00
|
|
|
}
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2024-08-24 20:18:36 +02:00
|
|
|
std::vector<CTreasureInfo> ZoneOptions::getTreasureInfo() const
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
|
|
|
return treasureInfo;
|
|
|
|
}
|
|
|
|
|
2023-03-27 17:29:46 +02:00
|
|
|
ui32 ZoneOptions::getMaxTreasureValue() const
|
|
|
|
{
|
|
|
|
return maxTreasureValue;
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
TRmgTemplateZoneId ZoneOptions::getMinesLikeZone() const
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
return minesLikeZone;
|
2018-03-05 16:05:17 +02:00
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
TRmgTemplateZoneId ZoneOptions::getTerrainTypeLikeZone() const
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
return terrainTypeLikeZone;
|
2018-03-05 16:05:17 +02:00
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
TRmgTemplateZoneId ZoneOptions::getTreasureLikeZone() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2024-08-24 20:18:36 +02:00
|
|
|
return treasureLikeZone;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectConfig ZoneOptions::getCustomObjects() const
|
|
|
|
{
|
|
|
|
return objectConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoneOptions::setCustomObjects(const ObjectConfig & value)
|
|
|
|
{
|
|
|
|
objectConfig = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRmgTemplateZoneId ZoneOptions::getCustomObjectsLikeZone() const
|
|
|
|
{
|
|
|
|
return customObjectsLikeZone;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2023-06-17 19:09:38 +02:00
|
|
|
void ZoneOptions::addConnection(const ZoneConnection & connection)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2023-06-17 19:09:38 +02:00
|
|
|
connectedZoneIds.push_back(connection.getOtherZoneId(getId()));
|
|
|
|
connectionDetails.push_back(connection);
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2023-06-17 19:09:38 +02:00
|
|
|
std::vector<ZoneConnection> ZoneOptions::getConnections() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2023-06-17 19:09:38 +02:00
|
|
|
return connectionDetails;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<TRmgTemplateZoneId> ZoneOptions::getConnectedZoneIds() const
|
|
|
|
{
|
|
|
|
return connectedZoneIds;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2022-08-09 07:54:32 +02:00
|
|
|
bool ZoneOptions::areTownsSameType() const
|
|
|
|
{
|
|
|
|
return townsAreSameType;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ZoneOptions::isMatchTerrainToTown() const
|
|
|
|
{
|
|
|
|
return matchTerrainToTown;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ZoneOptions::CTownInfo & ZoneOptions::getPlayerTowns() const
|
|
|
|
{
|
|
|
|
return playerTowns;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ZoneOptions::CTownInfo & ZoneOptions::getNeutralTowns() const
|
|
|
|
{
|
|
|
|
return neutralTowns;
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
static const std::vector<std::string> zoneTypes =
|
|
|
|
{
|
|
|
|
"playerStart",
|
|
|
|
"cpuStart",
|
|
|
|
"treasure",
|
2022-05-31 11:25:39 +02:00
|
|
|
"junction",
|
2024-11-23 13:19:25 +02:00
|
|
|
"water",
|
|
|
|
"sealed"
|
2018-03-09 20:11:20 +02:00
|
|
|
};
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
handler.serializeEnum("type", type, zoneTypes);
|
|
|
|
handler.serializeInt("size", size, 1);
|
|
|
|
handler.serializeInt("owner", owner);
|
|
|
|
handler.serializeStruct("playerTowns", playerTowns);
|
|
|
|
handler.serializeStruct("neutralTowns", neutralTowns);
|
|
|
|
handler.serializeBool("matchTerrainToTown", matchTerrainToTown, true);
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
#define SERIALIZE_ZONE_LINK(fieldName) handler.serializeInt(#fieldName, fieldName, NO_ZONE);
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
SERIALIZE_ZONE_LINK(minesLikeZone);
|
|
|
|
SERIALIZE_ZONE_LINK(terrainTypeLikeZone);
|
|
|
|
SERIALIZE_ZONE_LINK(treasureLikeZone);
|
2024-08-24 20:18:36 +02:00
|
|
|
SERIALIZE_ZONE_LINK(customObjectsLikeZone);
|
2024-09-14 08:41:00 +02:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
#undef SERIALIZE_ZONE_LINK
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
if(terrainTypeLikeZone == NO_ZONE)
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2023-08-18 12:38:19 +02:00
|
|
|
handler.serializeIdArray("terrainTypes", terrainTypes);
|
|
|
|
handler.serializeIdArray("bannedTerrains", bannedTerrains);
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
handler.serializeBool("townsAreSameType", townsAreSameType, false);
|
2023-08-18 12:38:19 +02:00
|
|
|
handler.serializeIdArray("allowedMonsters", monsterTypes);
|
|
|
|
handler.serializeIdArray("bannedMonsters", bannedMonsters);
|
|
|
|
handler.serializeIdArray("allowedTowns", townTypes);
|
|
|
|
handler.serializeIdArray("bannedTowns", bannedTownTypes);
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
{
|
|
|
|
//TODO: add support for std::map to serializeEnum
|
2023-05-04 21:43:31 +02:00
|
|
|
static const std::vector<std::string> zoneMonsterStrengths =
|
2018-03-09 20:11:20 +02:00
|
|
|
{
|
2023-05-03 12:07:00 +02:00
|
|
|
"none",
|
2018-03-09 20:11:20 +02:00
|
|
|
"weak",
|
|
|
|
"normal",
|
|
|
|
"strong"
|
|
|
|
};
|
|
|
|
|
2023-05-21 00:13:45 +02:00
|
|
|
int temporaryZoneMonsterStrengthIndex = monsterStrength == EMonsterStrength::ZONE_NONE ? 0 : monsterStrength - EMonsterStrength::ZONE_WEAK + 1 ; // temporary until serializeEnum starts supporting std::map
|
|
|
|
// temporaryZoneMonsterStrengthIndex = 0, 1, 2 and 3 for monsterStrength = ZONE_NONE, ZONE_WEAK, ZONE_NORMAL and ZONE_STRONG respectively
|
|
|
|
handler.serializeEnum("monsters", temporaryZoneMonsterStrengthIndex, 2, zoneMonsterStrengths); // default is normal monsters
|
|
|
|
switch (temporaryZoneMonsterStrengthIndex)
|
2018-03-09 20:11:20 +02:00
|
|
|
{
|
2023-05-21 00:13:45 +02:00
|
|
|
case 0:
|
|
|
|
monsterStrength = EMonsterStrength::ZONE_NONE;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
monsterStrength = EMonsterStrength::ZONE_WEAK;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
monsterStrength = EMonsterStrength::ZONE_NORMAL;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
monsterStrength = EMonsterStrength::ZONE_STRONG;
|
|
|
|
break;
|
2018-03-09 20:11:20 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
if(treasureLikeZone == NO_ZONE)
|
|
|
|
{
|
|
|
|
auto treasureData = handler.enterArray("treasure");
|
|
|
|
treasureData.serializeStruct(treasureInfo);
|
2023-03-27 17:29:46 +02:00
|
|
|
if (!handler.saving)
|
|
|
|
{
|
2023-03-28 17:13:24 +02:00
|
|
|
recalculateMaxTreasureValue();
|
2023-03-27 17:29:46 +02:00
|
|
|
}
|
2018-03-09 20:11:20 +02:00
|
|
|
}
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
if((minesLikeZone == NO_ZONE) && (!handler.saving || !mines.empty()))
|
|
|
|
{
|
|
|
|
auto minesData = handler.enterStruct("mines");
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
for(TResource idx = 0; idx < (GameConstants::RESOURCE_QUANTITY - 1); idx++)
|
|
|
|
{
|
|
|
|
handler.serializeInt(GameConstants::RESOURCE_NAMES[idx], mines[idx], 0);
|
|
|
|
}
|
|
|
|
}
|
2024-08-21 20:16:41 +02:00
|
|
|
|
|
|
|
handler.serializeStruct("customObjects", objectConfig);
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2023-07-06 22:15:00 +02:00
|
|
|
ZoneConnection::ZoneConnection():
|
2024-11-23 11:07:34 +02:00
|
|
|
id(-1),
|
2023-07-06 22:15:00 +02:00
|
|
|
zoneA(-1),
|
2018-03-09 20:11:20 +02:00
|
|
|
zoneB(-1),
|
2023-06-17 19:09:38 +02:00
|
|
|
guardStrength(0),
|
2023-07-07 16:32:17 +02:00
|
|
|
connectionType(rmg::EConnectionType::GUARDED),
|
|
|
|
hasRoad(rmg::ERoadOption::ROAD_TRUE)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-11-23 11:07:34 +02:00
|
|
|
int ZoneConnection::getId() const
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZoneConnection::setId(int id)
|
|
|
|
{
|
|
|
|
this->id = id;
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
TRmgTemplateZoneId ZoneConnection::getZoneA() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
return zoneA;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
TRmgTemplateZoneId ZoneConnection::getZoneB() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
return zoneB;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2023-06-17 19:09:38 +02:00
|
|
|
TRmgTemplateZoneId ZoneConnection::getOtherZoneId(TRmgTemplateZoneId id) const
|
|
|
|
{
|
|
|
|
if (id == zoneA)
|
|
|
|
{
|
|
|
|
return zoneB;
|
|
|
|
}
|
|
|
|
else if (id == zoneB)
|
|
|
|
{
|
|
|
|
return zoneA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw rmgException("Zone does not belong to this connection");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
int ZoneConnection::getGuardStrength() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
return guardStrength;
|
2022-08-09 07:54:32 +02:00
|
|
|
}
|
2023-06-17 19:09:38 +02:00
|
|
|
|
2023-07-07 16:32:17 +02:00
|
|
|
rmg::EConnectionType ZoneConnection::getConnectionType() const
|
2023-06-17 19:09:38 +02:00
|
|
|
{
|
|
|
|
return connectionType;
|
|
|
|
}
|
2023-07-06 22:15:00 +02:00
|
|
|
|
2023-07-07 16:32:17 +02:00
|
|
|
rmg::ERoadOption ZoneConnection::getRoadOption() const
|
2023-07-06 22:15:00 +02:00
|
|
|
{
|
|
|
|
return hasRoad;
|
|
|
|
}
|
2022-08-09 07:54:32 +02:00
|
|
|
|
|
|
|
bool operator==(const ZoneConnection & l, const ZoneConnection & r)
|
|
|
|
{
|
2024-11-23 11:07:34 +02:00
|
|
|
return l.id == r.id;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void ZoneConnection::serializeJson(JsonSerializeFormat & handler)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2023-06-17 19:09:38 +02:00
|
|
|
static const std::vector<std::string> connectionTypes =
|
|
|
|
{
|
|
|
|
"guarded",
|
|
|
|
"fictive",
|
|
|
|
"repulsive",
|
2024-07-29 20:36:23 +02:00
|
|
|
"wide",
|
|
|
|
"forcePortal"
|
2023-06-17 19:09:38 +02:00
|
|
|
};
|
|
|
|
|
2023-07-06 22:15:00 +02:00
|
|
|
static const std::vector<std::string> roadOptions =
|
|
|
|
{
|
|
|
|
"true",
|
|
|
|
"false",
|
|
|
|
"random"
|
|
|
|
};
|
|
|
|
|
2023-09-04 21:23:20 +02:00
|
|
|
if (handler.saving)
|
|
|
|
{
|
|
|
|
std::string zoneNameA = std::to_string(zoneA);
|
|
|
|
std::string zoneNameB = std::to_string(zoneB);
|
|
|
|
handler.serializeString("a", zoneNameA);
|
|
|
|
handler.serializeString("b", zoneNameB);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string zoneNameA;
|
|
|
|
std::string zoneNameB;
|
|
|
|
handler.serializeString("a", zoneNameA);
|
|
|
|
handler.serializeString("b", zoneNameB);
|
|
|
|
|
|
|
|
zoneA = std::stoi(zoneNameA);
|
|
|
|
zoneB = std::stoi(zoneNameB);
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
handler.serializeInt("guard", guardStrength, 0);
|
2023-06-17 19:09:38 +02:00
|
|
|
handler.serializeEnum("type", connectionType, connectionTypes);
|
2023-07-06 22:15:00 +02:00
|
|
|
handler.serializeEnum("road", hasRoad, roadOptions);
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
using namespace rmg;//todo: remove
|
|
|
|
|
2024-09-04 20:18:10 +02:00
|
|
|
CRmgTemplate::~CRmgTemplate() = default;
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
CRmgTemplate::CRmgTemplate()
|
2018-03-09 20:11:20 +02:00
|
|
|
: minSize(72, 72, 2),
|
2024-09-04 20:18:10 +02:00
|
|
|
maxSize(72, 72, 2),
|
|
|
|
mapSettings(std::make_unique<JsonNode>())
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
bool CRmgTemplate::matchesSize(const int3 & value) const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
const int64_t square = value.x * value.y * value.z;
|
|
|
|
const int64_t minSquare = minSize.x * minSize.y * minSize.z;
|
|
|
|
const int64_t maxSquare = maxSize.x * maxSize.y * maxSize.z;
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
return minSquare <= square && square <= maxSquare;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2022-05-31 11:25:39 +02:00
|
|
|
bool CRmgTemplate::isWaterContentAllowed(EWaterContent::EWaterContent waterContent) const
|
|
|
|
{
|
2023-05-20 13:29:55 +02:00
|
|
|
return waterContent == EWaterContent::RANDOM || allowedWaterContent.count(waterContent);
|
2022-05-31 11:25:39 +02:00
|
|
|
}
|
|
|
|
|
2022-06-05 08:02:58 +02:00
|
|
|
const std::set<EWaterContent::EWaterContent> & CRmgTemplate::getWaterContentAllowed() const
|
|
|
|
{
|
|
|
|
return allowedWaterContent;
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void CRmgTemplate::setId(const std::string & value)
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2018-03-09 20:11:20 +02:00
|
|
|
id = value;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2022-12-14 02:37:11 +02:00
|
|
|
void CRmgTemplate::setName(const std::string & value)
|
|
|
|
{
|
|
|
|
name = value;
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
const std::string & CRmgTemplate::getName() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2022-12-14 02:37:11 +02:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2024-02-03 17:23:56 +02:00
|
|
|
const std::string & CRmgTemplate::getDescription() const
|
|
|
|
{
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
2022-12-14 02:37:11 +02:00
|
|
|
const std::string & CRmgTemplate::getId() const
|
|
|
|
{
|
|
|
|
return id;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const CRmgTemplate::CPlayerCountRange & CRmgTemplate::getPlayers() const
|
|
|
|
{
|
|
|
|
return players;
|
|
|
|
}
|
|
|
|
|
2023-10-29 22:25:39 +02:00
|
|
|
const CRmgTemplate::CPlayerCountRange & CRmgTemplate::getHumanPlayers() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2023-10-29 22:25:39 +02:00
|
|
|
return humanPlayers;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
const CRmgTemplate::Zones & CRmgTemplate::getZones() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
return zones;
|
|
|
|
}
|
|
|
|
|
2023-06-17 19:09:38 +02:00
|
|
|
const std::vector<ZoneConnection> & CRmgTemplate::getConnectedZoneIds() const
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
2024-11-23 11:07:34 +02:00
|
|
|
return connections;
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRmgTemplate::validate() const
|
|
|
|
{
|
|
|
|
//TODO add some validation checks, throw on failure
|
|
|
|
}
|
|
|
|
|
2022-12-14 02:37:11 +02:00
|
|
|
std::pair<int3, int3> CRmgTemplate::getMapSizes() const
|
|
|
|
{
|
|
|
|
return {minSize, maxSize};
|
|
|
|
}
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
void CRmgTemplate::CPlayerCountRange::addRange(int lower, int upper)
|
|
|
|
{
|
2023-02-11 18:05:02 +02:00
|
|
|
range.emplace_back(lower, upper);
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRmgTemplate::CPlayerCountRange::addNumber(int value)
|
|
|
|
{
|
2023-02-11 18:05:02 +02:00
|
|
|
range.emplace_back(value, value);
|
2013-08-17 15:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CRmgTemplate::CPlayerCountRange::isInRange(int count) const
|
|
|
|
{
|
|
|
|
for(const auto & pair : range)
|
|
|
|
{
|
|
|
|
if(count >= pair.first && count <= pair.second) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<int> CRmgTemplate::CPlayerCountRange::getNumbers() const
|
|
|
|
{
|
|
|
|
std::set<int> numbers;
|
|
|
|
for(const auto & pair : range)
|
|
|
|
{
|
|
|
|
for(int i = pair.first; i <= pair.second; ++i) numbers.insert(i);
|
|
|
|
}
|
|
|
|
return numbers;
|
|
|
|
}
|
2018-03-09 20:11:20 +02:00
|
|
|
|
|
|
|
std::string CRmgTemplate::CPlayerCountRange::toString() const
|
|
|
|
{
|
|
|
|
if(range.size() == 1)
|
|
|
|
{
|
|
|
|
const auto & p = range.front();
|
|
|
|
if((p.first == p.second) && (p.first == 0))
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
|
2023-02-11 18:05:02 +02:00
|
|
|
for(const auto & p : range)
|
2018-03-09 20:11:20 +02:00
|
|
|
{
|
|
|
|
if(!first)
|
|
|
|
ret +=",";
|
|
|
|
else
|
|
|
|
first = false;
|
|
|
|
|
|
|
|
if(p.first == p.second)
|
|
|
|
{
|
2023-02-11 18:05:02 +02:00
|
|
|
ret += std::to_string(p.first);
|
2018-03-09 20:11:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-20 22:45:41 +02:00
|
|
|
ret += boost::str(boost::format("%d-%d") % p.first % p.second);
|
2018-03-09 20:11:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRmgTemplate::CPlayerCountRange::fromString(const std::string & value)
|
|
|
|
{
|
|
|
|
range.clear();
|
|
|
|
|
|
|
|
if(value.empty())
|
|
|
|
{
|
|
|
|
addNumber(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<std::string> commaParts;
|
|
|
|
boost::split(commaParts, value, boost::is_any_of(","));
|
|
|
|
for(const auto & commaPart : commaParts)
|
|
|
|
{
|
|
|
|
std::vector<std::string> rangeParts;
|
|
|
|
boost::split(rangeParts, commaPart, boost::is_any_of("-"));
|
|
|
|
if(rangeParts.size() == 2)
|
|
|
|
{
|
|
|
|
auto lower = boost::lexical_cast<int>(rangeParts[0]);
|
|
|
|
auto upper = boost::lexical_cast<int>(rangeParts[1]);
|
|
|
|
addRange(lower, upper);
|
|
|
|
}
|
|
|
|
else if(rangeParts.size() == 1)
|
|
|
|
{
|
|
|
|
auto val = boost::lexical_cast<int>(rangeParts.front());
|
|
|
|
addNumber(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-29 22:25:39 +02:00
|
|
|
int CRmgTemplate::CPlayerCountRange::maxValue() const
|
|
|
|
{
|
|
|
|
return *boost::max_element(getNumbers());
|
|
|
|
}
|
|
|
|
|
|
|
|
int CRmgTemplate::CPlayerCountRange::minValue() const
|
|
|
|
{
|
|
|
|
return *boost::min_element(getNumbers());
|
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void CRmgTemplate::serializeJson(JsonSerializeFormat & handler)
|
|
|
|
{
|
|
|
|
handler.serializeString("name", name);
|
2024-02-03 17:23:56 +02:00
|
|
|
handler.serializeString("description", description);
|
2018-03-09 20:11:20 +02:00
|
|
|
serializeSize(handler, minSize, "minSize");
|
|
|
|
serializeSize(handler, maxSize, "maxSize");
|
|
|
|
serializePlayers(handler, players, "players");
|
2023-10-30 18:21:03 +02:00
|
|
|
serializePlayers(handler, humanPlayers, "humans"); // TODO: Rename this parameter
|
2018-03-09 20:11:20 +02:00
|
|
|
|
2024-09-04 20:18:10 +02:00
|
|
|
*mapSettings = handler.getCurrent()["settings"];
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
{
|
|
|
|
auto connectionsData = handler.enterArray("connections");
|
2024-11-23 11:07:34 +02:00
|
|
|
connectionsData.serializeStruct(connections);
|
|
|
|
if(!handler.saving)
|
|
|
|
{
|
|
|
|
for(size_t i = 0; i < connections.size(); ++i)
|
|
|
|
{
|
|
|
|
connections[i].setId(i);
|
|
|
|
}
|
|
|
|
}
|
2018-03-09 20:11:20 +02:00
|
|
|
}
|
2022-06-05 08:02:58 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
boost::bimap<EWaterContent::EWaterContent, std::string> enc;
|
|
|
|
enc.insert({EWaterContent::NONE, "none"});
|
|
|
|
enc.insert({EWaterContent::NORMAL, "normal"});
|
|
|
|
enc.insert({EWaterContent::ISLANDS, "islands"});
|
|
|
|
JsonNode node;
|
|
|
|
if(handler.saving)
|
|
|
|
{
|
|
|
|
node.setType(JsonNode::JsonType::DATA_VECTOR);
|
|
|
|
for(auto wc : allowedWaterContent)
|
|
|
|
{
|
|
|
|
JsonNode n;
|
|
|
|
n.String() = enc.left.at(wc);
|
|
|
|
node.Vector().push_back(n);
|
|
|
|
}
|
|
|
|
}
|
2023-04-16 19:42:56 +02:00
|
|
|
handler.serializeRaw("allowedWaterContent", node, std::nullopt);
|
2022-06-05 08:02:58 +02:00
|
|
|
if(!handler.saving)
|
|
|
|
{
|
|
|
|
for(auto wc : node.Vector())
|
|
|
|
{
|
|
|
|
allowedWaterContent.insert(enc.right.at(std::string(wc.String())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-03-09 20:11:20 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
auto zonesData = handler.enterStruct("zones");
|
2023-02-11 18:05:02 +02:00
|
|
|
if(handler.saving)
|
2018-03-09 20:11:20 +02:00
|
|
|
{
|
|
|
|
for(auto & idAndZone : zones)
|
|
|
|
{
|
|
|
|
auto guard = handler.enterStruct(encodeZoneId(idAndZone.first));
|
|
|
|
idAndZone.second->serializeJson(handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-11 18:05:02 +02:00
|
|
|
for(const auto & idAndZone : zonesData->getCurrent().Struct())
|
2018-03-09 20:11:20 +02:00
|
|
|
{
|
|
|
|
auto guard = handler.enterStruct(idAndZone.first);
|
|
|
|
auto zone = std::make_shared<ZoneOptions>();
|
|
|
|
zone->setId(decodeZoneId(idAndZone.first));
|
|
|
|
zone->serializeJson(handler);
|
|
|
|
zones[zone->getId()] = zone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 20:18:10 +02:00
|
|
|
const JsonNode & CRmgTemplate::getMapSettings() const
|
|
|
|
{
|
|
|
|
return *mapSettings;
|
|
|
|
}
|
|
|
|
|
2024-08-24 20:18:36 +02:00
|
|
|
template<typename T>
|
|
|
|
T CRmgTemplate::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)
|
2023-03-19 10:27:05 +02:00
|
|
|
{
|
|
|
|
if (iteration >= 50)
|
|
|
|
{
|
2024-08-24 20:18:36 +02:00
|
|
|
logGlobal->error("Infinite recursion for %s detected in template %s", propertyString, name);
|
|
|
|
return T();
|
2023-03-19 10:27:05 +02:00
|
|
|
}
|
2024-08-24 20:18:36 +02:00
|
|
|
|
|
|
|
if (((*zone).*inheritFrom)() != rmg::ZoneOptions::NO_ZONE)
|
2023-03-19 10:27:05 +02:00
|
|
|
{
|
|
|
|
iteration++;
|
2024-08-24 20:18:36 +02:00
|
|
|
const auto otherZone = zones.at(((*zone).*inheritFrom)());
|
|
|
|
T inheritedValue = inheritZoneProperty(otherZone, getter, setter, inheritFrom, propertyString, iteration);
|
|
|
|
((*zone).*setter)(inheritedValue);
|
2023-03-19 10:27:05 +02:00
|
|
|
}
|
2024-08-24 20:18:36 +02:00
|
|
|
|
|
|
|
return ((*zone).*getter)();
|
2023-03-19 10:27:05 +02:00
|
|
|
}
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void CRmgTemplate::afterLoad()
|
|
|
|
{
|
|
|
|
for(auto & idAndZone : zones)
|
|
|
|
{
|
|
|
|
auto zone = idAndZone.second;
|
|
|
|
|
2024-08-24 20:18:36 +02:00
|
|
|
// Inherit properties recursively
|
|
|
|
inheritZoneProperty(zone,
|
|
|
|
&rmg::ZoneOptions::getTerrainTypes,
|
|
|
|
&rmg::ZoneOptions::setTerrainTypes,
|
|
|
|
&rmg::ZoneOptions::getTerrainTypeLikeZone,
|
|
|
|
"terrain types");
|
|
|
|
|
|
|
|
inheritZoneProperty(zone,
|
|
|
|
&rmg::ZoneOptions::getMinesInfo,
|
|
|
|
&rmg::ZoneOptions::setMinesInfo,
|
|
|
|
&rmg::ZoneOptions::getMinesLikeZone,
|
|
|
|
"mine types");
|
|
|
|
|
|
|
|
inheritZoneProperty(zone,
|
|
|
|
&rmg::ZoneOptions::getTreasureInfo,
|
|
|
|
&rmg::ZoneOptions::setTreasureInfo,
|
|
|
|
&rmg::ZoneOptions::getTreasureLikeZone,
|
|
|
|
"treasure info");
|
|
|
|
|
|
|
|
inheritZoneProperty(zone,
|
|
|
|
&rmg::ZoneOptions::getCustomObjects,
|
|
|
|
&rmg::ZoneOptions::setCustomObjects,
|
|
|
|
&rmg::ZoneOptions::getCustomObjectsLikeZone,
|
|
|
|
"custom objects");
|
|
|
|
|
|
|
|
//TODO: Inherit monster types as well
|
2023-07-01 15:25:20 +02:00
|
|
|
auto monsterTypes = zone->getMonsterTypes();
|
|
|
|
if (monsterTypes.empty())
|
|
|
|
{
|
|
|
|
zone->setMonsterTypes(VLC->townh->getAllowedFactions(false));
|
|
|
|
}
|
2018-03-09 20:11:20 +02:00
|
|
|
}
|
|
|
|
|
2024-11-23 11:07:34 +02:00
|
|
|
for(const auto & connection : connections)
|
2018-03-09 20:11:20 +02:00
|
|
|
{
|
|
|
|
auto id1 = connection.getZoneA();
|
|
|
|
auto id2 = connection.getZoneB();
|
|
|
|
|
|
|
|
auto zone1 = zones.at(id1);
|
|
|
|
auto zone2 = zones.at(id2);
|
|
|
|
|
2023-06-17 19:09:38 +02:00
|
|
|
zone1->addConnection(connection);
|
|
|
|
zone2->addConnection(connection);
|
2018-03-09 20:11:20 +02:00
|
|
|
}
|
2022-05-31 11:25:39 +02:00
|
|
|
|
2023-05-20 13:29:55 +02:00
|
|
|
if(allowedWaterContent.empty() || allowedWaterContent.count(EWaterContent::RANDOM))
|
2022-05-31 11:25:39 +02:00
|
|
|
{
|
2023-05-20 13:29:55 +02:00
|
|
|
allowedWaterContent.insert(EWaterContent::NONE);
|
|
|
|
allowedWaterContent.insert(EWaterContent::NORMAL);
|
|
|
|
allowedWaterContent.insert(EWaterContent::ISLANDS);
|
2022-05-31 11:25:39 +02:00
|
|
|
}
|
2023-05-20 13:29:55 +02:00
|
|
|
allowedWaterContent.erase(EWaterContent::RANDOM);
|
2018-03-09 20:11:20 +02:00
|
|
|
}
|
|
|
|
|
2024-08-21 20:16:41 +02:00
|
|
|
// TODO: Allow any integer size which does not match enum, as well
|
2018-03-09 20:11:20 +02:00
|
|
|
void CRmgTemplate::serializeSize(JsonSerializeFormat & handler, int3 & value, const std::string & fieldName)
|
|
|
|
{
|
|
|
|
static const std::map<std::string, int3> sizeMapping =
|
|
|
|
{
|
2024-02-29 13:45:08 +02:00
|
|
|
{"s", {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_SMALL, 1}},
|
|
|
|
{"s+u", {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_SMALL, 2}},
|
|
|
|
{"m", {CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_MIDDLE, 1}},
|
|
|
|
{"m+u", {CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_MIDDLE, 2}},
|
|
|
|
{"l", {CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_LARGE, 1}},
|
|
|
|
{"l+u", {CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_LARGE, 2}},
|
|
|
|
{"xl", {CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_XLARGE, 1}} ,
|
|
|
|
{"xl+u", {CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_XLARGE, 2}} ,
|
|
|
|
{"h", {CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_HUGE, 1}},
|
|
|
|
{"h+u", {CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_HUGE, 2}},
|
|
|
|
{"xh", {CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_XHUGE, 1}},
|
|
|
|
{"xh+u", {CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_XHUGE, 2}},
|
|
|
|
{"g", {CMapHeader::MAP_SIZE_GIANT, CMapHeader::MAP_SIZE_GIANT, 1}},
|
|
|
|
{"g+u", {CMapHeader::MAP_SIZE_GIANT, CMapHeader::MAP_SIZE_GIANT, 2}}
|
2018-03-09 20:11:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const std::map<int3, std::string> sizeReverseMapping = vstd::invertMap(sizeMapping);
|
|
|
|
|
|
|
|
std::string encodedValue;
|
|
|
|
|
|
|
|
if(handler.saving)
|
|
|
|
{
|
|
|
|
auto iter = sizeReverseMapping.find(value);
|
|
|
|
if(iter == sizeReverseMapping.end())
|
|
|
|
encodedValue = boost::str(boost::format("%dx%dx%d") % value.x % value.y % value.z);
|
|
|
|
else
|
|
|
|
encodedValue = iter->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
handler.serializeString(fieldName, encodedValue);
|
|
|
|
|
|
|
|
if(!handler.saving)
|
|
|
|
{
|
|
|
|
auto iter = sizeMapping.find(encodedValue);
|
|
|
|
|
|
|
|
if(iter == sizeMapping.end())
|
|
|
|
{
|
|
|
|
std::vector<std::string> parts;
|
|
|
|
boost::split(parts, encodedValue, boost::is_any_of("x"));
|
|
|
|
|
|
|
|
value.x = (boost::lexical_cast<int>(parts.at(0)));
|
|
|
|
value.y = (boost::lexical_cast<int>(parts.at(1)));
|
|
|
|
value.z = (boost::lexical_cast<int>(parts.at(2)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = iter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRmgTemplate::serializePlayers(JsonSerializeFormat & handler, CPlayerCountRange & value, const std::string & fieldName)
|
|
|
|
{
|
|
|
|
std::string encodedValue;
|
|
|
|
|
|
|
|
if(handler.saving)
|
|
|
|
encodedValue = value.toString();
|
|
|
|
|
|
|
|
handler.serializeString(fieldName, encodedValue);
|
|
|
|
|
|
|
|
if(!handler.saving)
|
|
|
|
value.fromString(encodedValue);
|
|
|
|
}
|
|
|
|
|
2024-08-21 20:16:41 +02:00
|
|
|
const std::vector<CompoundMapObjectID> & ZoneOptions::getBannedObjects() const
|
|
|
|
{
|
|
|
|
return objectConfig.getBannedObjects();
|
|
|
|
}
|
|
|
|
|
2024-08-24 15:12:22 +02:00
|
|
|
const std::vector<ObjectConfig::EObjectCategory> & ZoneOptions::getBannedObjectCategories() const
|
2024-08-21 20:16:41 +02:00
|
|
|
{
|
2024-08-24 15:12:22 +02:00
|
|
|
return objectConfig.getBannedObjectCategories();
|
2024-08-21 20:16:41 +02:00
|
|
|
}
|
|
|
|
|
2024-08-24 20:18:36 +02:00
|
|
|
const std::vector<ObjectInfo> & ZoneOptions::getConfiguredObjects() const
|
2024-08-21 20:16:41 +02:00
|
|
|
{
|
2024-08-24 20:18:36 +02:00
|
|
|
return objectConfig.getConfiguredObjects();
|
2024-08-21 20:16:41 +02:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|