fCraft.Forester.Generate C# (CSharp) Method

Generate() public static method

public static Generate ( [ args ) : void
args [
return void
        public static void Generate( [NotNull] ForesterArgs args )
        {
            if ( args == null )
                throw new ArgumentNullException( "args" );
            args.Validate();
            List<Tree> treeList = new List<Tree>();

            if ( args.Operation == ForesterOperation.Conserve ) {
                FindTrees( args, treeList );
            }

            if ( args.TreeCount > 0 && treeList.Count > args.TreeCount ) {
                treeList = treeList.Take( args.TreeCount ).ToList();
            }

            if ( args.Operation == ForesterOperation.Replant || args.Operation == ForesterOperation.Add ) {
                switch ( args.Shape ) {
                    case TreeShape.Rainforest:
                        PlantRainForestTrees( args, treeList );
                        break;

                    case TreeShape.Mangrove:
                        PlantMangroves( args, treeList );
                        break;

                    default:
                        PlantTrees( args, treeList );
                        break;
                }
            }

            if ( args.Operation != ForesterOperation.ClearCut ) {
                ProcessTrees( args, treeList );
                if ( args.Foliage ) {
                    foreach ( Tree tree in treeList ) {
                        tree.MakeFoliage();
                    }
                }
                if ( args.Wood ) {
                    foreach ( Tree tree in treeList ) {
                        tree.MakeTrunk();
                    }
                }
            }
        }

Usage Example

Example #1
0
        void PlantGiantTrees()
        {
            if (genParams.GiantTreeDensity <= 0)
            {
                return;
            }
            Map outMap = new Map(null, map.Width, map.Length, map.Height, false)
            {
                Blocks = (byte[])map.Blocks.Clone()
            };
            int plantableBlocks = ComputeSurfaceCoverage(Block.Grass);
            var foresterArgs    = new ForesterArgs {
                Map       = map,
                Rand      = rand,
                TreeCount = (int)(plantableBlocks * genParams.GiantTreeDensity / BaseGiantTreeDensity),
                Operation = Forester.ForesterOperation.Add,
                PlantOn   = Block.Grass
            };

            foresterArgs.BlockPlacing += (sender, e) => outMap.SetBlock(e.Coordinate, e.Block);
            Forester.Generate(foresterArgs);
            map = outMap;
        }
All Usage Examples Of fCraft.Forester::Generate