public static int EstimatedGlobalNumberOfSites(WorldGeneratorContext context, WorldGeneratorSettings.AlgorithmParameters parameters, PointOfInterestTemplate poiTemplate)
        {
            int value  = parameters.GetValue("MapSizeSensitivity");
            int value2 = parameters.GetValue("EmpireCountSensitivity");
            int strategicResourcesAbundancePercent = context.Settings.StrategicResourcesAbundancePercent;

            if (strategicResourcesAbundancePercent <= 0)
            {
                return(0);
            }
            int num = (from d in context.Districts.Values
                       where d.Content == District.Contents.Land
                       select d).Sum((District d) => d.Count) / 20;
            int num2 = (num - 100) * value / 100;

            num = 100 + num2;
            int num3 = context.EmpiresCount * 25;

            num2 = (num3 - 100) * value2 / 100;
            num3 = 100 + num2;
            int num4;

            if (!int.TryParse(poiTemplate.GetPropertyValue("NormalQuantity"), out num4))
            {
                num4 = 1;
            }
            else if (num4 == 0)
            {
                return(0);
            }
            num4 *= strategicResourcesAbundancePercent * num * num3;
            num4 /= 1000000;
            if (context.OceanicResourceCounts != null && context.OceanicResourceCounts.ContainsKey(poiTemplate.GetPropertyValue("ResourceName")))
            {
                int num5 = context.OceanicResourceCounts[poiTemplate.GetPropertyValue("ResourceName")];
                num4 -= num5;
            }
            return(num4);
        }
        public override void Execute(object context)
        {
            base.Execute(context);
            string key = "DistributeVillages";

            WorldGeneratorSettings.AlgorithmParameters algorithmParameters = null;
            if (base.Context.Settings.Algorithms.ContainsKey(key))
            {
                algorithmParameters = base.Context.Settings.Algorithms[key];
            }
            this.FactionCounter    = new Dictionary <string, int>();
            this.MinorFactionNames = new List <string>(from poi in base.Context.Settings.POITemplates.Values
                                                       where poi.GetPropertyValue("Type") == "Village"
                                                       where poi.HasProperty("AffinityMapping")
                                                       select poi.GetPropertyValue("AffinityMapping")).Distinct <string>().ToList <string>();
            if (this.MinorFactionNames.Count < 1)
            {
                return;
            }
            int num  = 1;
            int num2 = 3;
            int num3 = 1;
            int num4 = 1;

            if (algorithmParameters != null)
            {
                int value  = algorithmParameters.GetValue("MinSitesPerEmptyRegion");
                int value2 = algorithmParameters.GetValue("MaxSitesPerEmptyRegion");
                num  = Math.Min(value, value2);
                num2 = Math.Max(value, value2);
                int value3 = algorithmParameters.GetValue("MinSitesPerSpawnRegion");
                value2 = algorithmParameters.GetValue("MaxSitesPerSpawnRegion");
                num3   = Math.Min(value3, value2);
                num4   = Math.Max(value3, value2);
            }
            List <Region> list;

            if (!base.Context.Settings.XephiWorldGeneratorBalance)
            {
                list = new List <Region>(from r in base.Context.Regions.Values
                                         where r.LandMassType == Region.LandMassTypes.Continent
                                         where !base.Context.SpawnRegions.Contains(r.Id)
                                         orderby r.HexCount()
                                         select r);
            }
            else
            {
                list = new List <Region>(from r in base.Context.Regions.Values
                                         where r.LandMassType == Region.LandMassTypes.Continent
                                         where !base.Context.SpawnRegions.Contains(r.Id)
                                         orderby r.Resources.Count descending
                                         select r);
            }
            List <Region> list2;

            if (!base.Context.Settings.XephiWorldGeneratorBalance)
            {
                list2 = new List <Region>(from i in base.Context.SpawnRegions
                                          let r = base.Context.Regions[i]
                                                  where r.LandMassType == Region.LandMassTypes.Continent
                                                  orderby r.HexCount()
                                                  select r);
            }
            else
            {
                list2 = new List <Region>(from i in base.Context.SpawnRegions
                                          let r = base.Context.Regions[i]
                                                  where r.LandMassType == Region.LandMassTypes.Continent
                                                  orderby r.Resources.Count descending
                                                  select r);
            }
            this.ForbiddenContinents = new Dictionary <string, HashSet <int> >();
            foreach (string key2 in this.MinorFactionNames)
            {
                if (!this.FactionCounter.ContainsKey(key2))
                {
                    this.FactionCounter.Add(key2, 0);
                }
                if (!this.ForbiddenContinents.ContainsKey(key2))
                {
                    this.ForbiddenContinents.Add(key2, new HashSet <int>());
                }
            }
            this.ApplyScenarioRules();
            foreach (Region region in list)
            {
                float num5 = (float)list.IndexOf(region) / (float)list.Count;
                region.Villages = (int)(num5 * (float)(num2 - num + 1)) + num;
                if (region.Villages > 0)
                {
                    this.SpawnVillageInRegion(region);
                }
            }
            foreach (Region region2 in list2)
            {
                float num6 = (float)list2.IndexOf(region2) / (float)list2.Count;
                region2.Villages = (int)(num6 * (float)(num4 - num3 + 1)) + num3;
                if (region2.Villages > 0)
                {
                    this.SpawnVillageInRegion(region2);
                }
            }
            foreach (Region region3 in from r in base.Context.Regions.Values
                     where r.LandMassType == Region.LandMassTypes.Continent
                     select r)
            {
                base.Trace(string.Format("Region {0} in continent {1} : {2} villages of {3}", new object[]
                {
                    region3.Id,
                    region3.LandMassIndex,
                    region3.Villages,
                    region3.MinorFactionName
                }));
            }
        }