Index: source/Generating/ChunkGenerator.cpp =================================================================== --- source/Generating/ChunkGenerator.cpp (revision 1038) +++ source/Generating/ChunkGenerator.cpp (working copy) @@ -340,7 +340,7 @@ void cChunkGenerator::InitFinishGens(cIniFile & a_IniFile) { - AString Structures = a_IniFile.GetValueSet("Generator", "Finishers", "SprinkleFoliage,Ice,Snow,Lilypads,BottomLava,DeadBushes,PreSimulator"); + AString Structures = a_IniFile.GetValueSet("Generator", "Finishers", "SprinkleFoliage,Ice,Snow,Lilypads,BottomLava,DeadBushes,PreSimulator,Cactus"); AStringVector Str = StringSplit(Structures, ","); for (AStringVector::const_iterator itr = Str.begin(); itr != Str.end(); ++itr) @@ -351,6 +351,10 @@ int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", 10); m_FinishGens.push_back(new cFinishGenBottomLava(BottomLavaLevel)); } + else if (NoCaseCompare(*itr, "Cactus") == 0) + { + m_FinishGens.push_back(new cFinishGenCactus(m_Seed)); + } else if (NoCaseCompare(*itr, "DeadBushes") == 0) { m_FinishGens.push_back(new cFinishGenDeadBushes(m_Seed)); Index: source/Generating/FinishGen.cpp =================================================================== --- source/Generating/FinishGen.cpp (revision 1038) +++ source/Generating/FinishGen.cpp (working copy) @@ -613,3 +613,69 @@ } // for i } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cFinishGenCactus: + +int cFinishGenCactus::GetNumCactus(const cChunkDef::BiomeMap & a_BiomeMap) +{ + int res = 0; + for (int i = 0; i < ARRAYCOUNT(a_BiomeMap); i++) + { + if (a_BiomeMap[i] == biDesert) + { + res++; + } + } // for i - a_BiomeMap[] + return res / 256; +} + + + + + +void cFinishGenCactus::GenFinish( + int a_ChunkX, int a_ChunkZ, + cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change + cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change + cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data + const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to + cEntityList & a_Entities, // Entities may be added or deleted + cBlockEntityList & a_BlockEntities // Block entities may be added or deleted +) +{ + // Add DeadBushes on top of sand surface in Desert + + int NumCactus = GetNumCactus(a_BiomeMap); + for (int i = 0; i < NumCactus; i++) + { + int x = (m_Noise.IntNoise3DInt(a_ChunkX + a_ChunkZ, a_ChunkZ, i) / 13) % cChunkDef::Width; + int z = (m_Noise.IntNoise3DInt(a_ChunkX - a_ChunkZ, i, a_ChunkZ) / 11) % cChunkDef::Width; + + // Place a dead bush at {x, z} if possible (desert, empty block, sand below): + if (cChunkDef::GetBiome(a_BiomeMap, x, z) != biDesert) + { + // not swampland + continue; + } + int Height = cChunkDef::GetHeight(a_HeightMap, x, z); + if (Height >= cChunkDef::Height) + { + // Too high up + continue; + } + if (cChunkDef::GetBlock(a_BlockTypes, x, Height + 1, z) != E_BLOCK_AIR) + { + // not empty block + continue; + } + switch (cChunkDef::GetBlock(a_BlockTypes, x, Height, z)) + { + case E_BLOCK_SAND: + { + cChunkDef::SetBlock(a_BlockTypes, x, Height + 1, z, E_BLOCK_CACTUS); + cChunkDef::SetHeight(a_HeightMap, x, z, Height + 1); + break; + } + } // switch (GetBlock) + } // for i +} \ No newline at end of file Index: source/Generating/FinishGen.h =================================================================== --- source/Generating/FinishGen.h (revision 1038) +++ source/Generating/FinishGen.h (working copy) @@ -9,6 +9,7 @@ - cFinishGenBottomLava - cFinishGenPreSimulator - cFinishGenDeadBushes + - cFinishGenCactus */ @@ -21,7 +22,7 @@ - +//Snow class cFinishGenSnow : public cFinishGen { @@ -41,7 +42,7 @@ - +//Ice class cFinishGenIce : public cFinishGen { @@ -61,7 +62,7 @@ - +//SprinkleFoliage class cFinishGenSprinkleFoliage : public cFinishGen { @@ -94,7 +95,7 @@ - +//Lilypads class cFinishGenLilypads : public cFinishGen { @@ -124,7 +125,7 @@ - +//BottomLava class cFinishGenBottomLava : public cFinishGen { @@ -152,7 +153,7 @@ - +//PreSimulator class cFinishGenPreSimulator : public cFinishGen { @@ -192,7 +193,36 @@ +// Cactus +class cFinishGenCactus : + public cFinishGen +{ +public: + cFinishGenCactus(int a_Seed) : + m_Noise(a_Seed) + { + } + +protected: + cNoise m_Noise; + + int GetNumCactus(const cChunkDef::BiomeMap & a_BiomeMap); + + // cFinishGen override: + virtual void GenFinish( + int a_ChunkX, int a_ChunkZ, + cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change + cChunkDef::BlockNibbles & a_BlockMeta, // Block meta to read and change + cChunkDef::HeightMap & a_HeightMap, // Height map to read and change by the current data + const cChunkDef::BiomeMap & a_BiomeMap, // Biomes to adhere to + cEntityList & a_Entities, // Entities may be added or deleted + cBlockEntityList & a_BlockEntities // Block entities may be added or deleted + ) override; +} ; + +//DeadBushes + class cFinishGenDeadBushes : public cFinishGen { @@ -217,9 +247,4 @@ cEntityList & a_Entities, // Entities may be added or deleted cBlockEntityList & a_BlockEntities // Block entities may be added or deleted ) override; -} ; - - - - - +} ; \ No newline at end of file