From a40ed8bd0dd5402a3ce9b89940e4a7e505505788 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 22 Feb 2012 16:11:10 +0000 Subject: WorldGenerator: fixed small foliage - cacti now generate only at beaches, not underwater. git-svn-id: http://mc-server.googlecode.com/svn/trunk@316 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cWorldGenerator.cpp | 65 +++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/source/cWorldGenerator.cpp b/source/cWorldGenerator.cpp index c933cf804..8722372c4 100644 --- a/source/cWorldGenerator.cpp +++ b/source/cWorldGenerator.cpp @@ -258,23 +258,37 @@ void cWorldGenerator::GenerateTerrain(int a_ChunkX, int a_ChunkY, int a_ChunkZ, { // Replace top dirt with grass: a_BlockData[MakeIndex(x, Top - 1, z)] = E_BLOCK_GRASS; - } - else - { - // Add water up to the WATER_LEVEL: - for (int y = Top; y < WATER_LEVEL; ++y ) + + // Generate small foliage (1-block): + int TopY = Top - 1; + float val1 = Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f ); + float val2 = Noise.CubicNoise2D(xx * 0.01f, zz * 0.01f ); + float val3 = Noise.CubicNoise2D(xx * 0.01f + 10, zz * 0.01f + 10 ); + float val4 = Noise.CubicNoise2D(xx * 0.05f + 20, zz * 0.05f + 20 ); + if ((val3 > 0.2f) && ((r1.randInt()%128) > 124)) { - a_BlockData[ MakeIndex(x, y, z) ] = E_BLOCK_STATIONARY_WATER; + a_BlockData[ MakeIndex(x, TopY + 1, z) ] = E_BLOCK_YELLOW_FLOWER; } - } - - // Generate small foliage (1-block): - int index = MakeIndex(x, Top - 1, z); - int TopY = Top - 1; - float val1 = Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f ); - float val2 = Noise.CubicNoise2D(xx * 0.01f, zz * 0.01f ); - if( a_BlockData[index] == E_BLOCK_SAND ) + else if ((val4 > 0.2f) && ((r1.randInt() % 128) > 124)) + { + a_BlockData[ MakeIndex(x, TopY + 1, z) ] = E_BLOCK_RED_ROSE; + } + else if ((val1 + val2 + val3 + val4 > 0.2f) && ((r1.randInt() % 128) > 124)) + { + a_BlockData[ MakeIndex(x, TopY + 1, z) ] = E_BLOCK_RED_MUSHROOM; + } + else if ((val1 + val2 + val3 + val4 > 0.2f) && ((r1.randInt() % 128) > 124)) + { + a_BlockData[ MakeIndex(x, TopY + 1, z) ] = E_BLOCK_BROWN_MUSHROOM; + } + } // if (Top above beach-level) + else if (Top > WATER_LEVEL) { + // This is the sandy shore, generate cacti here + int index = MakeIndex(x, Top - 1, z); + int TopY = Top - 1; + float val1 = Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f ); + float val2 = Noise.CubicNoise2D(xx * 0.01f, zz * 0.01f ); if ((val1 + val2 > 0.f) && ((r1.randInt() % 128) > 124)) { a_BlockData[ MakeIndex(x, TopY + 1, z) ] = E_BLOCK_CACTUS; @@ -285,27 +299,14 @@ void cWorldGenerator::GenerateTerrain(int a_ChunkX, int a_ChunkY, int a_ChunkZ, continue; } } - else if( a_BlockData[index] == E_BLOCK_GRASS ) + else { - float val3 = Noise.CubicNoise2D(xx * 0.01f + 10, zz * 0.01f + 10 ); - float val4 = Noise.CubicNoise2D(xx * 0.05f + 20, zz * 0.05f + 20 ); - if( val3 > 0.2f && (r1.randInt()%128) > 124 ) - { - a_BlockData[ MakeIndex(x, TopY+1, z) ] = E_BLOCK_YELLOW_FLOWER; - } - else if( val4 > 0.2f && (r1.randInt()%128) > 124 ) - { - a_BlockData[ MakeIndex(x, TopY+1, z) ] = E_BLOCK_RED_ROSE; - } - else if( val1+val2+val3+val4 > 0.2f && (r1.randInt()%128) > 124 ) - { - a_BlockData[ MakeIndex(x, TopY+1, z) ] = E_BLOCK_RED_MUSHROOM; - } - else if( val1+val2+val3+val4 > 0.2f && (r1.randInt()%128) > 124 ) + // Add water up to the WATER_LEVEL: + for (int y = Top; y < WATER_LEVEL; ++y ) { - a_BlockData[ MakeIndex(x, TopY+1, z) ] = E_BLOCK_BROWN_MUSHROOM; + a_BlockData[ MakeIndex(x, y, z) ] = E_BLOCK_STATIONARY_WATER; } - } + } // else (Top is under waterlevel) } // for x } // for z } -- cgit v1.2.3