fCraft.FloatingIslandMapGenState.PlantTrees C# (CSharp) Method

PlantTrees() public method

public PlantTrees ( ) : void
return void
        void PlantTrees() {
            if( genParams.TreeClusterDensity <= 0 ) return;
            Random treeRand = new Random( rand.Next() );
            int maxTrees = (int)Math.Round( genParams.MapWidth*genParams.MapLength*genParams.TreeClusterDensity/
                                            BaseTreeClusterDensity );
            for( int cluster = 0; cluster < maxTrees; cluster++ ) {
                int clusterX = treeRand.Next( genParams.MapWidth );
                int clusterY = treeRand.Next( genParams.MapLength );
                for( int tree = 0; tree < genParams.TreeChainsPerCluster; tree++ ) {
                    int x = clusterX;
                    int y = clusterY;
                    for( int hop = 0; hop < genParams.TreeHopsPerChain; hop++ ) {
                        x += treeRand.Next( genParams.TreeSpread ) - treeRand.Next( genParams.TreeSpread );
                        y += treeRand.Next( genParams.TreeSpread ) - treeRand.Next( genParams.TreeSpread );
                        if( (x < 0) || (y < 0) || (x >= genParams.MapWidth) || (y >= genParams.MapLength) )
                            continue;
                        if( treeRand.Next( genParams.TreePlantRatio ) != 0 )
                            continue;

                        for( int z = genParams.MapHeight - 1; z > 0; z-- ) {
                            if( map.GetBlock( x, y, z - 1 ) == Block.Grass ) {
                                GrowTree( treeRand, x, y, z );
                                break;
                            }
                        }
                    }
                }
            }
        }