Cuberite
A lightweight, fast and extensible game server for Minecraft
FinishGen.h
Go to the documentation of this file.
1 
2 // FinishGen.h
3 
4 /* Interfaces to the various finishing generators:
5  - cFinishGenSnow
6  - cFinishGenIce
7  - cFinishGenSprinkleFoliage
8  - cFinishGenLilypads
9  - cFinishGenBottomLava
10  - cFinishGenPreSimulator
11  - cFinishGenDeadBushes
12 */
13 
14 
15 
16 
17 
18 #include "ComposableGenerator.h"
19 #include "../Noise/Noise.h"
20 #include "../ProbabDistrib.h"
21 #include "../Mobs/Monster.h"
22 
23 
24 
25 
26 
28  public cFinishGen
29 {
30 protected:
31  // cFinishGen override:
32  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
33 } ;
34 
35 
36 
37 
38 
40  public cFinishGen
41 {
42 protected:
43  // cFinishGen override:
44  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
45 } ;
46 
47 
48 
49 
50 
52  public cFinishGen
53 {
54 public:
56  m_Noise(a_Seed),
57  m_Seed(a_Seed)
58  {
59  }
60 
61 protected:
63  int m_Seed;
64 
65  void TryPlaceClump(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_Block);
66  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
67 } ;
68 
69 
70 
71 
72 
74  public cFinishGen
75 {
76 public:
77  // Contains the meta, type and weight for a clump block
78  struct FoliageInfo
79  {
82  int m_Weight;
83 
84  FoliageInfo(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_Weight) :
85  m_BlockType(a_BlockType),
86  m_BlockMeta(a_BlockMeta),
87  m_Weight(a_Weight)
88  {}
89  };
90 
91  // Contains the minimum and maximum amount of clumps for a biome and it's blocks.
92  struct BiomeInfo
93  {
96  std::vector<FoliageInfo> m_Blocks;
97 
99  m_MinNumClumpsPerChunk(0),
100  m_MaxNumClumpsPerChunk(2),
101  m_Blocks()
102  {}
103 
104  BiomeInfo(int a_MinNumClumpsPerChunk, int a_MaxNumClumpsPerChunk, std::vector<FoliageInfo> a_Blocks) :
105  m_MinNumClumpsPerChunk(a_MinNumClumpsPerChunk),
106  m_MaxNumClumpsPerChunk(a_MaxNumClumpsPerChunk),
107  m_Blocks(a_Blocks)
108  {}
109  };
110 
111 
112  cFinishGenClumpTopBlock(int a_Seed, std::vector<BiomeInfo> a_BlockList) :
113  m_Noise(a_Seed),
114  m_FlowersPerBiome()
115  {
116  std::swap(a_BlockList, m_FlowersPerBiome);
117  }
118 
121  static void ParseConfigurationString(AString a_String, std::vector<BiomeInfo> & a_Output);
122 
124  static std::vector<BiomeInfo> ParseIniFile(cIniFile & a_IniFile, AString a_ClumpPrefix);
125 protected:
126 
128  std::vector<BiomeInfo> m_FlowersPerBiome;
129 
131  const int MAX_NUM_FOLIAGE = 8;
132 
134  const int MIN_NUM_FOLIAGE = 4;
135 
137  const int RANGE_FROM_CENTER = 5;
138 
139  void TryPlaceFoliageClump(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_IsDoubleTall);
140  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
141 };
142 
143 
144 
145 
146 
148  public cFinishGen
149 {
150 public:
151  cFinishGenGlowStone(int a_Seed) :
152  m_Noise(a_Seed),
153  m_Seed(a_Seed)
154  {
155  }
156 
157 protected:
159  int m_Seed;
160 
161  void TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, int a_Size, int a_NumStrings);
162  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
163 } ;
164 
165 
166 
167 
168 
170  public cFinishGen
171 {
172 public:
173  cFinishGenTallGrass(int a_Seed) : m_Noise(a_Seed), m_Seed(a_Seed) {}
174 
175 protected:
177  int m_Seed;
178 
179  // cFinishGen override:
180  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
181 
183  {
184  switch (a_Biome)
185  {
186  case biSavanna:
187  case biSavannaM:
188  case biSavannaPlateau:
189  case biSavannaPlateauM:
190  case biPlains:
191  {
192  return 70;
193  }
194 
195  case biExtremeHillsEdge:
196  case biExtremeHillsPlus:
197  case biExtremeHills:
198  case biExtremeHillsPlusM:
199  case biExtremeHillsM:
200  case biIceMountains:
201  {
202  return 3;
203  }
204 
205  default:
206  {
207  return 20;
208  }
209  }
210  }
211 };
212 
213 
214 
215 
216 
218  public cFinishGen
219 {
220 public:
221  cFinishGenVines(int a_Seed, int a_Level) :
222  m_Noise(a_Seed),
223  m_Level(a_Level)
224  {
225  }
226 
227  bool IsJungleVariant(EMCSBiome a_Biome);
228 
229 protected:
231  int m_Level;
232 
233  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
234 };
235 
236 
237 
238 
239 
241  public cFinishGen
242 {
243 public:
245  m_Noise(a_Seed)
246  {
247  }
248 
249 protected:
251 
252  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
253 } ;
254 
255 
256 
257 
258 
260  public cFinishGen
261 {
262 public:
263  cFinishGenSprinkleFoliage(int a_Seed, int a_MaxCactusHeight, int a_MaxSugarcaneHeight):
264  m_Noise(a_Seed),
265  m_Seed(a_Seed),
266  m_MaxCactusHeight(a_MaxCactusHeight),
267  m_MaxSugarcaneHeight(a_MaxSugarcaneHeight)
268  {
269  }
270 protected:
272  int m_Seed;
275 
277  bool TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_RelX, HEIGHTTYPE & a_RelY, int a_RelZ);
278 
280  bool TryAddCactus(cChunkDesc & a_ChunkDesc, int a_RelX, HEIGHTTYPE & a_RelY, int a_RelZ);
281 
282  // Returns true is the specified biome is a desert or its variant
283  static bool IsDesertVariant(EMCSBiome a_biome);
284 
285  // cFinishGen override:
286  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
287 } ;
288 
289 
290 
291 
292 
298  public cFinishGen
299 {
300 public:
301  typedef std::vector<BLOCKTYPE> BlockList;
302  bool m_IsAllowedBelow[256];
303 
304  typedef std::vector<EMCSBiome> BiomeList;
305  bool m_IsBiomeAllowed[256];
306 
307 
309  int a_Seed, BLOCKTYPE a_BlockType, BiomeList a_Biomes, int a_Amount,
310  BlockList a_AllowedBelow
311  ) :
312  m_Noise(a_Seed),
313  m_BlockType(a_BlockType),
314  m_Amount(a_Amount)
315  {
316  // Initialize all the block types.
317  for (size_t idx = 0; idx < ARRAYCOUNT(m_IsAllowedBelow); ++idx)
318  {
319  m_IsAllowedBelow[idx] = false;
320  }
321 
322  // Load the allowed blocks into m_IsAllowedBelow
323  for (BlockList::iterator itr = a_AllowedBelow.begin(); itr != a_AllowedBelow.end(); ++itr)
324  {
325  m_IsAllowedBelow[*itr] = true;
326  }
327 
328  // Initialize all the biome types.
329  for (size_t idx = 0; idx < ARRAYCOUNT(m_IsBiomeAllowed); ++idx)
330  {
331  m_IsBiomeAllowed[idx] = false;
332  }
333 
334  // Load the allowed biomes into m_IsBiomeAllowed
335  for (BiomeList::iterator itr = a_Biomes.begin(); itr != a_Biomes.end(); ++itr)
336  {
337  m_IsBiomeAllowed[*itr] = true;
338  }
339  }
340 
341 protected:
344 
346  int m_Amount;
347 
348 
349  int GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap);
350 
352  inline bool IsAllowedBiome(EMCSBiome a_Biome)
353  {
354  return m_IsBiomeAllowed[a_Biome];
355  }
356 
358  inline bool IsAllowedBlockBelow(BLOCKTYPE a_BlockBelow)
359  {
360  return m_IsAllowedBelow[a_BlockBelow];
361  }
362 
363 
364  // cFinishGen override:
365  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
366 } ;
367 
368 
369 
370 
371 
373  public cFinishGen
374 {
375 public:
376  cFinishGenBottomLava(int a_Level) :
377  m_Level(a_Level)
378  {
379  }
380 
381  int GetLevel(void) const { return m_Level; }
382 protected:
383  int m_Level;
384 
385  // cFinishGen override:
386  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
387 } ;
388 
389 
390 
391 
392 
394  public cFinishGen
395 {
396 public:
397  cFinishGenPreSimulator(bool a_PreSimulateFallingBlocks, bool a_PreSimulateWater, bool a_PreSimulateLava);
398 
399 protected:
400 
404 
406  void CollapseSandGravel(cChunkDesc & a_ChunkDesc);
407 
411  void StationarizeFluid(
412  cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change
413  cChunkDef::HeightMap & a_HeightMap, // Height map to read
414  BLOCKTYPE a_Fluid,
415  BLOCKTYPE a_StationaryFluid
416  );
417 
418  // cFinishGen override:
419  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
420 } ;
421 
422 
423 
424 
425 
427  public cFinishGen
428 {
429 public:
430  cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cIniFile & a_IniFile, eDimension a_Dimension);
431 
432 protected:
433 
437  int m_Chance;
438 
439  // cFinishGen override:
440  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
441 
443  bool TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int y, int z);
444 } ;
445 
446 
447 
448 
449 
453  public cFinishGen
454 {
455 public:
456 
457  cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension);
458 
459 protected:
460 
463 
466 
467 
468  // cFinishGen override:
469  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
470 
472  bool TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int x, int y, int z, eMonsterType AnimalToSpawn);
473 
476  eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc);
477 } ;
478 
479 
480 
481 
482 
488  public cFinishGen
489 {
490  typedef cFinishGen Super;
491 
492 public:
493  struct OreInfo
494  {
495  BLOCKTYPE m_BlockType; // The type of the nest.
496  NIBBLETYPE m_BlockMeta; // The block meta
497  int m_MaxHeight; // The highest possible a nest can occur
498  int m_NumNests; // How many nests per chunk
499  int m_NestSize; // The amount of blocks a nest can have.
500 
502  m_BlockType(0),
503  m_BlockMeta(0),
504  m_MaxHeight(0),
505  m_NumNests(0),
506  m_NestSize(0)
507  {
508  }
509 
510  OreInfo(BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta, int a_MaxHeight, int a_NumNests, int a_NestSize) :
511  m_BlockType(a_OreType),
512  m_BlockMeta(a_OreMeta),
513  m_MaxHeight(a_MaxHeight),
514  m_NumNests(a_NumNests),
515  m_NestSize(a_NestSize)
516  {
517  }
518  };
519 
520  typedef std::vector<OreInfo> OreInfos;
521 
522  cFinishGenOres(int a_Seed, const OreInfos & a_OreInfos):
523  m_Noise(a_Seed),
524  m_OreInfos(a_OreInfos)
525  {
526  }
527 
528  // cFinishGen overrides:
529  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
530 
532  static const OreInfos & DefaultOverworldOres(void);
533 
535  static const OreInfos & DefaultNetherOres(void);
536 
538  static const OreInfos & DefaultNaturalPatches(void);
539 
543  static OreInfos OreInfosFromString(const AString & a_OreInfosString);
544 
548  static AString OreInfosToString(const OreInfos & a_OreInfos);
549 
551  void SetSeed(int a_Seed);
552 
553 protected:
556 
558  OreInfos m_OreInfos;
559 
560 
563  virtual void GenerateOre(
564  cChunkDesc & a_ChunkDesc,
565  BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta,
566  int a_MaxHeight, int a_NumNests, int a_NestSize,
567  int a_Seq
568  ) = 0;
569 
570  // TODO: Helper function to parse a config string into m_OreInfos
571 };
572 
573 
574 
575 
576 
578  public cFinishGenOres
579 {
581 
582 public:
583  cFinishGenOreNests(int a_Seed, const OreInfos & a_OreInfos):
584  Super(a_Seed, a_OreInfos)
585  {}
586 
587 protected:
588 
589  // cFinishGenOreClumps overrides:
590  virtual void GenerateOre(
591  cChunkDesc & a_ChunkDesc,
592  BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta,
593  int a_MaxHeight, int a_NumNests, int a_NestSize,
594  int a_Seq
595  ) override;
596 } ;
597 
598 
599 
600 
601 
603  public cFinishGenOres
604 {
606 
607 public:
608  cFinishGenOrePockets(int a_Seed, const OreInfos & a_OreInfos):
609  Super(a_Seed, a_OreInfos)
610  {}
611 
615  bool Initialize(cIniFile & a_IniFile, const AString & a_GenName);
616 
617 protected:
618 
619  // cFinishGenOreClumps overrides:
620  virtual void GenerateOre(
621  cChunkDesc & a_ChunkDesc,
622  BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta,
623  int a_MaxNestHeight, int a_NumNests, int a_NestSize,
624  int a_Seq
625  ) override;
626 
629  void imprintChunkOrePockets(
630  int a_ChunkX, int a_ChunkZ,
631  cChunkDesc & a_ChunkDesc,
632  BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta,
633  int a_MaxHeight, int a_NumNests, int a_NestSize,
634  int a_Seq
635  );
636 
640  void imprintPocket(
641  cChunkDesc & a_ChunkDesc,
642  int a_MinPocketX, int a_PocketY, int a_MinPocketZ,
643  int a_NestSize, int a_Seq,
644  BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta
645  );
646 
648  void imprintSphere(
649  cChunkDesc & a_ChunkDesc,
650  double a_SphereX, double a_SphereY, double a_SphereZ, double a_Radius,
651  BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta
652  );
653 };
654 
655 
656 
657 
cFinishGenOres Super
Definition: FinishGen.h:605
FoliageInfo(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_Weight)
Definition: FinishGen.h:84
cFinishGenOres Super
Definition: FinishGen.h:580
cFinishGen Super
Definition: FinishGen.h:490
eDimension
Dimension of a world.
Definition: BlockID.h:1127
cFinishGenSingleTopBlock(int a_Seed, BLOCKTYPE a_BlockType, BiomeList a_Biomes, int a_Amount, BlockList a_AllowedBelow)
Definition: FinishGen.h:308
cNoise m_Noise
Definition: FinishGen.h:230
BLOCKTYPE BlockTypes[NumBlocks]
The type used for block type operations and storage, AXIS_ORDER ordering.
Definition: ChunkDef.h:150
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
std::vector< OreInfo > OreInfos
Definition: FinishGen.h:520
cFinishGenVines(int a_Seed, int a_Level)
Definition: FinishGen.h:221
bool IsAllowedBlockBelow(BLOCKTYPE a_BlockBelow)
Returns true if the given blocktype may be below m_BlockType.
Definition: FinishGen.h:358
std::vector< BiomeInfo > m_FlowersPerBiome
Definition: FinishGen.h:128
BiomeInfo(int a_MinNumClumpsPerChunk, int a_MaxNumClumpsPerChunk, std::vector< FoliageInfo > a_Blocks)
Definition: FinishGen.h:104
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:21
Base class for generators that have an ore list attached to them.
Definition: FinishGen.h:487
unsigned char HEIGHTTYPE
The type used by the heightmap.
Definition: ChunkDef.h:48
cProbabDistrib m_HeightDistribution
Definition: FinishGen.h:435
cNoise m_Noise
The noise used for generating.
Definition: FinishGen.h:555
eMonsterType
Identifies individual monster type, as well as their network type-ID.
Definition: MonsterTypes.h:10
OreInfo(BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta, int a_MaxHeight, int a_NumNests, int a_NestSize)
Definition: FinishGen.h:510
NIBBLETYPE m_BlockMeta
Definition: FinishGen.h:496
This class adds a single top block in random positions in the specified biome on top of specified all...
Definition: FinishGen.h:297
cFinishGenClumpTopBlock(int a_Seed, std::vector< BiomeInfo > a_BlockList)
Definition: FinishGen.h:112
cFinishGenBottomLava(int a_Level)
Definition: FinishGen.h:376
cNoise m_Noise
The noise used as the source of randomness.
Definition: FinishGen.h:462
int m_Amount
Relative amount of blocks to try adding.
Definition: FinishGen.h:346
virtual void GenFinish(cChunkDesc &a_ChunkDesc) override
Definition: FinishGen.cpp:945
Definition: Noise.h:19
int m_Chance
Chance, [0..100], that a spring will be generated in a chunk.
Definition: FinishGen.h:437
int GetBiomeDensity(EMCSBiome a_Biome)
Definition: FinishGen.h:182
cFinishGenOrePockets(int a_Seed, const OreInfos &a_OreInfos)
Definition: FinishGen.h:608
std::vector< BLOCKTYPE > BlockList
Definition: FinishGen.h:301
std::string AString
Definition: StringUtils.h:13
OreInfos m_OreInfos
All the ores enabled in this generator.
Definition: FinishGen.h:558
std::vector< EMCSBiome > BiomeList
Definition: FinishGen.h:304
cFinishGenNetherClumpFoliage(int a_Seed)
Definition: FinishGen.h:55
std::vector< FoliageInfo > m_Blocks
Definition: FinishGen.h:96
cFinishGenTallGrass(int a_Seed)
Definition: FinishGen.h:173
cFinishGenOres(int a_Seed, const OreInfos &a_OreInfos)
Definition: FinishGen.h:522
cFinishGenSoulsandRims(int a_Seed)
Definition: FinishGen.h:244
bool IsAllowedBiome(EMCSBiome a_Biome)
Returns true if the given biome is a biome that is allowed.
Definition: FinishGen.h:352
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:142
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:147
The interface that a finisher must implement Finisher implements changes to the chunk after the rough...
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
Definition: Globals.h:290
cFinishGenSprinkleFoliage(int a_Seed, int a_MaxCactusHeight, int a_MaxSugarcaneHeight)
Definition: FinishGen.h:263
int m_AnimalProbability
Chance, [0..100], that an animal pack will be generated in a chunk.
Definition: FinishGen.h:465
int GetLevel(void) const
Definition: FinishGen.h:381
cFinishGenOreNests(int a_Seed, const OreInfos &a_OreInfos)
Definition: FinishGen.h:583
This class populates generated chunks with packs of biome-dependant animals Animals: cows...
Definition: FinishGen.h:452
cFinishGenGlowStone(int a_Seed)
Definition: FinishGen.h:151