Esempio n. 1
0
 public AreaOptions(Func <ILandValueCalculator> getLandValueCalculator,
                    TerraformingOptions terraformingOptions,
                    ProcessOptions processOptions,
                    Func <ICityServiceStrengthLevels> getCityServiceStrengthLevels)
     : this(getLandValueCalculator, processOptions, getCityServiceStrengthLevels)
 {
     _terraformingOptions = terraformingOptions ?? throw new ArgumentNullException(nameof(terraformingOptions));
 }
        internal void ApplyWith(ZoneInfoGrid repo, TerraformingOptions options)
        {
            ScatterZoneConsumptionClouds(
                repo: repo,
                options: options,
                random: _random,
                valueSelector: o => o.Woodlands,
                createZoneConsumption: _woodlandZoneFactory
                );
            ScatterZoneConsumptionClouds(
                repo: repo,
                options: options,
                random: _random,
                valueSelector: o => o.Lakes,
                createZoneConsumption: _waterZoneFactory
                );

            if (options.HorizontalRiver)
            {
                GenerateRiver(repo: repo, isHorizontal: true);
            }
            if (options.VerticalRiver)
            {
                GenerateRiver(repo: repo, isHorizontal: false);
            }
            if (options.EastCoast)
            {
                GenerateCoastLine(
                    repo: repo,
                    zonePointCoordinateSelector: x => x.X,
                    pointValueSelector: x => x.Max()
                    );
            }
            if (options.WestCoast)
            {
                GenerateCoastLine(
                    repo: repo,
                    zonePointCoordinateSelector: x => x.X,
                    pointValueSelector: x => x.Min()
                    );
            }
            if (options.SouthCoast)
            {
                GenerateCoastLine(
                    repo: repo,
                    zonePointCoordinateSelector: x => x.Y,
                    pointValueSelector: x => x.Max()
                    );
            }
            if (options.NorthCoast)
            {
                GenerateCoastLine(
                    repo: repo,
                    zonePointCoordinateSelector: x => x.Y,
                    pointValueSelector: x => x.Min()
                    );
            }
        }
        internal static void ScatterZoneConsumptionClouds(
            ZoneInfoGrid repo,
            TerraformingOptions options,
            Random random,
            Func <TerraformingOptions, int> valueSelector,
            Func <IAreaZoneConsumption> createZoneConsumption)
        {
            foreach (var iteration in Enumerable.Range(0, valueSelector(options)))
            {
                var woodlandTargetPoint = repo.ZoneInfos[new ZonePoint
                                                         {
                                                             X = random.Next(10, (repo.ZoneWidthAndHeight - 10)),
                                                             Y = random.Next(10, (repo.ZoneWidthAndHeight - 10))
                                                         }];

                foreach (var subiteration in Enumerable.Range(0, 4))
                {
                    var center = woodlandTargetPoint
                                 .GetRelativeZoneInfo(new RelativeZoneInfoQuery(
                                                          relativeX: random.Next(-3, 3),
                                                          relativeY: random.Next(-3, 3)

                                                          )
                                                      );

                    if (center.HasNoMatch)
                    {
                        continue;
                    }

                    var targets = center.MatchingObject.GetSurroundingZoneInfosDiamond(3);

                    foreach (var target in targets
                             .Where(x => x.HasMatch))
                    {
                        var action = target.MatchingObject.ConsumptionState
                                     .TryConsumeWith(createZoneConsumption());

                        if (action.CanOverrideWithResult.WillSucceed)
                        {
                            action.Apply();
                        }
                    }
                }
            }
        }