8 #include "../Noise/Noise.h"
28 static bool ParseRange(
const AString & a_Params,
int & a_Min,
int & a_Range,
bool a_LogWarnings)
31 if (params.size() == 0)
39 CONDWARNING(a_LogWarnings,
"Cannot parse minimum height from string \"%s\"!", params[0].c_str());
42 if (params.size() == 1)
47 int maxHeight = a_Min;
50 CONDWARNING(a_LogWarnings,
"Cannot parse maximum height from string \"%s\"!", params[1].c_str());
53 if (maxHeight < a_Min)
55 std::swap(maxHeight, a_Min);
57 a_Range = maxHeight - a_Min + 1;
89 CONDWARNING(a_LogWarnings,
"Cannot parse the fixed height from string \"%s\"!", a_Params.c_str());
130 if (params.size() != 2)
132 CONDWARNING(a_LogWarnings,
"Cannot parse the range parameters from string \"%s\"!", a_Params.c_str());
138 CONDWARNING(a_LogWarnings,
"Cannot parse the minimum or maximum height from string \"%s\"!", a_Params.c_str());
143 std::swap(
m_Min, Max);
237 terrainHeight = std::max(1 + terrainHeight,
m_SeaLevel);
240 return terrainHeight + rel;
287 auto idxPipe = a_StrategyDesc.find(
'|');
288 if (idxPipe == AString::npos)
290 idxPipe = a_StrategyDesc.length();
292 AString StrategyClass = a_StrategyDesc.substr(0, idxPipe);
298 Strategy = std::make_shared<cVerticalStrategyFixed>();
302 Strategy = std::make_shared<cVerticalStrategyRange>();
306 Strategy = std::make_shared<cVerticalStrategyTerrainTop>();
308 else if (
NoCaseCompare(StrategyClass,
"TerrainOrOceanTop") == 0)
310 Strategy = std::make_shared<cVerticalStrategyTerrainOrOceanTop>();
319 if (idxPipe < a_StrategyDesc.length())
321 Params = a_StrategyDesc.substr(idxPipe + 1);
323 if (!Strategy->InitializeFromString(Params, a_LogWarnings))
cPiece::cVerticalStrategyPtr CreateVerticalStrategyFromString(const AString &a_StrategyDesc, bool a_LogWarnings)
Returns a new cPiece::cVerticalStrategy descendant based on the specified description.
static const int SEED_OFFSET
#define CONDWARNING(ShouldLog,...)
AStringVector StringSplitAndTrim(const AString &str, const AString &delim)
Split the string at any of the listed delimiters and trim each value.
int NoCaseCompare(const AString &s1, const AString &s2)
Case-insensitive string comparison.
bool StringToInteger(const AString &a_str, T &a_Num)
Parses any integer type.
Parses a string containing a range in which both values are optional ("<MinHeight>|<MaxHeight>") into...
static bool ParseRange(const AString &a_Params, int &a_Min, int &a_Range, bool a_LogWarnings)
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
The interface that a biome generator must implement A biome generator takes chunk coords on input and...
The interface that is used to query terrain height from the shape generator.
virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap &a_HeightMap)=0
Retrieves the heightmap for the specified chunk.
std::shared_ptr< cVerticalStrategy > cVerticalStrategyPtr
Base class (interface) for strategies for placing the starting pieces vertically.
A vertical strategy that places the piece at a predefined height.
cVerticalStrategyFixed(void)
virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) override
Returns the Y coord of the piece.
int m_Height
Height at which the pieces are placed.
virtual bool InitializeFromString(const AString &a_Params, bool a_LogWarnings) override
Initializes the strategy's parameters from the string representation.
A vertical strategy that places the piece in a random height between two heights.
cVerticalStrategyRange(void)
virtual bool InitializeFromString(const AString &a_Params, bool a_LogWarnings) override
Initializes the strategy's parameters from the string representation.
virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) override
Returns the Y coord of the piece.
virtual void AssignGens(int a_Seed, cBiomeGen &a_BiomeGen, cTerrainHeightGen &a_TerrainHeightGen, int a_SeaLevel) override
Called when the piece pool is assigned to a generator, so that the strategies may bind to the underly...
int m_Min
Range for the random generator.
int m_Seed
Seed for the random generator.
A vertical strategy that places the piece in a specified range relative to the top of the terrain.
virtual bool InitializeFromString(const AString &a_Params, bool a_LogWarnings) override
Initializes the strategy's parameters from the string representation.
int m_Seed
Seed for the random generator.
cTerrainHeightGen * m_HeightGen
Height generator from which the top of the terrain is read.
virtual void AssignGens(int a_Seed, cBiomeGen &a_BiomeGen, cTerrainHeightGen &a_HeightGen, int a_SeaLevel) override
Called when the piece pool is assigned to a generator, so that the strategies may bind to the underly...
int m_MinRelHeight
Minimum relative height at which the prefab is placed.
virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) override
Returns the Y coord of the piece.
int m_RelHeightRange
Range of the relative heights at which the prefab can be placed above the minimum.
A vertical strategy that places the piece within a range on top of the terrain or ocean,...
int m_RelHeightRange
Range of the relative heights at which the prefab can be placed above the minimum.
cTerrainHeightGen * m_HeightGen
Height generator from which the top of the terrain is read.
virtual void AssignGens(int a_Seed, cBiomeGen &a_BiomeGen, cTerrainHeightGen &a_HeightGen, int a_SeaLevel) override
Called when the piece pool is assigned to a generator, so that the strategies may bind to the underly...
int m_SeaLevel
The sea level used by the world.
int m_Seed
Seed for the random generator.
virtual bool InitializeFromString(const AString &a_Params, bool a_LogWarnings) override
Initializes the strategy's parameters from the string representation.
int m_MinRelHeight
Minimum relative height at which the prefab is placed.
virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) override
Returns the Y coord of the piece.
int IntNoise2DInt(int a_X, int a_Y) const