diff options
Diffstat (limited to 'src/Generating')
-rw-r--r-- | src/Generating/CompoGen.cpp | 11 | ||||
-rw-r--r-- | src/Generating/CompoGen.h | 2 | ||||
-rw-r--r-- | src/Generating/ComposableGenerator.cpp | 6 | ||||
-rw-r--r-- | src/Generating/FinishGen.cpp | 114 | ||||
-rw-r--r-- | src/Generating/FinishGen.h | 22 |
5 files changed, 146 insertions, 9 deletions
diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp index cb9c04fd7..7cadc881a 100644 --- a/src/Generating/CompoGen.cpp +++ b/src/Generating/CompoGen.cpp @@ -218,7 +218,7 @@ void cCompoGenClassic::InitializeCompoGen(cIniFile & a_IniFile) cCompoGenNether::cCompoGenNether(int a_Seed) : m_Noise1(a_Seed + 10), m_Noise2(a_Seed * a_Seed * 10 + a_Seed * 1000 + 6000), - m_Threshold(0) + m_MaxThreshold(25000) { } @@ -282,17 +282,16 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc: // Interpolate between FloorLo and FloorHi: for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) { + int Threshold = static_cast<int>(m_Noise1.CubicNoise2D(static_cast<float>(BaseX + x) / 75, static_cast<float>(BaseZ + z) / 75) * m_MaxThreshold); int Lo = FloorLo[x + 17 * z] / 256; int Hi = FloorHi[x + 17 * z] / 256; for (int y = 0; y < SEGMENT_HEIGHT; y++) { int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; - BLOCKTYPE Block = E_BLOCK_AIR; - if (Val < m_Threshold) // Don't calculate if the block should be Netherrack or Soulsand when it's already decided that it's air. + if (Val < Threshold) // Don't calculate if the block should be Netherrack when it's already decided that it's air. { - Block = E_BLOCK_NETHERRACK; + a_ChunkDesc.SetBlockType(x, y + Segment, z, E_BLOCK_NETHERRACK); } - a_ChunkDesc.SetBlockType(x, y + Segment, z, Block); } } @@ -329,7 +328,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc: void cCompoGenNether::InitializeCompoGen(cIniFile & a_IniFile) { - m_Threshold = a_IniFile.GetValueSetI("Generator", "NetherThreshold", m_Threshold); + m_MaxThreshold = a_IniFile.GetValueSetF("Generator", "NetherMaxThreshold", m_MaxThreshold); } diff --git a/src/Generating/CompoGen.h b/src/Generating/CompoGen.h index 3847688cd..d4d38bfdd 100644 --- a/src/Generating/CompoGen.h +++ b/src/Generating/CompoGen.h @@ -99,7 +99,7 @@ protected: cNoise m_Noise1; cNoise m_Noise2; - int m_Threshold; + double m_MaxThreshold; // cTerrainCompositionGen overrides: virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) override; diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 4a670b064..6b7643ddb 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -347,6 +347,10 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) AString HeightDistrib = a_IniFile.GetValueSet ("Generator", "DungeonRoomsHeightDistrib", "0, 0; 10, 10; 11, 500; 40, 500; 60, 40; 90, 1"); m_FinishGens.push_back(cFinishGenPtr(new cDungeonRoomsFinisher(m_ShapeGen, Seed, GridSize, MaxSize, MinSize, HeightDistrib))); } + else if (NoCaseCompare(*itr, "GlowStone") == 0) + { + m_FinishGens.push_back(cFinishGenPtr(new cFinishGenGlowStone(Seed))); + } else if (NoCaseCompare(*itr, "Ice") == 0) { m_FinishGens.push_back(cFinishGenPtr(new cFinishGenIce)); @@ -447,7 +451,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) else if (NoCaseCompare(*itr, "NetherForts") == 0) { int GridSize = a_IniFile.GetValueSetI("Generator", "NetherFortsGridSize", 512); - int MaxOffset = a_IniFile.GetValueSetI("Generator", "NetherFortMaxOffset", 128); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxOffset", 128); int MaxDepth = a_IniFile.GetValueSetI("Generator", "NetherFortsMaxDepth", 12); m_FinishGens.push_back(cFinishGenPtr(new cNetherFortGen(Seed, GridSize, MaxOffset, MaxDepth))); } diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 5839a4ccc..7541c8598 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -180,6 +180,118 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a //////////////////////////////////////////////////////////////////////////////// +// cFinishGenGlowStone: + +void cFinishGenGlowStone::GenFinish(cChunkDesc & a_ChunkDesc) +{ + int ChunkX = a_ChunkDesc.GetChunkX(); + int ChunkZ = a_ChunkDesc.GetChunkZ(); + + // Change the number of attempts to create a vein depending on the maximum height of the chunk. A standard Nether could have 5 veins at most. + int NumGlowStone = m_Noise.IntNoise2DInt(ChunkX, ChunkZ) % a_ChunkDesc.GetMaxHeight() / 23; + + for (int i = 1; i <= NumGlowStone; i++) + { + // The maximum size for a string of glowstone can get 3 - 5 blocks long + int Size = 3 + m_Noise.IntNoise3DInt(ChunkX, i, ChunkZ) % 3; + + // Generate X/Z coordinates. + int X = Size + (m_Noise.IntNoise2DInt(i, Size) % (cChunkDef::Width - Size * 2)); + int Z = Size + (m_Noise.IntNoise2DInt(X, i) % (cChunkDef::Width - Size * 2)); + + int Height = a_ChunkDesc.GetHeight(X, Z); + for (int y = Height; y > Size; y--) + { + if (!cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(X, y, Z))) + { + // Current block isn't solid, bail out + continue; + } + + if (a_ChunkDesc.GetBlockType(X, y - 1, Z) != E_BLOCK_AIR) + { + // The block below isn't air, bail out + continue; + } + + if ((m_Noise.IntNoise3DInt(X, y, Z) % 100) < 95) + { + // Have a 5% chance of creating the glowstone + continue; + } + + TryPlaceGlowstone(a_ChunkDesc, X, y, Z, Size, 5 + m_Noise.IntNoise3DInt(X, y, Z) % 7); + break; + } + } +} + + + + + +void cFinishGenGlowStone::TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, int a_Size, int a_NumStrings) +{ + // The starting point of every glowstone string + Vector3i StartPoint = Vector3i(a_RelX, a_RelY, a_RelZ); + + // Array with possible directions for a string of glowstone to go to. + const Vector3i AvailableDirections[] = + { + { -1, 0, 0 }, { 1, 0, 0 }, + { 0, -1, 0 }, // Don't let the glowstone go up + { 0, 0, -1 }, { 0, 0, 1 }, + + // Diagonal direction. Only X or Z with Y. + // If all were changed the glowstone string looks awkward + { 0, -1, 1 }, { 1, -1, 0 }, + { 0, -1, -1 }, { -1, -1, 0 }, + + }; + + for (int i = 1; i <= a_NumStrings; i++) + { + // The current position of the string that is being generated + Vector3i CurrentPos = Vector3i(StartPoint); + + // A vector where the previous direction of a glowstone string is stored. + // This is used to make the strings change direction when going one block further + Vector3i PreviousDirection = Vector3i(); + + for (int j = 0; j < a_Size; j++) + { + Vector3i Direction = AvailableDirections[m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i, CurrentPos.z) % ARRAYCOUNT(AvailableDirections)]; + int Attempts = 2; // multiply by 1 would make no difference, so multiply by 2 instead + + while (Direction.Equals(PreviousDirection)) + { + // To make the glowstone branches look better we want to make the direction change every time. + Direction = AvailableDirections[m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i * Attempts, CurrentPos.z) % ARRAYCOUNT(AvailableDirections)]; + Attempts++; + } + + // Update the previous direction variable + PreviousDirection = Direction; + + // Update the position of the glowstone string + CurrentPos += Direction; + if (cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z)) && (a_ChunkDesc.GetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z) != E_BLOCK_GLOWSTONE)) + { + // The glowstone hit something solid, and it wasn't glowstone. Stop the string. + break; + } + + // Place a glowstone block. + a_ChunkDesc.SetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z, E_BLOCK_GLOWSTONE); + } + } +} + + + + + +//////////////////////////////////////////////////////////////////////////////// // cFinishGenTallGrass: void cFinishGenTallGrass::GenFinish(cChunkDesc & a_ChunkDesc) @@ -523,7 +635,7 @@ void cFinishGenSoulsandRims::GenFinish(cChunkDesc & a_ChunkDesc) { // The current block is air. Let's bail ut. BLOCKTYPE Block = a_ChunkDesc.GetBlockType(x, y, z); - if (Block == E_BLOCK_AIR) + if (Block != E_BLOCK_NETHERRACK) { continue; } diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index 70696c4f8..aa50335d4 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -70,6 +70,28 @@ protected: +class cFinishGenGlowStone : + public cFinishGen +{ +public: + cFinishGenGlowStone(int a_Seed) : + m_Noise(a_Seed), + m_Seed(a_Seed) + { + } + +protected: + cNoise m_Noise; + int m_Seed; + + void TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, int a_Size, int a_NumStrings); + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; +} ; + + + + + class cFinishGenTallGrass : public cFinishGen { |