2013-08-17 15:46:48 +03:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
#include "../int3.h"
|
2013-08-17 15:46:48 +03:00
|
|
|
#include "../GameConstants.h"
|
2018-03-05 16:05:17 +02:00
|
|
|
#include "../ResourceSet.h"
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
class JsonSerializeFormat;
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2023-05-20 13:29:55 +02:00
|
|
|
enum class ETemplateZoneType
|
2018-03-05 16:05:17 +02:00
|
|
|
{
|
2023-05-20 13:29:55 +02:00
|
|
|
PLAYER_START,
|
|
|
|
CPU_START,
|
|
|
|
TREASURE,
|
|
|
|
JUNCTION,
|
|
|
|
WATER
|
|
|
|
};
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2023-05-20 13:29:55 +02:00
|
|
|
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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-05-20 17:28:25 +02:00
|
|
|
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
|
|
|
|
{
|
2023-05-20 17:28:25 +02:00
|
|
|
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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
class DLL_LINKAGE CTreasureInfo
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
public:
|
2018-03-05 16:05:17 +02:00
|
|
|
ui32 min;
|
|
|
|
ui32 max;
|
|
|
|
ui16 density;
|
2018-03-09 20:11:20 +02:00
|
|
|
CTreasureInfo();
|
2022-05-31 11:25:39 +02:00
|
|
|
CTreasureInfo(ui32 min, ui32 max, ui16 density);
|
2018-03-09 20:11:20 +02:00
|
|
|
|
|
|
|
bool operator ==(const CTreasureInfo & other) const;
|
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
2018-03-05 16:05:17 +02:00
|
|
|
};
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2023-06-17 19:09:38 +02:00
|
|
|
namespace EConnectionType
|
|
|
|
{
|
|
|
|
enum class EConnectionType
|
|
|
|
{
|
|
|
|
GUARDED = 0, //default
|
|
|
|
FICTIVE,
|
|
|
|
REPULSIVE,
|
|
|
|
WIDE
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
namespace rmg
|
|
|
|
{
|
|
|
|
|
|
|
|
class DLL_LINKAGE ZoneConnection
|
|
|
|
{
|
|
|
|
public:
|
2023-06-17 19:09:38 +02:00
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
ZoneConnection();
|
|
|
|
|
|
|
|
TRmgTemplateZoneId getZoneA() const;
|
|
|
|
TRmgTemplateZoneId getZoneB() const;
|
2023-06-17 19:09:38 +02:00
|
|
|
TRmgTemplateZoneId getOtherZoneId(TRmgTemplateZoneId id) const;
|
2018-03-09 20:11:20 +02:00
|
|
|
int getGuardStrength() const;
|
2023-06-17 19:09:38 +02:00
|
|
|
EConnectionType::EConnectionType getConnectionType() const;
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
2022-08-09 07:54:32 +02:00
|
|
|
|
|
|
|
friend bool operator==(const ZoneConnection &, const ZoneConnection &);
|
2013-08-17 15:46:48 +03:00
|
|
|
private:
|
2018-03-05 16:05:17 +02:00
|
|
|
TRmgTemplateZoneId zoneA;
|
|
|
|
TRmgTemplateZoneId zoneB;
|
2013-08-17 15:46:48 +03:00
|
|
|
int guardStrength;
|
2023-06-17 19:09:38 +02:00
|
|
|
EConnectionType::EConnectionType connectionType;
|
2013-08-17 15:46:48 +03:00
|
|
|
};
|
|
|
|
|
2018-03-05 16:05:17 +02:00
|
|
|
class DLL_LINKAGE ZoneOptions
|
|
|
|
{
|
|
|
|
public:
|
2018-03-09 20:11:20 +02:00
|
|
|
static const TRmgTemplateZoneId NO_ZONE;
|
2018-03-05 16:05:17 +02:00
|
|
|
|
|
|
|
class DLL_LINKAGE CTownInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTownInfo();
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
int getTownCount() const;
|
|
|
|
int getCastleCount() const;
|
|
|
|
int getTownDensity() const;
|
|
|
|
int getCastleDensity() const;
|
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
2018-03-05 16:05:17 +02:00
|
|
|
|
|
|
|
private:
|
2018-03-09 20:11:20 +02:00
|
|
|
int townCount;
|
|
|
|
int castleCount;
|
|
|
|
int townDensity;
|
|
|
|
int castleDensity;
|
2018-03-05 16:05:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ZoneOptions();
|
|
|
|
|
|
|
|
TRmgTemplateZoneId getId() const;
|
|
|
|
void setId(TRmgTemplateZoneId value);
|
|
|
|
|
2023-05-20 13:29:55 +02:00
|
|
|
ETemplateZoneType getType() const;
|
|
|
|
void setType(ETemplateZoneType value);
|
2022-05-31 11:25:39 +02:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
int getSize() const;
|
2018-03-05 16:05:17 +02:00
|
|
|
void setSize(int value);
|
2023-04-16 19:42:56 +02:00
|
|
|
std::optional<int> getOwner() const;
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2022-09-29 11:44:46 +02:00
|
|
|
const std::set<TerrainId> & getTerrainTypes() const;
|
|
|
|
void setTerrainTypes(const std::set<TerrainId> & value);
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2022-08-09 07:54:32 +02:00
|
|
|
const CTownInfo & getPlayerTowns() const;
|
|
|
|
const CTownInfo & getNeutralTowns() const;
|
2023-04-09 17:26:32 +02:00
|
|
|
std::set<FactionID> getDefaultTownTypes() const;
|
|
|
|
const std::set<FactionID> & getTownTypes() const;
|
|
|
|
const std::set<FactionID> & getMonsterTypes() const;
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2023-04-09 17:26:32 +02:00
|
|
|
void setTownTypes(const std::set<FactionID> & value);
|
|
|
|
void setMonsterTypes(const std::set<FactionID> & value);
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void setMinesInfo(const std::map<TResource, ui16> & value);
|
2018-03-05 16:05:17 +02:00
|
|
|
std::map<TResource, ui16> getMinesInfo() const;
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void setTreasureInfo(const std::vector<CTreasureInfo> & value);
|
2022-05-31 11:25:39 +02:00
|
|
|
void addTreasureInfo(const CTreasureInfo & value);
|
2018-03-05 16:05:17 +02:00
|
|
|
const std::vector<CTreasureInfo> & getTreasureInfo() const;
|
2023-03-27 17:29:46 +02:00
|
|
|
ui32 getMaxTreasureValue() const;
|
2023-03-28 17:13:24 +02:00
|
|
|
void recalculateMaxTreasureValue();
|
2018-03-05 16:05:17 +02:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
TRmgTemplateZoneId getMinesLikeZone() const;
|
|
|
|
TRmgTemplateZoneId getTerrainTypeLikeZone() const;
|
|
|
|
TRmgTemplateZoneId getTreasureLikeZone() const;
|
|
|
|
|
2023-06-17 19:09:38 +02:00
|
|
|
void addConnection(const ZoneConnection & connection);
|
|
|
|
std::vector<ZoneConnection> getConnections() const;
|
|
|
|
std::vector<TRmgTemplateZoneId> getConnectedZoneIds() const;
|
2018-03-09 20:11:20 +02:00
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
2022-08-09 07:54:32 +02:00
|
|
|
|
2023-05-21 00:13:45 +02:00
|
|
|
EMonsterStrength::EMonsterStrength monsterStrength;
|
2022-08-09 07:54:32 +02:00
|
|
|
|
|
|
|
bool areTownsSameType() const;
|
|
|
|
bool isMatchTerrainToTown() const;
|
2018-03-05 16:05:17 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
TRmgTemplateZoneId id;
|
2023-05-20 13:29:55 +02:00
|
|
|
ETemplateZoneType type;
|
2018-03-05 16:05:17 +02:00
|
|
|
int size;
|
2023-03-27 17:29:46 +02:00
|
|
|
ui32 maxTreasureValue;
|
2023-04-16 19:42:56 +02:00
|
|
|
std::optional<int> owner;
|
2018-03-05 16:05:17 +02:00
|
|
|
CTownInfo playerTowns;
|
|
|
|
CTownInfo neutralTowns;
|
|
|
|
bool matchTerrainToTown;
|
2022-09-29 11:44:46 +02:00
|
|
|
std::set<TerrainId> terrainTypes;
|
2018-03-05 16:05:17 +02:00
|
|
|
bool townsAreSameType;
|
|
|
|
|
2023-04-09 17:26:32 +02:00
|
|
|
std::set<FactionID> townTypes;
|
|
|
|
std::set<FactionID> monsterTypes;
|
2018-03-05 16:05:17 +02:00
|
|
|
|
|
|
|
std::map<TResource, ui16> mines; //obligatory mines to spawn in this zone
|
|
|
|
|
|
|
|
std::vector<CTreasureInfo> treasureInfo;
|
|
|
|
|
2023-06-17 19:09:38 +02:00
|
|
|
std::vector<TRmgTemplateZoneId> connectedZoneIds; //list of adjacent zone ids
|
|
|
|
std::vector<ZoneConnection> connectionDetails; //list of connections linked to that zone
|
2018-03-09 20:11:20 +02:00
|
|
|
|
|
|
|
TRmgTemplateZoneId minesLikeZone;
|
|
|
|
TRmgTemplateZoneId terrainTypeLikeZone;
|
|
|
|
TRmgTemplateZoneId treasureLikeZone;
|
2018-03-05 16:05:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
/// The CRmgTemplate describes a random map template.
|
|
|
|
class DLL_LINKAGE CRmgTemplate
|
|
|
|
{
|
|
|
|
public:
|
2018-03-09 20:11:20 +02:00
|
|
|
using Zones = std::map<TRmgTemplateZoneId, std::shared_ptr<rmg::ZoneOptions>>;
|
2013-08-17 15:46:48 +03:00
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
class DLL_LINKAGE CPlayerCountRange
|
2013-08-17 15:46:48 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void addRange(int lower, int upper);
|
|
|
|
void addNumber(int value);
|
|
|
|
bool isInRange(int count) const;
|
|
|
|
std::set<int> getNumbers() const;
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
std::string toString() const;
|
|
|
|
void fromString(const std::string & value);
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
private:
|
2018-03-09 20:11:20 +02:00
|
|
|
std::vector<std::pair<int, int> > range;
|
2013-08-17 15:46:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
CRmgTemplate();
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
bool matchesSize(const int3 & value) const;
|
2022-05-31 11:25:39 +02:00
|
|
|
bool isWaterContentAllowed(EWaterContent::EWaterContent waterContent) const;
|
2022-06-05 08:02:58 +02:00
|
|
|
const std::set<EWaterContent::EWaterContent> & getWaterContentAllowed() const;
|
2018-03-09 20:11:20 +02:00
|
|
|
|
|
|
|
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;
|
2013-08-17 15:46:48 +03:00
|
|
|
const std::string & getName() const;
|
2018-03-09 20:11:20 +02:00
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
const CPlayerCountRange & getPlayers() const;
|
|
|
|
const CPlayerCountRange & getCpuPlayers() const;
|
2022-12-14 02:37:11 +02:00
|
|
|
std::pair<int3, int3> getMapSizes() const;
|
2018-03-09 20:11:20 +02:00
|
|
|
const Zones & getZones() const;
|
2023-06-17 19:09:38 +02:00
|
|
|
const std::vector<rmg::ZoneConnection> & getConnectedZoneIds() const;
|
2013-08-17 15:46:48 +03:00
|
|
|
|
|
|
|
void validate() const; /// Tests template on validity and throws exception on failure
|
|
|
|
|
2018-03-09 20:11:20 +02:00
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
|
|
|
|
2013-08-17 15:46:48 +03:00
|
|
|
private:
|
2018-03-09 20:11:20 +02:00
|
|
|
std::string id;
|
2013-08-17 15:46:48 +03:00
|
|
|
std::string name;
|
2018-03-09 20:11:20 +02:00
|
|
|
int3 minSize, maxSize;
|
2013-08-17 15:46:48 +03:00
|
|
|
CPlayerCountRange players, cpuPlayers;
|
2018-03-09 20:11:20 +02:00
|
|
|
Zones zones;
|
2023-06-17 19:09:38 +02:00
|
|
|
std::vector<rmg::ZoneConnection> connectedZoneIds;
|
2022-05-31 11:25:39 +02:00
|
|
|
std::set<EWaterContent::EWaterContent> allowedWaterContent;
|
2018-03-09 20:11:20 +02:00
|
|
|
|
|
|
|
void afterLoad();
|
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);
|
2018-03-09 20:11:20 +02:00
|
|
|
void serializeSize(JsonSerializeFormat & handler, int3 & value, const std::string & fieldName);
|
|
|
|
void serializePlayers(JsonSerializeFormat & handler, CPlayerCountRange & value, const std::string & fieldName);
|
2013-08-17 15:46:48 +03:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|