Пример #1
0
        public RegionLink LinkFrom(EdgeSpan span)
        {
            ulong key = span.UniqueHashCode();

            if (!links.TryGetValue(key, out var value))
            {
                value      = new RegionLink();
                value.span = span;
                links.Add(key, value);
            }
            return(value);
        }
Пример #2
0
        public RegionLink LinkFrom(EdgeSpan span)
        {
            ulong      key = span.UniqueHashCode();
            RegionLink regionLink;

            if (!this.links.TryGetValue(key, out regionLink))
            {
                regionLink      = new RegionLink();
                regionLink.span = span;
                this.links.Add(key, regionLink);
            }
            return(regionLink);
        }
Пример #3
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);
             }
         }
     }
 }