public static bool PathableNeighborIndices(RegionCostCalculator __instance, ref List <int> __result, int index) { if (tmpPathableNeighborIndices == null) { tmpPathableNeighborIndices = new List <int>(); } else { tmpPathableNeighborIndices.Clear(); } PathGrid pathGrid = map(__instance).pathGrid; int x = map(__instance).Size.x; bool num = index % x > 0; bool flag = index % x < x - 1; bool flag2 = index >= x; bool flag3 = index / x < map(__instance).Size.z - 1; if (flag2 && pathGrid.WalkableFast(index - x)) { tmpPathableNeighborIndices.Add(index - x); } if (flag && pathGrid.WalkableFast(index + 1)) { tmpPathableNeighborIndices.Add(index + 1); } if (num && pathGrid.WalkableFast(index - 1)) { tmpPathableNeighborIndices.Add(index - 1); } if (flag3 && pathGrid.WalkableFast(index + x)) { tmpPathableNeighborIndices.Add(index + x); } bool flag4 = !num || PathFinder.BlocksDiagonalMovement(index - 1, map(__instance)); bool flag5 = !flag || PathFinder.BlocksDiagonalMovement(index + 1, map(__instance)); if (flag2 && !PathFinder.BlocksDiagonalMovement(index - x, map(__instance))) { if (!flag5 && pathGrid.WalkableFast(index - x + 1)) { tmpPathableNeighborIndices.Add(index - x + 1); } if (!flag4 && pathGrid.WalkableFast(index - x - 1)) { tmpPathableNeighborIndices.Add(index - x - 1); } } if (flag3 && !PathFinder.BlocksDiagonalMovement(index + x, map(__instance))) { if (!flag5 && pathGrid.WalkableFast(index + x + 1)) { tmpPathableNeighborIndices.Add(index + x + 1); } if (!flag4 && pathGrid.WalkableFast(index + x - 1)) { tmpPathableNeighborIndices.Add(index + x - 1); } } __result = tmpPathableNeighborIndices; return(false); }
public static bool Init(RegionCostCalculator __instance, CellRect destination, HashSet <Region> destRegions, TraverseParms parms, int moveTicksCardinal, int moveTicksDiagonal, ByteGrid avoidGrid, Area allowedArea, bool drafted) { regionGridField(__instance) = map(__instance).regionGrid.DirectGrid; traverseParmsField(__instance) = parms; destinationCellField(__instance) = destination.CenterCell; moveTicksCardinalField(__instance) = moveTicksCardinal; moveTicksDiagonalField(__instance) = moveTicksDiagonal; avoidGridField(__instance) = avoidGrid; allowedAreaField(__instance) = allowedArea; draftedField(__instance) = drafted; //temps? regionMinLink(__instance).Clear(); distances(__instance).Clear(); linkTargetCells(__instance).Clear(); minPathCosts(__instance).Clear(); if (!queueDict.TryGetValue(__instance, out FastPriorityQueueRegionLinkQueueEntry2 queue)) { queue = new FastPriorityQueueRegionLinkQueueEntry2(new DistanceComparer2()); } foreach (Region destRegion in destRegions) { int minPathCost = __instance.RegionMedianPathCost(destRegion); for (int i = 0; i < destRegion.links.Count; i++) { RegionLink regionLink = destRegion.links[i]; if (!regionLink.GetOtherRegion(destRegion).Allows(traverseParmsField(__instance), isDestination: false)) { continue; } int num = funcRegionLinkDistanceIRI(__instance, destinationCellField(__instance), regionLink, minPathCost); if (distances(__instance).TryGetValue(regionLink, out int value)) { if (num < value) { linkTargetCells(__instance)[regionLink] = funcGetLinkTargetCell(__instance, destinationCellField(__instance), regionLink); } num = Math.Min(value, num); } else { linkTargetCells(__instance)[regionLink] = funcGetLinkTargetCell(__instance, destinationCellField(__instance), regionLink); } distances(__instance)[regionLink] = num; } GetPreciseRegionLinkDistances(__instance, destRegion, destination, preciseRegionLinkDistances(__instance)); for (int j = 0; j < preciseRegionLinkDistances(__instance).Count; j++) { Pair <RegionLink, int> pair = preciseRegionLinkDistances(__instance)[j]; RegionLink first = pair.First; int num2 = distances(__instance)[first]; int num3; if (pair.Second > num2) { distances(__instance)[first] = pair.Second; num3 = pair.Second; } else { num3 = num2; } queue.Push(new RegionLinkQueueEntry2(destRegion, first, num3, num3)); } } return(false); }
public static bool GetRegionDistance(RegionCostCalculator __instance, ref int __result, Region region, out RegionLink minLink) { if (regionMinLink(__instance).TryGetValue(region.id, out minLink)) { __result = distances(__instance)[minLink]; return(false); } FastPriorityQueueRegionLinkQueueEntry2 queue; if (!queueDict.TryGetValue(__instance, out queue)) { queue = new FastPriorityQueueRegionLinkQueueEntry2(new DistanceComparer2()); } while (queue.Count != 0) { RegionLinkQueueEntry2 regionLinkQueueEntry = queue.Pop(); int num = distances(__instance)[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(__instance), traverseParms(__instance).pawn); if (num2 == int.MaxValue) { continue; } //num2 += OctileDistance(1, 0); num2 += funcOctileDistance(__instance, 1, 0); } int minPathCost = __instance.RegionMedianPathCost(otherRegion); for (int i = 0; i < otherRegion.links.Count; i++) { RegionLink regionLink = otherRegion.links[i]; if (regionLink == null || regionLink.GetOtherRegion(otherRegion) == null || regionLink == regionLinkQueueEntry.Link || !regionLink.GetOtherRegion(otherRegion).type.Passable()) { continue; } //int val = (otherRegion.door != null) ? num2 : RegionLinkDistance(regionLinkQueueEntry.Link, regionLink, minPathCost); int val = (otherRegion.door != null) ? num2 : funcRegionLinkDistanceRRI(__instance, regionLinkQueueEntry.Link, regionLink, minPathCost); val = Math.Max(val, 1); int num3 = num + val; //int estimatedPathCost = MinimumRegionLinkDistance(destinationCell, regionLink) + num3; int estimatedPathCost = funcMinimumRegionLinkDistance(__instance, destinationCell(__instance), regionLink) + num3; if (distances(__instance).TryGetValue(regionLink, out int value)) { if (num3 < value) { distances(__instance)[regionLink] = num3; if (!queueDict.TryGetValue(__instance, out queue)) { queue = new FastPriorityQueueRegionLinkQueueEntry2(new DistanceComparer2()); } queue.Push(new RegionLinkQueueEntry2(otherRegion, regionLink, num3, estimatedPathCost)); } } else { if (!queueDict.TryGetValue(__instance, out queue)) { queue = new FastPriorityQueueRegionLinkQueueEntry2(new DistanceComparer2()); } distances(__instance).Add(regionLink, num3); queue.Push(new RegionLinkQueueEntry2(otherRegion, regionLink, num3, estimatedPathCost)); } } if (!regionMinLink(__instance).ContainsKey(otherRegion.id)) { regionMinLink(__instance).Add(otherRegion.id, regionLinkQueueEntry.Link); if (otherRegion == region) { minLink = regionLinkQueueEntry.Link; __result = regionLinkQueueEntry.Cost; return(false); } } } __result = 10000; return(false); }
public static int MinimumRegionLinkDistance2(RegionCostCalculator __instance, IntVec3 cell, RegionLink link) { IntVec3 intVec = cell - LinkClosestCell(cell, link); return(OctileDistance2(__instance, Math.Abs(intVec.x), Math.Abs(intVec.z))); }
public static int OctileDistance2(RegionCostCalculator __instance, int dx, int dz) { return(GenMath.OctileDistance(dx, dz, moveTicksCardinalField(__instance), moveTicksDiagonalField(__instance))); }
private static List <int> PathableNeighborIndices2(RegionCostCalculator __instance, int index) { List <int> tmpPathableNeighborIndices = new List <int>(); //Replaces tmpPathableNeighborIndices.Clear(); //tmpPathableNeighborIndices.Clear(); PathGrid pathGrid = map(__instance).pathGrid; int x = map(__instance).Size.x; bool num = index % x > 0; bool flag = index % x < x - 1; bool flag2 = index >= x; bool flag3 = index / x < map(__instance).Size.z - 1; if (flag2 && pathGrid.WalkableFast(index - x)) { tmpPathableNeighborIndices.Add(index - x);//Replaces tmpPathableNeighborIndices } if (flag && pathGrid.WalkableFast(index + 1)) { tmpPathableNeighborIndices.Add(index + 1);//Replaces tmpPathableNeighborIndices } if (num && pathGrid.WalkableFast(index - 1)) { tmpPathableNeighborIndices.Add(index - 1);//Replaces tmpPathableNeighborIndices } if (flag3 && pathGrid.WalkableFast(index + x)) { tmpPathableNeighborIndices.Add(index + x);//Replaces tmpPathableNeighborIndices } bool flag4 = !num || PathFinder.BlocksDiagonalMovement(index - 1, map(__instance)); bool flag5 = !flag || PathFinder.BlocksDiagonalMovement(index + 1, map(__instance)); if (flag2 && !PathFinder.BlocksDiagonalMovement(index - x, map(__instance))) { if (!flag5 && pathGrid.WalkableFast(index - x + 1)) { tmpPathableNeighborIndices.Add(index - x + 1);//Replaces tmpPathableNeighborIndices } if (!flag4 && pathGrid.WalkableFast(index - x - 1)) { tmpPathableNeighborIndices.Add(index - x - 1);//Replaces tmpPathableNeighborIndices } } if (flag3 && !PathFinder.BlocksDiagonalMovement(index + x, map(__instance))) { if (!flag5 && pathGrid.WalkableFast(index + x + 1)) { tmpPathableNeighborIndices.Add(index + x + 1);//Replaces tmpPathableNeighborIndices } if (!flag4 && pathGrid.WalkableFast(index + x - 1)) { tmpPathableNeighborIndices.Add(index + x - 1);//Replaces tmpPathableNeighborIndices } } return(tmpPathableNeighborIndices);//Replaces tmpPathableNeighborIndices }