private void CalculateContiguousGroups()
        {
            WorldGrid        worldGrid        = Find.WorldGrid;
            WorldFloodFiller worldFloodFiller = Find.WorldFloodFiller;
            int   minSize           = this.MinSize;
            int   maxSize           = this.MaxSize;
            float maxPctOfWholeArea = this.MaxPctOfWholeArea;
            int   maxPassageWidth   = this.MaxPassageWidth;

            FeatureWorker.ClearVisited();
            FeatureWorker.ClearGroupSizes();
            for (int i = 0; i < this.roots.Count; i++)
            {
                int num = this.roots[i];
                if (!FeatureWorker.visited[num])
                {
                    FeatureWorker_Protrusion.tmpGroup.Clear();
                    worldFloodFiller.FloodFill(num, (int x) => this.rootsSet.Contains(x), delegate(int x)
                    {
                        FeatureWorker.visited[x] = true;
                        FeatureWorker_Protrusion.tmpGroup.Add(x);
                    }, int.MaxValue, null);
                    for (int j = 0; j < FeatureWorker_Protrusion.tmpGroup.Count; j++)
                    {
                        FeatureWorker.groupSize[FeatureWorker_Protrusion.tmpGroup[j]] = FeatureWorker_Protrusion.tmpGroup.Count;
                    }
                }
            }
            FeatureWorker.ClearVisited();
            for (int k = 0; k < this.rootsWithoutSmallPassages.Count; k++)
            {
                int num2 = this.rootsWithoutSmallPassages[k];
                if (!FeatureWorker.visited[num2])
                {
                    this.currentGroup.Clear();
                    worldFloodFiller.FloodFill(num2, (int x) => this.rootsWithoutSmallPassagesSet.Contains(x), delegate(int x)
                    {
                        FeatureWorker.visited[x] = true;
                        this.currentGroup.Add(x);
                    }, int.MaxValue, null);
                    if (this.currentGroup.Count >= minSize)
                    {
                        GenPlanetMorphology.Dilate(this.currentGroup, maxPassageWidth * 2, (int x) => this.rootsSet.Contains(x));
                        if (this.currentGroup.Count <= maxSize)
                        {
                            float num3 = (float)this.currentGroup.Count / (float)FeatureWorker.groupSize[num2];
                            if (num3 <= maxPctOfWholeArea)
                            {
                                if (this.def.canTouchWorldEdge || !this.currentGroup.Any((int x) => worldGrid.IsOnEdge(x)))
                                {
                                    this.currentGroupMembers.Clear();
                                    for (int l = 0; l < this.currentGroup.Count; l++)
                                    {
                                        if (this.IsMember(this.currentGroup[l]))
                                        {
                                            this.currentGroupMembers.Add(this.currentGroup[l]);
                                        }
                                    }
                                    if (this.currentGroupMembers.Count >= minSize)
                                    {
                                        if (this.currentGroup.Any((int x) => worldGrid[x].feature == null))
                                        {
                                            this.currentGroup.RemoveAll((int x) => worldGrid[x].feature != null);
                                        }
                                        base.AddFeature(this.currentGroupMembers, this.currentGroup);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        private void CalculateContiguousGroups()
        {
            WorldGrid        worldGrid        = Find.WorldGrid;
            WorldFloodFiller worldFloodFiller = Find.WorldFloodFiller;
            int   minSize           = MinSize;
            int   maxSize           = MaxSize;
            float maxPctOfWholeArea = MaxPctOfWholeArea;
            int   maxPassageWidth   = MaxPassageWidth;

            FeatureWorker.ClearVisited();
            FeatureWorker.ClearGroupSizes();
            for (int i = 0; i < roots.Count; i++)
            {
                int num = roots[i];
                if (!FeatureWorker.visited[num])
                {
                    tmpGroup.Clear();
                    worldFloodFiller.FloodFill(num, (int x) => rootsSet.Contains(x), delegate(int x)
                    {
                        FeatureWorker.visited[x] = true;
                        tmpGroup.Add(x);
                    });
                    for (int j = 0; j < tmpGroup.Count; j++)
                    {
                        FeatureWorker.groupSize[tmpGroup[j]] = tmpGroup.Count;
                    }
                }
            }
            FeatureWorker.ClearVisited();
            for (int k = 0; k < rootsWithoutSmallPassages.Count; k++)
            {
                int num2 = rootsWithoutSmallPassages[k];
                if (FeatureWorker.visited[num2])
                {
                    continue;
                }
                currentGroup.Clear();
                worldFloodFiller.FloodFill(num2, (int x) => rootsWithoutSmallPassagesSet.Contains(x), delegate(int x)
                {
                    FeatureWorker.visited[x] = true;
                    currentGroup.Add(x);
                });
                if (currentGroup.Count < minSize)
                {
                    continue;
                }
                GenPlanetMorphology.Dilate(currentGroup, maxPassageWidth * 2, (int x) => rootsSet.Contains(x));
                if (currentGroup.Count > maxSize || (float)currentGroup.Count / (float)FeatureWorker.groupSize[num2] > maxPctOfWholeArea || (!def.canTouchWorldEdge && currentGroup.Any((int x) => worldGrid.IsOnEdge(x))))
                {
                    continue;
                }
                currentGroupMembers.Clear();
                for (int l = 0; l < currentGroup.Count; l++)
                {
                    if (IsMember(currentGroup[l]))
                    {
                        currentGroupMembers.Add(currentGroup[l]);
                    }
                }
                if (currentGroupMembers.Count >= minSize)
                {
                    if (currentGroup.Any((int x) => worldGrid[x].feature == null))
                    {
                        currentGroup.RemoveAll((int x) => worldGrid[x].feature != null);
                    }
                    AddFeature(currentGroupMembers, currentGroup);
                }
            }
        }
示例#3
0
 public static void Close(List <int> tiles, int count)
 {
     GenPlanetMorphology.Dilate(tiles, count, null);
     GenPlanetMorphology.Erode(tiles, count, null);
 }