fCraft.Forester.PlantMangroves C# (CSharp) Method

PlantMangroves() private static method

private static PlantMangroves ( ForesterArgs args, ICollection treelist ) : void
args ForesterArgs
treelist ICollection
return void
        private static void PlantMangroves( ForesterArgs args, ICollection<Tree> treelist )
        {
            int treeheight = args.Height;

            int attempts = 0;
            while ( treelist.Count < args.TreeCount && attempts < MaxTries ) {
                attempts++;
                int height = args.Rand.Next( treeheight - args.HeightVariation,
                                             treeheight + args.HeightVariation + 1 );
                int padding = ( int )( height / 3f + 1 );
                int mindim = Math.Min( args.Map.Width, args.Map.Length );
                if ( padding > mindim / 2.2 ) {
                    padding = ( int )( mindim / 2.2 );
                }
                int x = args.Rand.Next( padding, args.Map.Width - padding - 1 );
                int z = args.Rand.Next( padding, args.Map.Length - padding - 1 );
                int top = args.Map.Height - 1;

                int y = top - DistanceToBlock( args.Map, new Vector3F( x, z, top ), Vector3F.Down, Block.Air, true );
                int dist = DistanceToBlock( args.Map, new Vector3F( x, z, y ), Vector3F.Down, Block.Water, true );

                if ( dist > height * .618 || dist == 0 ) {
                    continue;
                }

                y += ( int )Math.Sqrt( height - dist ) + 2;
                treelist.Add( new Tree {
                    Args = args,
                    Height = height,
                    Pos = new Vector3I( x, y, z )
                } );
            }
        }