Cuberite
A lightweight, fast and extensible game server for Minecraft
VillageGen.cpp
Go to the documentation of this file.
1 
2 // VillageGen.cpp
3 
4 // Implements the cVillageGen class representing the village generator
5 
6 #include "Globals.h"
7 #include "VillageGen.h"
9 #include "../BlockInfo.h"
10 
11 
12 
13 
14 
15 /*
16 How village generating works:
17 By descending from a cGridStructGen, a semi-random (jitter) grid is generated. A village may be generated for each
18 of the grid's cells. Each cell checks the biomes in an entire chunk around its center, only generating a village if
19 all biomes are village-friendly. If yes, the entire village structure is built for that cell. If not, the cell
20 is left village-less.
21 
22 A village is generated using the regular BFS piece generator. The well piece is used as the starting piece,
23 the roads and houses are then used as the following pieces. Only the houses are read from the prefabs,
24 though, the roads are generated by code and their content is ignored. A special subclass of the cPiecePool
25 class is used, so that the roads connect to each other and to the well only in predefined manners.
26 
27 The well has connectors of type "2". The houses have connectors of type "-1". The roads have connectors of
28 both types' opposites, type "-2" at the far ends and type "1" on the long edges. Additionally, there are
29 type "2" connectors along the long edges of the roads as well, so that the roads create T junctions.
30 
31 When the village is about to be drawn into a chunk, it queries the heights for each piece intersecting the
32 chunk. The pieces are shifted so that their first connector lies on the surface, and the roads are drawn
33 directly by turning the surface blocks into gravel / sandstone.
34 
35 The village prefabs are stored in global piecepools (one pool per village type). In order to support
36 per-village density setting, the cVillage class itself implements the cPiecePool interface, relaying the
37 calls to the underlying cVillagePiecePool, after processing the density check.
38 */
39 
41  public cPrefabPiecePool
42 {
44 
45 public:
46 
48  const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs,
49  const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs
50  ):
51  Super(a_PieceDefs, a_NumPieceDefs, a_StartingPieceDefs, a_NumStartingPieceDefs)
52  {
53  AddRoadPieces();
54  }
55 
57  {
58  AddRoadPieces();
59  }
60 
61  void AddRoadPieces(void)
62  {
63  // Add the road pieces:
64  for (int len = 27; len < 60; len += 12)
65  {
66  cBlockArea BA;
69  cPrefab * RoadPiece = new cPrefab(BA, 1);
70  RoadPiece->AddConnector(0, 0, 1, cPiece::cConnector::dirXM, -2);
71  RoadPiece->AddConnector(len - 1, 0, 1, cPiece::cConnector::dirXP, -2);
72  RoadPiece->SetDefaultWeight(100);
73 
74  // Add the road connectors:
75  for (int x = 1; x < len; x += 12)
76  {
77  RoadPiece->AddConnector(x, 0, 0, cPiece::cConnector::dirZM, 2);
78  RoadPiece->AddConnector(x, 0, 2, cPiece::cConnector::dirZP, 2);
79  }
80 
81  // Add the buildings connectors:
82  for (int x = 7; x < len; x += 12)
83  {
84  RoadPiece->AddConnector(x, 0, 0, cPiece::cConnector::dirZM, 1);
85  RoadPiece->AddConnector(x, 0, 2, cPiece::cConnector::dirZP, 1);
86  }
87  m_AllPieces.push_back(RoadPiece);
88  m_PiecesByConnector[-2].push_back(RoadPiece);
89  m_PiecesByConnector[1].push_back(RoadPiece);
90  m_PiecesByConnector[2].push_back(RoadPiece);
91  } // for len - roads of varying length
92  }
93 
94 
95  // cPrefabPiecePool overrides:
96  virtual int GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece) override
97  {
98  // Roads cannot branch T-wise (appending -2 connector to a +2 connector on a 1-high piece):
99  if ((a_ExistingConnector.m_Type == 2) && (a_PlacedPiece.GetDepth() > 0) && (a_PlacedPiece.GetPiece().GetSize().y == 1))
100  {
101  return 0;
102  }
103 
104  return static_cast<const cPrefab &>(a_NewPiece).GetPieceWeight(a_PlacedPiece, a_ExistingConnector);
105  }
106 };
107 
108 
109 
110 
111 
114  protected cPiecePool
115 {
117 
118 public:
119 
121  int a_Seed,
122  int a_GridX, int a_GridZ,
123  int a_OriginX, int a_OriginZ,
124  int a_MaxRoadDepth,
125  int a_MaxSize,
126  int a_Density,
127  cVillagePiecePool & a_Prefabs,
128  cTerrainHeightGen & a_HeightGen
129  ):
130  Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ),
131  m_Seed(a_Seed),
132  m_Noise(a_Seed),
133  m_MaxSize(a_MaxSize),
134  m_Density(a_Density),
135  m_Borders(
136  {a_OriginX - a_MaxSize, 0, a_OriginZ - a_MaxSize},
137  {a_OriginX + a_MaxSize, cChunkDef::Height - 1, a_OriginZ + a_MaxSize}
138  ),
139  m_Prefabs(a_Prefabs),
140  m_HeightGen(a_HeightGen)
141  {
142  // Generate the pieces for this village; don't care about the Y coord:
143  cPieceGeneratorBFSTree pg(*this, a_Seed);
144  pg.PlacePieces(a_OriginX, a_OriginZ, a_MaxRoadDepth + 1, m_Pieces);
145  if (m_Pieces.empty())
146  {
147  return;
148  }
149  }
150 
151 
152 protected:
154  int m_Seed;
155 
158 
161 
164 
167 
170 
173 
176 
177 
178  // cGridStructGen::cStructure overrides:
179  virtual void DrawIntoChunk(cChunkDesc & a_Chunk) override
180  {
181  // Iterate over all items
182  // Each intersecting prefab is placed on ground, then drawn
183  // Each intersecting road is drawn by replacing top soil blocks with gravel / sandstone blocks
184  cChunkDef::HeightMap HeightMap; // Heightmap for this chunk, used by roads
185  m_HeightGen.GenHeightMap(a_Chunk.GetChunkCoords(), HeightMap);
186  for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr)
187  {
188  const cPrefab & Prefab = static_cast<const cPrefab &>((*itr)->GetPiece());
189  if ((*itr)->GetPiece().GetSize().y == 1)
190  {
191  // It's a road, special handling (change top terrain blocks to m_RoadBlock)
192  DrawRoad(a_Chunk, **itr, HeightMap);
193  continue;
194  }
195  if (Prefab.ShouldMoveToGround() && !(*itr)->HasBeenMovedToGround())
196  {
197  PlacePieceOnGround(**itr);
198  }
199  Prefab.Draw(a_Chunk, itr->get());
200  } // for itr - m_PlacedPieces[]
201  }
202 
203 
207  {
208  cPiece::cConnector FirstConnector = a_Piece.GetRotatedConnector(0);
209  int ChunkX, ChunkZ;
210  int BlockX = FirstConnector.m_Pos.x;
211  int BlockZ = FirstConnector.m_Pos.z;
212  int BlockY;
213  cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
214  cChunkDef::HeightMap HeightMap;
215  m_HeightGen.GenHeightMap({ChunkX, ChunkZ}, HeightMap);
216  int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ);
217  a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1);
218  }
219 
220 
224  void DrawRoad(cChunkDesc & a_Chunk, cPlacedPiece & a_Road, cChunkDef::HeightMap & a_HeightMap)
225  {
226  cCuboid RoadCoords = a_Road.GetHitBox();
227  RoadCoords.Sort();
228  int MinX = std::max(RoadCoords.p1.x - a_Chunk.GetChunkX() * cChunkDef::Width, 0);
229  int MaxX = std::min(RoadCoords.p2.x - a_Chunk.GetChunkX() * cChunkDef::Width, cChunkDef::Width - 1);
230  int MinZ = std::max(RoadCoords.p1.z - a_Chunk.GetChunkZ() * cChunkDef::Width, 0);
231  int MaxZ = std::min(RoadCoords.p2.z - a_Chunk.GetChunkZ() * cChunkDef::Width, cChunkDef::Width - 1);
232  auto WaterRoadBlockType = m_Prefabs.GetVillageWaterRoadBlockType();
233  auto WaterRoadBlockMeta = m_Prefabs.GetVillageWaterRoadBlockMeta();
234  auto RoadBlockType = m_Prefabs.GetVillageRoadBlockType();
235  auto RoadBlockMeta = m_Prefabs.GetVillageRoadBlockMeta();
236  for (int z = MinZ; z <= MaxZ; z++)
237  {
238  for (int x = MinX; x <= MaxX; x++)
239  {
240  auto height = cChunkDef::GetHeight(a_HeightMap, x, z);
241  if (IsBlockWater(a_Chunk.GetBlockType(x, height, z)))
242  {
243  a_Chunk.SetBlockTypeMeta(x, height, z, WaterRoadBlockType, WaterRoadBlockMeta);
244  }
245  else
246  {
247  a_Chunk.SetBlockTypeMeta(x, height, z, RoadBlockType, RoadBlockMeta);
248  }
249  }
250  }
251  }
252 
253 
254  // cPiecePool overrides:
255  virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override
256  {
257  return m_Prefabs.GetPiecesWithConnector(a_ConnectorType);
258  }
259 
260 
261  virtual cPieces GetStartingPieces(void) override
262  {
263  return m_Prefabs.GetStartingPieces();
264  }
265 
266 
267  virtual int GetPieceWeight(
268  const cPlacedPiece & a_PlacedPiece,
269  const cPiece::cConnector & a_ExistingConnector,
270  const cPiece & a_NewPiece
271  ) override
272  {
273  // Check against the density:
274  if (a_ExistingConnector.m_Type == 1)
275  {
276  const Vector3i & Coords = a_PlacedPiece.GetRotatedConnector(a_ExistingConnector).m_Pos;
277  int rnd = (m_Noise.IntNoise3DInt(Coords.x, Coords.y, Coords.z) / 7) % 100;
278  if (rnd > m_Density)
279  {
280  return 0;
281  }
282  }
283 
284  // Density check passed, relay to m_Prefabs:
285  return m_Prefabs.GetPieceWeight(a_PlacedPiece, a_ExistingConnector, a_NewPiece);
286  }
287 
288 
289  virtual int GetStartingPieceWeight(const cPiece & a_NewPiece) override
290  {
291  return m_Prefabs.GetStartingPieceWeight(a_NewPiece);
292  }
293 
294 
295  virtual void PiecePlaced(const cPiece & a_Piece) override
296  {
297  m_Prefabs.PiecePlaced(a_Piece);
298  }
299 
300 
301  virtual void Reset(void) override
302  {
303  m_Prefabs.Reset();
304  }
305 
306 
307  void MoveAllDescendants(cPlacedPieces & a_PlacedPieces, size_t a_Pivot, int a_HeightDifference)
308  {
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++)
312  {
313  if (
314  (a_PlacedPieces[i]->GetParent() == Pivot.get()) && // It is a direct dependant of the pivot
315  !(static_cast<const cPrefab &>(a_PlacedPieces[i]->GetPiece())).ShouldMoveToGround() // It attaches strictly by connectors
316  )
317  {
318  a_PlacedPieces[i]->MoveToGroundBy(a_HeightDifference);
319  MoveAllDescendants(a_PlacedPieces, i, a_HeightDifference);
320  }
321  } // for i - a_PlacedPieces[]
322  }
323 } ;
324 
325 
326 
327 
328 
330 // cVillageGen:
331 
333  int a_Seed,
334  int a_GridSize,
335  int a_MaxOffset,
336  int a_MaxDepth,
337  int a_MaxSize,
338  int a_MinDensity,
339  int a_MaxDensity,
340  cBiomeGen & a_BiomeGen,
341  cTerrainHeightGen & a_HeightGen,
342  int a_SeaLevel,
343  const AStringVector & a_PrefabsToLoad
344 ) :
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)
353 {
354  for (const auto & toLoad: a_PrefabsToLoad)
355  {
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))
359  {
360  if (NoCaseCompare(prefabs->GetIntendedUse(), "village") != 0)
361  {
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()
364  );
365  }
366  prefabs->AssignGens(a_Seed, m_BiomeGen, m_HeightGen, a_SeaLevel);
367  m_Pools.push_back(std::move(prefabs));
368  }
369  }
370 }
371 
372 
373 
374 
375 
376 cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ)
377 {
378  // Generate the biomes for the chunk surrounding the origin:
379  int ChunkX, ChunkZ;
380  cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ);
381  cChunkDef::BiomeMap Biomes;
382  m_BiomeGen.GenBiomes({ChunkX, ChunkZ}, Biomes);
383 
384  // Get a list of pools that support each biome within the chunk:
385  // If just one column's biome is not allowed, the pool is not used because it's likely that an unfriendly biome is too close
386  auto availablePools = m_Pools;
387  for (size_t i = 0; i < ARRAYCOUNT(Biomes); i++)
388  {
389  auto biome = Biomes[i];
390  availablePools.erase(std::remove_if(availablePools.begin(), availablePools.end(),
391  [biome](std::shared_ptr<cVillagePiecePool> & a_Pool)
392  {
393  return !a_Pool->IsBiomeAllowed(biome);
394  }),
395  availablePools.end()
396  );
397  // Bail out if no compatible pools left:
398  if (availablePools.empty())
399  {
400  return cStructurePtr();
401  }
402  }
403 
404  // Pick one pool from the available pools:
405  if (availablePools.empty())
406  {
407  return cStructurePtr();
408  }
409  auto rnd = m_RandNoise.IntNoise2DInt(a_OriginX, a_OriginZ) / 11;
410  auto pool = availablePools[static_cast<size_t>(rnd) % availablePools.size()];
411  rnd /= 137;
412 
413  // Choose density for the village, random between m_MinDensity and m_MaxDensity:
414  int Density;
415  if (pool->GetMaxDensity() > pool->GetMinDensity())
416  {
417  Density = pool->GetMinDensity() + rnd % (pool->GetMaxDensity() - pool->GetMinDensity());
418  }
419  else
420  {
421  Density = pool->GetMinDensity();
422  }
423 
424  // Create a village based on the chosen prefabs:
425  return cStructurePtr(new cVillage(m_Seed, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize, Density, *pool.get(), m_HeightGen));
426 }
bool IsBlockWater(BLOCKTYPE a_BlockType)
Definition: BlockInfo.cpp:10
@ E_BLOCK_GRAVEL
Definition: BlockType.h:23
std::vector< cPiece * > cPieces
Definition: PiecePool.h:262
std::vector< cPlacedPiecePtr > cPlacedPieces
Definition: PiecePool.h:370
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
Definition: Globals.h:231
void LOGWARNING(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:67
int NoCaseCompare(const AString &s1, const AString &s2)
Case-insensitive string comparison.
std::vector< AString > AStringVector
Definition: StringUtils.h:12
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.
Definition: BlockArea.cpp:338
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.
Definition: BlockArea.cpp:773
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
Definition: ChunkDef.h:210
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:
Definition: ChunkDef.h:147
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
Definition: ChunkDef.h:132
static const int Width
Definition: ChunkDef.h:124
static const int Height
Definition: ChunkDef.h:125
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
Definition: ChunkDef.h:303
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:137
Definition: Cuboid.h:10
Vector3i p2
Definition: Cuboid.h:13
void Sort(void)
Definition: Cuboid.cpp:23
Vector3i p1
Definition: Cuboid.h:13
int GetChunkX() const
Definition: ChunkDesc.h:49
void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: ChunkDesc.cpp:63
BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const
Definition: ChunkDesc.cpp:90
cChunkCoords GetChunkCoords() const
Definition: ChunkDesc.h:54
int GetChunkZ() const
Definition: ChunkDesc.h:50
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.
Definition: GridStructGen.h:46
std::shared_ptr< cStructure > cStructurePtr
Definition: GridStructGen.h:77
int m_Seed
Seed for generating grid offsets and also available for descendants.
Represents a single structure that occupies the grid point.
Definition: GridStructGen.h:50
Represents a single piece.
Definition: PiecePool.h:21
virtual Vector3i GetSize(void) const =0
Returns the dimensions of this piece.
int m_Type
Type of the connector.
Definition: PiecePool.h:54
Vector3i m_Pos
Position relative to the piece.
Definition: PiecePool.h:50
This class is an interface that stores pieces for a generator.
Definition: PiecePool.h:278
Represents a single piece that has been placed to specific coords in the world.
Definition: PiecePool.h:328
const cCuboid & GetHitBox(void) const
Definition: PiecePool.h:336
void MoveToGroundBy(int a_OffsetY)
Moves the placed piece Y-wise by the specified offset.
Definition: PiecePool.cpp:504
cPiece::cConnector GetRotatedConnector(size_t a_Index) const
Returns the connector at the specified index, rotated in the actual placement.
Definition: PiecePool.cpp:484
int GetDepth(void) const
Definition: PiecePool.h:337
const cPiece & GetPiece(void) const
Definition: PiecePool.h:333
Definition: Prefab.h:33
bool ShouldMoveToGround(void) const
Returns whether the prefab should be moved Y-wise to ground before drawing, rather than staying at th...
Definition: Prefab.h:139
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.
Definition: Prefab.cpp:320
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.
Definition: Prefab.cpp:133
void SetDefaultWeight(int a_DefaultWeight)
Sets the (unmodified) DefaultWeight property for this piece.
Definition: Prefab.cpp:311
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...
Definition: VillageGen.cpp:96
cVillagePiecePool(const cPrefab::sDef *a_PieceDefs, size_t a_NumPieceDefs, const cPrefab::sDef *a_StartingPieceDefs, size_t a_NumStartingPieceDefs)
Definition: VillageGen.cpp:47
void AddRoadPieces(void)
Definition: VillageGen.cpp:61
virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override
Returns a list of pieces that contain the specified connector type.
Definition: VillageGen.cpp:255
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...
Definition: VillageGen.cpp:289
cNoise m_Noise
The noise used as a pseudo-random generator.
Definition: VillageGen.cpp:157
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)
Definition: VillageGen.cpp:120
cTerrainHeightGen & m_HeightGen
The underlying height generator, used for placing the structures on top of the terrain.
Definition: VillageGen.cpp:172
int m_Density
The density for this village.
Definition: VillageGen.cpp:163
void DrawRoad(cChunkDesc &a_Chunk, cPlacedPiece &a_Road, cChunkDef::HeightMap &a_HeightMap)
Draws the road into the chunk.
Definition: VillageGen.cpp:224
virtual void Reset(void) override
Called when the pool has finished the current structure and should reset any piece-counters it has fo...
Definition: VillageGen.cpp:301
cCuboid m_Borders
Borders of the village - no item may reach out of this cuboid.
Definition: VillageGen.cpp:166
int m_MaxSize
Maximum size, in X / Z blocks, of the village (radius from the origin)
Definition: VillageGen.cpp:160
virtual void DrawIntoChunk(cChunkDesc &a_Chunk) override
Draws self into the specified chunk.
Definition: VillageGen.cpp:179
void PlacePieceOnGround(cPlacedPiece &a_Piece)
Adjusts the Y coord of the given piece so that the piece is on the ground.
Definition: VillageGen.cpp:206
cPlacedPieces m_Pieces
The village pieces, placed by the generator.
Definition: VillageGen.cpp:175
virtual cPieces GetStartingPieces(void) override
Returns the pieces that should be used as the starting point.
Definition: VillageGen.cpp:261
void MoveAllDescendants(cPlacedPieces &a_PlacedPieces, size_t a_Pivot, int a_HeightDifference)
Definition: VillageGen.cpp:307
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...
Definition: VillageGen.cpp:267
cVillagePiecePool & m_Prefabs
Prefabs to use for buildings.
Definition: VillageGen.cpp:169
virtual void PiecePlaced(const cPiece &a_Piece) override
Called after a piece is placed, to notify the pool that it has been used.
Definition: VillageGen.cpp:295
int m_Seed
Seed for the random functions.
Definition: VillageGen.cpp:154
cVillagePiecePools m_Pools
All available prefab sets.
Definition: VillageGen.h:73
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.
Definition: VillageGen.cpp:332
int m_MaxDepth
Maximum depth of the generator tree.
Definition: VillageGen.h:55
cTerrainHeightGen & m_HeightGen
The underlying height generator, used to position the prefabs crossing chunk borders.
Definition: VillageGen.h:70
cBiomeGen & m_BiomeGen
The underlying biome generator that defines whether the village is created or not.
Definition: VillageGen.h:67
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override
Create a new structure at the specified gridpoint.
Definition: VillageGen.cpp:376
cNoise m_RandNoise
The noise used for generating random numbers.
Definition: VillageGen.h:52
int m_MaxSize
Maximum size, in X / Z blocks, of the village (radius from the origin)
Definition: VillageGen.h:58
Definition: Noise.h:20
int IntNoise3DInt(int a_X, int a_Y, int a_Z) const
Definition: Noise.h:254
int IntNoise2DInt(int a_X, int a_Y) const
Definition: Noise.h:243
static AString GetPathSeparator()
Returns the path separator used by the current platform.
Definition: File.cpp:669
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17