private bool CheckRegionBasedReachability(TraverseParms traverseParams) { while (this.openQueue.Count > 0) { Region region = this.openQueue.Dequeue(); for (int i = 0; i < region.links.Count; i++) { RegionLink regionLink = region.links[i]; for (int j = 0; j < 2; j++) { Region region2 = regionLink.regions[j]; if (region2 != null && region2.reachedIndex != this.reachedIndex && region2.type.Passable() && region2.Allows(traverseParams, false)) { if (this.destRegions.Contains(region2)) { for (int k = 0; k < this.startingRegions.Count; k++) { this.cache.AddCachedResult(this.startingRegions[k].Room, region2.Room, traverseParams, true); } return(true); } this.QueueNewOpenRegion(region2); } } } } for (int l = 0; l < this.startingRegions.Count; l++) { for (int m = 0; m < this.destRegions.Count; m++) { this.cache.AddCachedResult(this.startingRegions[l].Room, this.destRegions[m].Room, traverseParams, false); } } return(false); }
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); }
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); }
public void BreadthFirstTraverseWork(Region root, RegionEntryPredicate entryCondition, RegionProcessor regionProcessor, int maxRegions, RegionType traversableRegionTypes) { if ((root.type & traversableRegionTypes) == 0) { return; } closedIndex++; open.Clear(); numRegionsProcessed = 0; QueueNewOpenRegion(root); while (open.Count > 0) { Region region = open.Dequeue(); if (DebugViewSettings.drawRegionTraversal) { region.Debug_Notify_Traversed(); } if (regionProcessor != null && regionProcessor(region)) { FinalizeSearch(); return; } if (ShouldCountRegion(region)) { numRegionsProcessed++; } if (numRegionsProcessed >= maxRegions) { FinalizeSearch(); return; } for (int i = 0; i < region.links.Count; i++) { RegionLink regionLink = region.links[i]; for (int j = 0; j < 2; j++) { Region region2 = regionLink.regions[j]; if (region2 != null && region2.closedIndex[closedArrayPos] != closedIndex && (region2.type & traversableRegionTypes) != 0 && (entryCondition == null || entryCondition(region, region2))) { QueueNewOpenRegion(region2); } } } } FinalizeSearch(); }
public void BreadthFirstTraverseWork(Region root, RegionEntryPredicate entryCondition, RegionProcessor regionProcessor, int maxRegions, RegionType traversableRegionTypes) { if ((root.type & traversableRegionTypes) != RegionType.None) { this.closedIndex += 1u; this.open.Clear(); this.numRegionsProcessed = 0; this.QueueNewOpenRegion(root); while (!this.open.Empty) { Region region = this.open.PopFront(); if (DebugViewSettings.drawRegionTraversal) { region.Debug_Notify_Traversed(); } if (regionProcessor != null) { if (regionProcessor(region)) { this.FinalizeSearch(); return; } } this.numRegionsProcessed++; if (this.numRegionsProcessed >= maxRegions) { this.FinalizeSearch(); return; } for (int i = 0; i < region.links.Count; i++) { RegionLink regionLink = region.links[i]; for (int j = 0; j < 2; j++) { Region region2 = regionLink.regions[j]; if (region2 != null && region2.closedIndex[this.closedArrayPos] != this.closedIndex && (region2.type & traversableRegionTypes) != RegionType.None && (entryCondition == null || entryCondition(region, region2))) { this.QueueNewOpenRegion(region2); } } } } this.FinalizeSearch(); } }
private bool CheckRegionBasedReachability(TraverseParms traverseParams) { while (openQueue.Count > 0) { Region region = openQueue.Dequeue(); for (int i = 0; i < region.links.Count; i++) { RegionLink regionLink = region.links[i]; for (int j = 0; j < 2; j++) { Region region2 = regionLink.regions[j]; if (region2 == null || region2.reachedIndex == reachedIndex || !region2.type.Passable() || !region2.Allows(traverseParams, isDestination: false)) { continue; } if (destRegions.Contains(region2)) { for (int k = 0; k < startingRegions.Count; k++) { cache.AddCachedResult(startingRegions[k].Room, region2.Room, traverseParams, reachable: true); } return(true); } QueueNewOpenRegion(region2); } } } for (int l = 0; l < startingRegions.Count; l++) { for (int m = 0; m < destRegions.Count; m++) { cache.AddCachedResult(startingRegions[l].Room, destRegions[m].Room, traverseParams, reachable: false); } } return(false); }
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); } } } }
public void Notify_LinkHasNoRegions(RegionLink link) { this.links.Remove(link.UniqueHashCode()); }