Beispiel #1
0
        protected void CreateBlobs()
        {
            this.BlobMap = new Dictionary <District, CreateContinents.Blob>();
            List <District> list = new List <District>(from d in base.Context.Districts.Values
                                                       where d.Content != District.Contents.WasteNS
                                                       where d.Content != District.Contents.WasteEW
                                                       select d);
            AdHocGraph <District>    graph         = new AdHocGraph <District>(list);
            RandomScatter <District> randomScatter = new RandomScatter <District>(graph);

            randomScatter.Randomizer = base.Context.Randomizer;
            randomScatter.Shots      = Math.Min(list.Count, 500);
            randomScatter.Execute();
            SeedGrower <District, CreateContinents.Blob> seedGrower = new SeedGrower <District, CreateContinents.Blob>(graph)
            {
                Randomizer = base.Context.Randomizer,
                Blank      = null
            };

            foreach (District key in randomScatter.Impacts)
            {
                seedGrower.Seeds.Add(key, new CreateContinents.Blob(this.BlobMap));
            }
            seedGrower.Execute();
            for (int i = 0; i < seedGrower.Graph.Nodes; i++)
            {
                District district          = seedGrower.Graph.Node(i);
                CreateContinents.Blob blob = seedGrower.SeededGraph[i];
                this.BlobMap.Add(district, blob);
                blob.Districts.Add(district);
            }
            this.CoreBlobs = new List <CreateContinents.Blob>(this.BlobMap.Values.Distinct <CreateContinents.Blob>());
        }
Beispiel #2
0
        protected void MakeIslands(int islandSize, int keepPercent)
        {
            CreateContinents.< > c__DisplayClass14_0 CS$ < > 8__locals1 = new CreateContinents.< > c__DisplayClass14_0();
            CS$ < > 8__locals1.< > 4__this = this;
            CreateContinents.< > c__DisplayClass14_0  CS$ < > 8__locals2 = CS$ < > 8__locals1;
            ProximityComputer <CreateContinents.Blob> proximityComputer  = new ProximityComputer <CreateContinents.Blob>(this.BlobGraph);

            proximityComputer.StartingNodes = new List <CreateContinents.Blob>(from c in this.Continents
                                                                               from b in c.Blobs
                                                                               select b);
            CS$ < > 8__locals2.proxer = proximityComputer;
            CS$ < > 8__locals1.proxer.Execute();
            CS$ < > 8__locals1.potentialIslands = new List <CreateContinents.Blob>(from b in this.CoreBlobs
                                                                                   where CS$ < > 8__locals1.proxer.Proximity(b) > 1
                                                                                   select b);
            List <CreateContinents.Blob> list = new List <CreateContinents.Blob>();

            while (CS$ < > 8__locals1.potentialIslands.Count > 0 && this.Continents.Count < 254)
            {
                List <CreateContinents.Blob> island = new List <CreateContinents.Blob>();
                CreateContinents.Blob        blob   = CS$ < > 8__locals1.potentialIslands.ElementAt(base.Context.Randomizer.Next(CS$ < > 8__locals1.potentialIslands.Count));
                CS$ < > 8__locals1.potentialIslands.Remove(blob);
                island.Add(blob);
                list.Clear();
                List <CreateContinents.Blob>        list2  = list;
                IEnumerable <CreateContinents.Blob> source = this.BlobGraph.Adjacents(blob);
                Func <CreateContinents.Blob, bool>  predicate;
                if ((predicate = CS$ < > 8__locals1.< > 9__3) == null)
                {
                    predicate = (CS$ < > 8__locals1.< > 9__3 = ((CreateContinents.Blob n) => CS$ < > 8__locals1.potentialIslands.Contains(n)));
                }
                list2.AddRange(source.Where(predicate));
                while (list.Count > 0)
                {
                    if (island.Sum((CreateContinents.Blob b) => b.Districts.Sum((District d) => d.Count)) >= islandSize)
                    {
                        break;
                    }
                    CreateContinents.Blob item = list.ElementAt(base.Context.Randomizer.Next(list.Count));
                    island.Add(item);
                    CS$ < > 8__locals1.potentialIslands.Remove(item);
                    list.Clear();
                    List <CreateContinents.Blob> list3 = list;
                    var source2 = from b in island
                                  from n in this.BlobGraph.Adjacents(b)
                                  select new
                    {
                        b,
                        n
                    };
                    var predicate2;
                    if ((predicate2 = CS$ < > 8__locals1.< > 9__6) == null)
                    {
                        predicate2 = (CS$ < > 8__locals1.< > 9__6 = (< > h__TransparentIdentifier0 => CS$ < > 8__locals1.potentialIslands.Contains(< > h__TransparentIdentifier0.n)));
                    }
                    list3.AddRange(from <> h__TransparentIdentifier0 in source2.Where(predicate2)
                                   select <> h__TransparentIdentifier0.n);
                }
                if (island.Count > 0)
                {
                    if (island.Sum((CreateContinents.Blob b) => b.Districts.Sum((District d) => d.Count)) < 3 * islandSize)
                    {
                        if (island.Sum((CreateContinents.Blob b) => b.Districts.Sum((District d) => d.Count)) > islandSize && base.Context.Randomizer.Next(100) < keepPercent)
                        {
                            CreateContinents.Continent continent = new CreateContinents.Continent(this.BlobGraph);
                            this.Continents.Add(continent);
                            island.ForEach(delegate(CreateContinents.Blob b)
                            {
                                b.Content = District.Contents.Land;
                            });
                            island.ForEach(delegate(CreateContinents.Blob b)
                            {
                                b.Districts.ForEach(delegate(District d)
                                {
                                    d.Content = District.Contents.Land;
                                });
                            });
                            continent.Blobs.UnionWith(island);
                            Func <CreateContinents.Blob, bool> < > 9__18;
                            CS$ < > 8__locals1.potentialIslands.RemoveAll(delegate(CreateContinents.Blob b)
                            {
                                IEnumerable <CreateContinents.Blob> source3 = CS$ < > 8__locals1.< > 4__this.BlobGraph.Adjacents(b);
                                Func <CreateContinents.Blob, bool> predicate3;
                                if ((predicate3 = < > 9__18) == null)
                                {
                                    predicate3 = (< > 9__18 = ((CreateContinents.Blob n) => island.Contains(n)));
                                }
                                return(source3.Any(predicate3));
                            });
                        }
                    }
                }
            }
        }
Beispiel #3
0
        protected void GrowSmoothLandMasses(WorldGeneratorSettings.ContinentStyles shaping, WorldGeneratorSettings.ContinentStyles spreading)
        {
            this.AvailableBlobs = new HashSet <CreateContinents.Blob>(this.CoreBlobs);
            this.Influencer     = new IncrementalInfluencer <CreateContinents.Blob>(this.BlobGraph);
            List <CreateContinents.Blob> list = new List <CreateContinents.Blob>(this.AvailableBlobs);
            Dictionary <CreateContinents.Continent, Dictionary <CreateContinents.Blob, int> > valuations = new Dictionary <CreateContinents.Continent, Dictionary <CreateContinents.Blob, int> >();

            foreach (CreateContinents.Continent continent in this.Continents)
            {
                CreateContinents.Blob blob3 = null;
                if (spreading == WorldGeneratorSettings.ContinentStyles.Regular)
                {
                    List <CreateContinents.Blob> list2 = this.Influencer.FarthestNodes();
                    blob3 = list2.ElementAt(base.Context.Randomizer.Next(list2.Count));
                    this.Influencer.Add(blob3);
                }
                else if (list.Count > 0)
                {
                    blob3 = list.ElementAt(base.Context.Randomizer.Next(list.Count));
                }
                if (!base.Context.Settings.WorldWrap && this.Continents.Count == 1)
                {
                    HexPos mapCenter = new HexPos(base.Context.Grid.Columns / 2, base.Context.Grid.Rows / 2);
                    Func <District, bool> < > 9__1;
                    blob3 = this.CoreBlobs.Find(delegate(CreateContinents.Blob b)
                    {
                        IEnumerable <District> districts = b.Districts;
                        Func <District, bool> predicate;
                        if ((predicate = < > 9__1) == null)
                        {
                            predicate = (< > 9__1 = ((District d) => d.Contains(mapCenter)));
                        }
                        return(districts.Any(predicate));
                    });
                }
                if (blob3 != null)
                {
                    this.AvailableBlobs.Remove(blob3);
                    continent.Blobs.Add(blob3);
                    list.Remove(blob3);
                    foreach (CreateContinents.Blob item in this.BlobGraph.Adjacents(blob3))
                    {
                        list.Remove(item);
                    }
                    valuations.Add(continent, new Dictionary <CreateContinents.Blob, int>());
                    continent.ProxBlober.StartingNodes.Add(blob3);
                    continent.ProxBlober.Execute();
                    continent.ComputeInfluence();
                }
            }
            foreach (CreateContinents.Continent continent2 in this.Continents)
            {
                Dictionary <CreateContinents.Blob, int> dictionary = valuations[continent2];
                List <CreateContinents.Continent>       list3      = new List <CreateContinents.Continent>(this.Continents);
                list3.Remove(continent2);
                using (HashSet <CreateContinents.Blob> .Enumerator enumerator3 = this.AvailableBlobs.GetEnumerator())
                {
                    while (enumerator3.MoveNext())
                    {
                        CreateContinents.Blob blob = enumerator3.Current;
                        if (list3.Count > 0)
                        {
                            dictionary.Add(blob, list3.Min((CreateContinents.Continent k) => k.ProxBlober.Proximity(blob)));
                        }
                        else
                        {
                            dictionary.Add(blob, 0);
                        }
                        Dictionary <CreateContinents.Blob, int> dictionary2 = dictionary;
                        CreateContinents.Blob blob2 = blob;
                        dictionary2[blob2] -= continent2.ProxBlober.Proximity(blob);
                        if (shaping == WorldGeneratorSettings.ContinentStyles.Chaotic)
                        {
                            dictionary2         = dictionary;
                            blob2               = blob;
                            dictionary2[blob2] += base.Context.Randomizer.Next(8) - base.Context.Randomizer.Next(8);
                        }
                    }
                }
            }
            bool flag = true;

            for (;;)
            {
                if (this.Continents.Sum((CreateContinents.Continent k) => k.HexCount) >= this.ExpectedLandHexes || !flag)
                {
                    break;
                }
                flag = false;
                List <CreateContinents.Continent> source = new List <CreateContinents.Continent>(from k in this.Continents
                                                                                                 orderby k.WeightedHexCount
                                                                                                 select k);
                CreateContinents.Continent        smallest = source.First <CreateContinents.Continent>();
                List <CreateContinents.Continent> others   = new List <CreateContinents.Continent>(this.Continents);
                others.Remove(smallest);
                List <CreateContinents.Blob> list4 = new List <CreateContinents.Blob>(from b in this.AvailableBlobs
                                                                                      where b.Neighbours.Any((CreateContinents.Blob n) => smallest.Blobs.Contains(n))
                                                                                      where !others.Any((CreateContinents.Continent k) => k.Influence.Contains(b))
                                                                                      orderby valuations[smallest][b] descending
                                                                                      select b);
                if (list4.Count > 0)
                {
                    flag = true;
                    CreateContinents.Blob item2 = list4.First <CreateContinents.Blob>();
                    smallest.Blobs.Add(item2);
                    this.AvailableBlobs.Remove(item2);
                    smallest.ComputeInfluence();
                }
            }
        }