public int GetRegionDistance(VehicleRegion region, out VehicleRegionLink minLink) { if (regionMinLink.TryGetValue(region.id, out minLink)) { return(distances[minLink]); } while (queue.Count != 0) { RegionLinkQueueEntry regionLinkQueueEntry = queue.Pop(); int num = distances[regionLinkQueueEntry.Link]; if (regionLinkQueueEntry.Cost == num) { VehicleRegion otherRegion = regionLinkQueueEntry.Link.GetOtherRegion(regionLinkQueueEntry.From); if (!(otherRegion is null) && otherRegion.valid) { int num2 = 0; if (!(otherRegion.door is null)) { num2 = VehiclePathFinder.GetBuildingCost(otherRegion.door, traverseParms, traverseParms.pawn); if (num2 == int.MaxValue) { continue; } num2 += OctileDistance(1, 0); } int minPathCost = RegionMedianPathCost(otherRegion); foreach (VehicleRegionLink regionLink in otherRegion.links) { if (regionLink != regionLinkQueueEntry.Link && regionLink.GetOtherRegion(otherRegion).type.Passable()) { int num3 = (otherRegion.door is null) ? RegionLinkDistance(regionLinkQueueEntry.Link, regionLink, minPathCost) : num2; num3 = Math.Max(num3, 1); int num4 = num + num3; int estimatedPathCost = MinimumRegionLinkDistance(destinationCell, regionLink) + num4; if (distances.TryGetValue(regionLink, out int num5)) { if (num4 < num5) { distances[regionLink] = num4; queue.Push(new RegionLinkQueueEntry(otherRegion, regionLink, num4, estimatedPathCost)); } } else { distances.Add(regionLink, num4); queue.Push(new RegionLinkQueueEntry(otherRegion, regionLink, num4, estimatedPathCost)); } } } if (!regionMinLink.ContainsKey(otherRegion.id)) { regionMinLink.Add(otherRegion.id, regionLinkQueueEntry.Link); if (otherRegion == region) { minLink = regionLinkQueueEntry.Link; return(regionLinkQueueEntry.Cost); } } } } } return(10000); }
public int GetRegionDistance(Region region, out RegionLink minLink) { if (this.regionMinLink.TryGetValue(region.id, out minLink)) { return(this.distances[minLink]); } while (this.queue.Count != 0) { RegionLinkQueueEntry regionLinkQueueEntry = this.queue.Pop(); int num = this.distances[regionLinkQueueEntry.Link]; Region otherRegion; int num2; if (regionLinkQueueEntry.Cost == num) { otherRegion = regionLinkQueueEntry.Link.GetOtherRegion(regionLinkQueueEntry.From); if (otherRegion != null && otherRegion.valid) { num2 = 0; if (otherRegion.portal != null) { num2 = PathFinder.GetBuildingCost(otherRegion.portal, this.traverseParms, this.traverseParms.pawn); if (num2 != 2147483647) { num2 += this.OctileDistance(1, 0); goto IL_00ca; } continue; } goto IL_00ca; } } continue; IL_00ca: int minPathCost = this.RegionMedianPathCost(otherRegion); for (int i = 0; i < otherRegion.links.Count; i++) { RegionLink regionLink = otherRegion.links[i]; if (regionLink != regionLinkQueueEntry.Link && regionLink.GetOtherRegion(otherRegion).type.Passable()) { int val = (otherRegion.portal == null) ? this.RegionLinkDistance(regionLinkQueueEntry.Link, regionLink, minPathCost) : num2; val = Math.Max(val, 1); int num3 = num + val; int estimatedPathCost = this.MinimumRegionLinkDistance(this.destinationCell, regionLink) + num3; int num4 = default(int); if (this.distances.TryGetValue(regionLink, out num4)) { if (num3 < num4) { this.distances[regionLink] = num3; this.queue.Push(new RegionLinkQueueEntry(otherRegion, regionLink, num3, estimatedPathCost)); } } else { this.distances.Add(regionLink, num3); this.queue.Push(new RegionLinkQueueEntry(otherRegion, regionLink, num3, estimatedPathCost)); } } } if (!this.regionMinLink.ContainsKey(otherRegion.id)) { this.regionMinLink.Add(otherRegion.id, regionLinkQueueEntry.Link); if (otherRegion == region) { minLink = regionLinkQueueEntry.Link; return(regionLinkQueueEntry.Cost); } } } return(10000); }
public int GetRegionDistance(Region region, out RegionLink minLink) { if (regionMinLink.TryGetValue(region.id, out minLink)) { return(distances[minLink]); } while (queue.Count != 0) { RegionLinkQueueEntry regionLinkQueueEntry = queue.Pop(); int num = distances[regionLinkQueueEntry.Link]; if (regionLinkQueueEntry.Cost != num) { continue; } Region otherRegion = regionLinkQueueEntry.Link.GetOtherRegion(regionLinkQueueEntry.From); if (otherRegion == null || !otherRegion.valid) { continue; } int num2 = 0; if (otherRegion.door != null) { num2 = PathFinder.GetBuildingCost(otherRegion.door, traverseParms, traverseParms.pawn); if (num2 == int.MaxValue) { continue; } num2 += OctileDistance(1, 0); } int minPathCost = RegionMedianPathCost(otherRegion); for (int i = 0; i < otherRegion.links.Count; i++) { RegionLink regionLink = otherRegion.links[i]; if (regionLink == regionLinkQueueEntry.Link || !regionLink.GetOtherRegion(otherRegion).type.Passable()) { continue; } int val = (otherRegion.door != null) ? num2 : RegionLinkDistance(regionLinkQueueEntry.Link, regionLink, minPathCost); val = Math.Max(val, 1); int num3 = num + val; int estimatedPathCost = MinimumRegionLinkDistance(destinationCell, regionLink) + num3; if (distances.TryGetValue(regionLink, out int value)) { if (num3 < value) { distances[regionLink] = num3; queue.Push(new RegionLinkQueueEntry(otherRegion, regionLink, num3, estimatedPathCost)); } } else { distances.Add(regionLink, num3); queue.Push(new RegionLinkQueueEntry(otherRegion, regionLink, num3, estimatedPathCost)); } } if (!regionMinLink.ContainsKey(otherRegion.id)) { regionMinLink.Add(otherRegion.id, regionLinkQueueEntry.Link); if (otherRegion == region) { minLink = regionLinkQueueEntry.Link; return(regionLinkQueueEntry.Cost); } } } return(10000); }