void PlantShrooms() {
Random shroomRand = new Random( random.Next() );
int maxShrooms = genParams.MapWidth*genParams.MapLength*genParams.MapHeight/genParams.ShroomClusterDensity;
for( int cluster = 0; cluster < maxShrooms; cluster++ ) {
int shroomType = shroomRand.Next( 2 );
int clusterX = shroomRand.Next( genParams.MapWidth );
int clusterY = shroomRand.Next( genParams.MapLength );
int clusterZ = shroomRand.Next( genParams.MapHeight );
for( int shroom = 0; shroom < genParams.ShroomChainsPerCluster; shroom++ ) {
int x = clusterX;
int y = clusterY;
int z = clusterZ;
for( int hop = 0; hop < genParams.ShroomHopsPerChain; hop++ ) {
x += shroomRand.Next( genParams.ShroomSpreadHorizontal ) -
shroomRand.Next( genParams.ShroomSpreadHorizontal );
y += shroomRand.Next( genParams.ShroomSpreadHorizontal ) -
shroomRand.Next( genParams.ShroomSpreadHorizontal );
z += shroomRand.Next( genParams.ShroomSpreadVertical ) -
shroomRand.Next( genParams.ShroomSpreadVertical );
if( (x < 0) || (y < 0) || (z < 1) || (x >= genParams.MapWidth) || (y >= genParams.MapLength) ||
(z >= heightmap[(x + y*genParams.MapWidth)] - 1) )
continue;
int index = Index( x, y, z );
Block blockAbove = (Block)blocks[index];
if( blockAbove != Block.Air )
continue;
Block blockUnder = (Block)blocks[Index( x, y, z - 1 )];
if( blockUnder != Block.Stone )
continue;
if( shroomType == 0 ) {
blocks[index] = (byte)Block.BrownMushroom;
} else {
blocks[index] = (byte)Block.RedMushroom;
}
}
}
}
}