Ejemplo n.º 1
0
        public Region TryGenerateRegionFrom(IntVec3 root)
        {
            RegionType expectedRegionType = root.GetExpectedRegionType(this.map);

            if (expectedRegionType == RegionType.None)
            {
                return(null);
            }
            if (this.working)
            {
                Log.Error("Trying to generate a new region but we are currently generating one. Nested calls are not allowed.");
                return(null);
            }
            this.working = true;
            try
            {
                this.regionGrid  = this.map.regionGrid;
                this.newReg      = Region.MakeNewUnfilled(root, this.map);
                this.newReg.type = expectedRegionType;
                if (this.newReg.type == RegionType.Portal)
                {
                    this.newReg.portal = root.GetDoor(this.map);
                }
                this.FloodFillAndAddCells(root);
                this.CreateLinks();
                this.RegisterThingsInRegionListers();
                return(this.newReg);
            }
            finally
            {
                this.working = false;
            }
        }
Ejemplo n.º 2
0
 private void SweepInTwoDirectionsAndTryToCreateLink(Rot4 potentialOtherRegionDir, IntVec3 c)
 {
     if (potentialOtherRegionDir.IsValid)
     {
         HashSet <IntVec3> hashSet = this.linksProcessedAt[potentialOtherRegionDir.AsInt];
         if (!hashSet.Contains(c))
         {
             IntVec3 c2 = c + potentialOtherRegionDir.FacingCell;
             if (c2.InBounds(this.map) && this.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(c2) == this.newReg)
             {
                 return;
             }
             RegionType expectedRegionType = c2.GetExpectedRegionType(this.map);
             if (expectedRegionType != 0)
             {
                 Rot4 rot = potentialOtherRegionDir;
                 rot.Rotate(RotationDirection.Clockwise);
                 int num  = 0;
                 int num2 = 0;
                 hashSet.Add(c);
                 if (!expectedRegionType.IsOneCellRegion())
                 {
                     while (true)
                     {
                         IntVec3 intVec = c + rot.FacingCell * (num + 1);
                         if (intVec.InBounds(this.map) && this.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(intVec) == this.newReg && (intVec + potentialOtherRegionDir.FacingCell).GetExpectedRegionType(this.map) == expectedRegionType)
                         {
                             if (!hashSet.Add(intVec))
                             {
                                 Log.Error("We've processed the same cell twice.");
                             }
                             num++;
                             continue;
                         }
                         break;
                     }
                     while (true)
                     {
                         IntVec3 intVec2 = c - rot.FacingCell * (num2 + 1);
                         if (intVec2.InBounds(this.map) && this.regionGrid.GetRegionAt_NoRebuild_InvalidAllowed(intVec2) == this.newReg && (intVec2 + potentialOtherRegionDir.FacingCell).GetExpectedRegionType(this.map) == expectedRegionType)
                         {
                             if (!hashSet.Add(intVec2))
                             {
                                 Log.Error("We've processed the same cell twice.");
                             }
                             num2++;
                             continue;
                         }
                         break;
                     }
                 }
                 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);
                 RegionLink regionLink = this.map.regionLinkDatabase.LinkFrom(span);
                 regionLink.Register(this.newReg);
                 this.newReg.links.Add(regionLink);
             }
         }
     }
 }
Ejemplo n.º 3
0
 private bool <FloodFillAndAddCells> m__0(IntVec3 x)
 {
     return(this.newReg.extentsLimit.Contains(x) && x.GetExpectedRegionType(this.map) == this.newReg.type);
 }