Example #1
0
        public WaterRegion TryGenerateRegionFrom(IntVec3 root)
        {
            RegionType expectedRegionType = WaterRegionTypeUtility.GetExpectedRegionType(root, this.map);

            if (expectedRegionType == RegionType.None)
            {
                return(null);
            }
            if (this.working)
            {
                Log.Error("Trying to generate a new water region but we are currently generating one. Nested calls are not allowed.", false);
                return(null);
            }
            this.working = true;
            WaterRegion result;

            try
            {
                this.regionGrid  = MapExtensionUtility.GetExtensionToMap(this.map).getWaterRegionGrid;
                this.newReg      = WaterRegion.MakeNewUnfilled(root, this.map);
                this.newReg.type = expectedRegionType;
                //Portal type?
                this.FloodFillAndAddCells(root);
                this.CreateLinks();
                this.RegisterThingsInRegionListers();
                result = this.newReg;
            }
            finally
            {
                this.working = false;
            }
            return(result);
        }
Example #2
0
 private void FloodFillAndAddCells(IntVec3 root)
 {
     this.newRegCells.Clear();
     if (this.newReg.type.IsOneCellRegion())
     {
         this.AddCell(root);
     }
     else
     {
         this.map.floodFiller.FloodFill(root, (IntVec3 x) => this.newReg.extentsLimit.Contains(x) && WaterRegionTypeUtility.GetExpectedRegionType(x, this.map) == this.newReg.type, delegate(IntVec3 x)
         {
             this.AddCell(x);
         }, int.MaxValue, false, null);
     }
 }
Example #3
0
        private void SweepInTwoDirectionsAndTryToCreateLink(Rot4 potentialOtherRegionDir, IntVec3 c)
        {
            if (!potentialOtherRegionDir.IsValid)
            {
                return;
            }
            HashSet <IntVec3> hashSet = this.linksProcessedAt[potentialOtherRegionDir.AsInt];

            if (hashSet.Contains(c))
            {
                return;
            }
            IntVec3 c2 = c + potentialOtherRegionDir.FacingCell;

            if (c2.InBoundsShip(this.map) && this.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(c2) == this.newReg)
            {
                return;
            }
            RegionType expectedRegionType = WaterRegionTypeUtility.GetExpectedRegionType(c2, this.map);

            if (expectedRegionType == RegionType.None)
            {
                return;
            }
            Rot4 rot = potentialOtherRegionDir;

            rot.Rotate(RotationDirection.Clockwise);
            int num  = 0;
            int num2 = 0;

            hashSet.Add(c);
            if (!WaterRegionTypeUtility.IsOneCellRegion(expectedRegionType))
            {
                for (;;)
                {
                    IntVec3 intVec = c + rot.FacingCell * (num + 1);
                    if (!intVec.InBoundsShip(this.map) || this.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(intVec) != this.newReg ||
                        WaterRegionTypeUtility.GetExpectedRegionType(intVec + potentialOtherRegionDir.FacingCell, this.map) != expectedRegionType)
                    {
                        break;
                    }
                    if (!hashSet.Add(intVec))
                    {
                        Log.Error("We've processed the same cell twice.", false);
                    }
                    num++;
                }
                for (; ;)
                {
                    IntVec3 intVec2 = c - rot.FacingCell * (num2 + 1);
                    if (!intVec2.InBoundsShip(this.map) || this.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(intVec2) != this.newReg ||
                        WaterRegionTypeUtility.GetExpectedRegionType(intVec2 + potentialOtherRegionDir.FacingCell, this.map) != expectedRegionType)
                    {
                        break;
                    }
                    if (!hashSet.Add(intVec2))
                    {
                        Log.Error("We've processed the same cell twice.", false);
                    }
                    num2++;
                }
            }
            int           length = num + num2 + 1;
            SpanDirection dir;
            IntVec3       root;

            if (potentialOtherRegionDir == Rot4.North)
            {
                dir  = SpanDirection.East;
                root = c - rot.FacingCell * num2;
                root.z++;
            }
            else if (potentialOtherRegionDir == Rot4.South)
            {
                dir  = SpanDirection.East;
                root = c + rot.FacingCell * num;
            }
            else if (potentialOtherRegionDir == Rot4.East)
            {
                dir  = SpanDirection.North;
                root = c + rot.FacingCell * num;
                root.x++;
            }
            else
            {
                dir  = SpanDirection.North;
                root = c - rot.FacingCell * num2;
            }
            EdgeSpan        span       = new EdgeSpan(root, dir, length);
            WaterRegionLink regionLink = MapExtensionUtility.GetExtensionToMap(this.map).getWaterRegionLinkDatabase.LinkFrom(span);

            regionLink.Register(this.newReg);
            this.newReg.links.Add(regionLink);
        }