9 #include "../BlockInfo.h"
49 const cPrefab::sDef * a_StartingPieceDefs,
size_t a_NumStartingPieceDefs
51 Super(a_PieceDefs, a_NumPieceDefs, a_StartingPieceDefs, a_NumStartingPieceDefs)
64 for (
int len = 27; len < 60; len += 12)
75 for (
int x = 1; x < len; x += 12)
82 for (
int x = 7; x < len; x += 12)
122 int a_GridX,
int a_GridZ,
123 int a_OriginX,
int a_OriginZ,
130 Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ),
136 {a_OriginX - a_MaxSize, 0, a_OriginZ - a_MaxSize},
144 pg.PlacePieces(a_OriginX, a_OriginZ, a_MaxRoadDepth + 1,
m_Pieces);
186 for (cPlacedPieces::iterator itr =
m_Pieces.begin(), end =
m_Pieces.end(); itr != end; ++itr)
188 const cPrefab & Prefab =
static_cast<const cPrefab &
>((*itr)->GetPiece());
189 if ((*itr)->GetPiece().GetSize().y == 1)
192 DrawRoad(a_Chunk, **itr, HeightMap);
199 Prefab.
Draw(a_Chunk, itr->get());
210 int BlockX = FirstConnector.
m_Pos.
x;
211 int BlockZ = FirstConnector.
m_Pos.
z;
236 for (
int z = MinZ; z <= MaxZ; z++)
238 for (
int x = MinX; x <= MaxX; x++)
243 a_Chunk.
SetBlockTypeMeta(x, height, z, WaterRoadBlockType, WaterRoadBlockMeta);
274 if (a_ExistingConnector.
m_Type == 1)
309 size_t num = a_PlacedPieces.size();
310 auto & Pivot = a_PlacedPieces[a_Pivot];
311 for (
size_t i = a_Pivot + 1; i < num; i++)
314 (a_PlacedPieces[i]->GetParent() == Pivot.get()) &&
315 !(
static_cast<const cPrefab &
>(a_PlacedPieces[i]->GetPiece())).ShouldMoveToGround()
318 a_PlacedPieces[i]->MoveToGroundBy(a_HeightDifference);
345 Super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 100),
346 m_RandNoise(a_Seed + 1000),
347 m_MaxDepth(a_MaxDepth),
348 m_MaxSize(a_MaxSize),
349 m_MinDensity(a_MinDensity),
350 m_MaxDensity(a_MaxDensity),
351 m_BiomeGen(a_BiomeGen),
352 m_HeightGen(a_HeightGen)
354 for (
const auto & toLoad: a_PrefabsToLoad)
356 auto prefabs = std::make_shared<cVillagePiecePool>();
357 auto fileName = fmt::format(FMT_STRING(
"Prefabs{0}Villages{0}{1}.cubeset"),
cFile::GetPathSeparator(), toLoad);
358 if (prefabs->LoadFromFile(fileName,
true))
360 if (
NoCaseCompare(prefabs->GetIntendedUse(),
"village") != 0)
362 LOGWARNING(
"Village generator: File %s is intended for use in \"%s\", rather than villages. Loading the file, but the generator may behave unexpectedly.",
363 fileName, prefabs->GetIntendedUse()
367 m_Pools.push_back(std::move(prefabs));
387 for (
size_t i = 0; i <
ARRAYCOUNT(Biomes); i++)
389 auto biome = Biomes[i];
390 availablePools.erase(std::remove_if(availablePools.begin(), availablePools.end(),
391 [biome](std::shared_ptr<cVillagePiecePool> & a_Pool)
393 return !a_Pool->IsBiomeAllowed(biome);
398 if (availablePools.empty())
405 if (availablePools.empty())
410 auto pool = availablePools[
static_cast<size_t>(rnd) % availablePools.size()];
415 if (pool->GetMaxDensity() > pool->GetMinDensity())
417 Density = pool->GetMinDensity() + rnd % (pool->GetMaxDensity() - pool->GetMinDensity());
421 Density = pool->GetMinDensity();
bool IsBlockWater(BLOCKTYPE a_BlockType)
std::vector< cPiece * > cPieces
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)
int NoCaseCompare(const AString &s1, const AString &s2)
Case-insensitive string comparison.
std::vector< AString > AStringVector
void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes=baTypes|baMetas|baBlockEntities)
Creates a new area of the specified size and contents.
void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta=0, NIBBLETYPE a_BlockLight=0, NIBBLETYPE a_BlockSkyLight=0x0f)
Fills the entire block area with the specified data.
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:
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)
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const
cChunkCoords GetChunkCoords() const
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.
virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap &a_HeightMap)=0
Retrieves the heightmap for the specified chunk.
Generates structures in a semi-random grid.
std::shared_ptr< cStructure > cStructurePtr
int m_Seed
Seed for generating grid offsets and also available for descendants.
Represents a single structure that occupies the grid point.
Represents a single piece.
virtual Vector3i GetSize(void) const =0
Returns the dimensions of this piece.
int m_Type
Type of the connector.
Vector3i m_Pos
Position relative to the piece.
This class is an interface that stores pieces for a generator.
Represents a single piece that has been placed to specific coords in the world.
const cCuboid & GetHitBox(void) const
void MoveToGroundBy(int a_OffsetY)
Moves the placed piece Y-wise by the specified offset.
cPiece::cConnector GetRotatedConnector(size_t a_Index) const
Returns the connector at the specified index, rotated in the actual placement.
const cPiece & GetPiece(void) const
bool ShouldMoveToGround(void) const
Returns whether the prefab should be moved Y-wise to ground before drawing, rather than staying at th...
void AddConnector(int a_RelX, int a_RelY, int a_RelZ, cPiece::cConnector::eDirection a_Direction, int a_Type)
Adds the specified connector to the list of connectors this piece supports.
void Draw(cChunkDesc &a_Dest, const cPlacedPiece *a_Placement) const
Draws the prefab into the specified chunk, according to the placement stored in the PlacedPiece.
void SetDefaultWeight(int a_DefaultWeight)
Sets the (unmodified) DefaultWeight property for this piece.
cPrefabPiecePool(void)
Creates an empty instance.
cPiecesMap m_PiecesByConnector
The map that has all pieces by their connector types The pieces are copies out of m_AllPieces and sho...
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...
BLOCKTYPE GetVillageWaterRoadBlockType(void) const
NIBBLETYPE GetVillageWaterRoadBlockMeta(void) const
virtual cPieces GetStartingPieces(void) override
Returns the pieces that should be used as the starting point.
cPieces m_AllPieces
All the pieces that are allowed for building.
BLOCKTYPE GetVillageRoadBlockType(void) const
virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override
Returns a list of pieces that contain the specified connector type.
virtual void Reset(void) override
Called when the pool has finished the current structure and should reset any piece-counters it has fo...
NIBBLETYPE GetVillageRoadBlockMeta(void) const
virtual void PiecePlaced(const cPiece &a_Piece) override
Called after a piece is placed, to notify the pool that it has been used.
virtual int GetPieceWeight(const cPlacedPiece &a_PlacedPiece, const cPiece::cConnector &a_ExistingConnector, const cPiece &a_NewPiece) override
Returns the relative weight with which the a_NewPiece is to be selected for placing under a_PlacedPie...
cVillagePiecePool(const cPrefab::sDef *a_PieceDefs, size_t a_NumPieceDefs, const cPrefab::sDef *a_StartingPieceDefs, size_t a_NumStartingPieceDefs)
virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override
Returns a list of pieces that contain the specified connector type.
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...
cNoise m_Noise
The noise used as a pseudo-random generator.
cVillage(int a_Seed, int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_MaxRoadDepth, int a_MaxSize, int a_Density, cVillagePiecePool &a_Prefabs, cTerrainHeightGen &a_HeightGen)
cTerrainHeightGen & m_HeightGen
The underlying height generator, used for placing the structures on top of the terrain.
int m_Density
The density for this village.
void DrawRoad(cChunkDesc &a_Chunk, cPlacedPiece &a_Road, cChunkDef::HeightMap &a_HeightMap)
Draws the road into the chunk.
virtual void Reset(void) override
Called when the pool has finished the current structure and should reset any piece-counters it has fo...
cCuboid m_Borders
Borders of the village - no item may reach out of this cuboid.
int m_MaxSize
Maximum size, in X / Z blocks, of the village (radius from the origin)
virtual void DrawIntoChunk(cChunkDesc &a_Chunk) override
Draws self into the specified chunk.
void PlacePieceOnGround(cPlacedPiece &a_Piece)
Adjusts the Y coord of the given piece so that the piece is on the ground.
cPlacedPieces m_Pieces
The village pieces, placed by the generator.
virtual cPieces GetStartingPieces(void) override
Returns the pieces that should be used as the starting point.
void MoveAllDescendants(cPlacedPieces &a_PlacedPieces, size_t a_Pivot, int a_HeightDifference)
virtual int GetPieceWeight(const cPlacedPiece &a_PlacedPiece, const cPiece::cConnector &a_ExistingConnector, const cPiece &a_NewPiece) override
Returns the relative weight with which the a_NewPiece is to be selected for placing under a_PlacedPie...
cVillagePiecePool & m_Prefabs
Prefabs to use for buildings.
virtual void PiecePlaced(const cPiece &a_Piece) override
Called after a piece is placed, to notify the pool that it has been used.
int m_Seed
Seed for the random functions.
cVillagePiecePools m_Pools
All available prefab sets.
cVillageGen(int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, cBiomeGen &a_BiomeGen, cTerrainHeightGen &a_HeightGen, int a_SeaLevel, const AStringVector &a_PrefabsToLoad)
Creates a new instance of the generator with the specified parameters.
int m_MaxDepth
Maximum depth of the generator tree.
cTerrainHeightGen & m_HeightGen
The underlying height generator, used to position the prefabs crossing chunk borders.
cBiomeGen & m_BiomeGen
The underlying biome generator that defines whether the village is created or not.
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override
Create a new structure at the specified gridpoint.
cNoise m_RandNoise
The noise used for generating random numbers.
int m_MaxSize
Maximum size, in X / Z blocks, of the village (radius from the origin)
int IntNoise3DInt(int a_X, int a_Y, int a_Z) const
int IntNoise2DInt(int a_X, int a_Y) const
static AString GetPathSeparator()
Returns the path separator used by the current platform.