fCraft.MapGeneration.ForesterArgs.Validate C# (CSharp) Method

Validate() private method

private Validate ( ) : void
return void
        internal void Validate() {
            if (TreeCount < 0) TreeCount = 0;
            if (Height < 1) Height = 1;
            if (HeightVariation > Height) HeightVariation = Height;
            if (TrunkThickness < 0) TrunkThickness = 0;
            if (TrunkHeight < 0) TrunkHeight = 0;
            if (FoliageDensity < 0) FoliageDensity = 0;
            if (BranchDensity < 0) BranchDensity = 0;
        }
    }

Usage Example

Example #1
0
        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)
            {
                return;
            }

            ProcessTrees(args, treeList);
            if (args.Foliage)
            {
                foreach (Tree tree in treeList)
                {
                    tree.MakeFoliage();
                }
            }
            if (args.Wood)
            {
                foreach (Tree tree in treeList)
                {
                    tree.MakeTrunk();
                }
            }
        }