fCraft.Forester.FindTrees C# (CSharp) Method

FindTrees() private static method

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

            for ( int x = 0; x < args.Map.Width; x++ ) {
                for ( int z = 0; z < args.Map.Length; z++ ) {
                    int y = args.Map.Height - 1;
                    while ( true ) {
                        int foliagetop = args.Map.SearchColumn( x, z, args.FoliageBlock, y );
                        if ( foliagetop < 0 )
                            break;
                        y = foliagetop;
                        Vector3I trunktop = new Vector3I( x, y - 1, z );
                        int height = DistanceToBlock( args.Map, new Vector3F( trunktop ), Vector3F.Down, args.TrunkBlock, true );
                        if ( height == 0 ) {
                            y--;
                            continue;
                        }
                        y -= height;
                        if ( args.Height > 0 ) {
                            height = args.Rand.Next( treeheight - args.HeightVariation,
                                                     treeheight + args.HeightVariation + 1 );
                        }
                        treelist.Add( new Tree {
                            Args = args,
                            Pos = new Vector3I( x, y, z ),
                            Height = height
                        } );
                        y--;
                    }
                }
            }
        }