5 #include "../IniFile.h"
41 LOGWARNING(
"SinglePieceStructures generator: File %s is intended for use in \"%s\", rather than single piece structures. Loading the file, but the generator may behave unexpectedly.",
73 OutPiece.push_back(
GetPiece(a_OriginX, a_OriginZ));
74 return std::make_shared<cPrefabStructure>(a_GridX, a_GridZ, a_OriginX, a_OriginZ, std::move(OutPiece),
m_HeightGen);
88 for (cPieces::const_iterator itr = StartingPieces.begin(), end = StartingPieces.end(); itr != end; ++itr)
95 int Chosen = rnd % Total;
96 StartingPiece = StartingPieces.front();
97 for (cPieces::const_iterator itr = StartingPieces.begin(), end = StartingPieces.end(); itr != end; ++itr)
102 StartingPiece = *itr;
110 StartingPiece = StartingPieces[
static_cast<size_t>(rnd) % StartingPieces.size()];
115 int Rotations[4] = {0};
116 int NumRotations = 1;
117 for (
size_t i = 1; i <
ARRAYCOUNT(Rotations); i++)
121 Rotations[NumRotations] =
static_cast<int>(i);
125 int Rotation = Rotations[rnd % NumRotations];
167 for (
const auto & S: Structures)
169 auto FileName = fmt::format(FMT_STRING(
"Prefabs{0}SinglePieceStructures{0}{1}.cubeset"),
cFile::PathSeparator(), S);
172 FileName.append(
".gz");
175 LOGWARNING(
"Cannot load SinglePieceStructure cubeset file %s", FileName);
180 auto Gen = std::make_shared<cGen>(
m_Seed, a_BiomeGen, a_HeightGen, a_SeaLevel, S);
181 if (Gen->LoadFromFile(FileName))
190 LOGWARNING(
"The PieceStructures generator was asked to generate \"%s\", but none of the prefabs are valid.", a_Prefabs);
204 Gen->GenFinish(a_Chunk);
std::vector< cPiece * > cPieces
std::unique_ptr< cPlacedPiece > cPlacedPiecePtr
std::vector< cPlacedPiecePtr > cPlacedPieces
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
void LOGWARNING(std::string_view a_Format, const Args &... args)
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.
unsigned char Rotation(const BlockState Block)
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
The interface that a biome generator must implement A biome generator takes chunk coords on input and...
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap)=0
Generates biomes for the given chunk.
The interface that is used to query terrain height from the shape generator.
Generates structures in a semi-random grid.
std::shared_ptr< cStructure > cStructurePtr
cGridStructGen(int a_Seed, int a_GridSizeX, int a_GridSizeZ, int a_MaxOffsetX, int a_MaxOffsetZ, int a_MaxStructureSizeX, int a_MaxStructureSizeZ, size_t a_MaxCacheSize)
int m_Seed
Seed for generating grid offsets and also available for descendants.
void SetGeneratorParams(const AStringMap &a_GeneratorParams)
Sets the generator params based on the dictionary passed in.
cNoise m_Noise
The noise used for generating grid offsets.
Represents a single piece.
virtual bool CanRotateCCW(int a_NumRotations) const =0
Returns true if the piece can be rotated CCW the specific number of 90-degree turns.
int GetStartingPieceHeight(int a_BlockX, int a_BlockZ)
Returns the height, based on m_VerticalStrategy, for this piece when used as the starting piece.
Represents a single piece that has been placed to specific coords in the world.
void Clear(void)
Removes and frees all pieces from this pool.
virtual int GetStartingPieceWeight(const cPiece &a_NewPiece) override
Returns the relative weight with which the a_NewPiece is to be selected for placing as the first piec...
bool IsBiomeAllowed(EMCSBiome a_Biome) const
Returns true if a_Biome is among the accepted biomes in the m_AcceptedBiomes metadata member.
virtual cPieces GetStartingPieces(void) override
Returns the pieces that should be used as the starting point.
bool LoadFromFile(const AString &a_FileName, bool a_LogWarnings)
Loads the pieces from the specified file.
const AStringMap & GetAllMetadata(void) const
void AssignGens(int a_Seed, cBiomeGen &a_BiomeGen, cTerrainHeightGen &a_HeightGen, int a_SeaLevel)
Called when the piece pool is assigned to a generator, so that the individual starting pieces' vertic...
const AString & GetIntendedUse(void) const
cPrefabPiecePool m_PiecePool
All available prefabs.
int m_SeaLevel
The world's sea level, if available.
cBiomeGen & m_BiomeGen
The underlying biome generator that defines whether the structure is created or not.
AString m_Name
The name that is used for reporting.
cGen(int a_Seed, cBiomeGen &a_BiomeGen, cTerrainHeightGen &a_HeightGen, int a_SeaLevel, const AString &a_Name)
bool LoadFromFile(const AString &a_FileName)
Loads the piecepool from a file.
cTerrainHeightGen & m_HeightGen
The underlying height generator, used to position the prefabs crossing chunk borders if they are set ...
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override
Create a new structure at the specified gridpoint.
cPlacedPiecePtr GetPiece(int a_BlockX, int a_BlockZ)
Determines which piece to place from the piece pool.
virtual void GenFinish(cChunkDesc &a_ChunkDesc) override
bool Initialize(const AString &a_Prefabs, int a_SeaLevel, cBiomeGen &a_BiomeGen, cTerrainHeightGen &a_HeightGen)
Initializes the generator based on the specified prefab sets.
cSinglePieceStructuresGen(int a_Seed)
cGenPtrs m_Gens
The individual structure generators, one per piecepool.
int m_Seed
The seed for the random number generator.
int IntNoise2DInt(int a_X, int a_Y) const
static char PathSeparator()
static bool IsFile(const AString &a_Path)
Returns true if the specified path is a regular file.