private static void DetermineStartRegions2(Reachability __instance, IntVec3 start, List <Region> this_startingRegions, PathGrid pathGrid, RegionGrid regionGrid, uint this_reachedIndex, Queue <Region> this_openQueue, ref int this_numRegionsOpened, HashSet <Region> regionsReached) { //this_startingRegions.Clear(); if (pathGrid.WalkableFast(start)) { Region validRegionAt = regionGrid.GetValidRegionAt(start); if (validRegionAt != null) { QueueNewOpenRegion(validRegionAt, this_reachedIndex, this_openQueue, ref this_numRegionsOpened, regionsReached); this_startingRegions.Add(validRegionAt); } else { Log.Warning("regionGrid.GetValidRegionAt returned null for start at: " + start.ToString()); } } else { for (int index = 0; index < 8; ++index) { IntVec3 intVec3 = start + GenAdj.AdjacentCells[index]; if (intVec3.InBounds(map(__instance)) && pathGrid.WalkableFast(intVec3)) { Region validRegionAt = regionGrid.GetValidRegionAt(intVec3); if (validRegionAt != null && (int)validRegionAt.reachedIndex != (int)this_reachedIndex) { QueueNewOpenRegion(validRegionAt, this_reachedIndex, this_openQueue, ref this_numRegionsOpened, regionsReached); this_startingRegions.Add(validRegionAt); } } } } }
private static void DetermineStartRegions(Map map, IntVec3 start, List <Region> startingRegionsParam, PathGrid pathGrid, RegionGrid regionGrid, Queue <Region> openQueueParam, HashSet <Region> regionsReached) { startingRegionsParam.Clear(); if (pathGrid.WalkableFast(start)) { Region validRegionAt = regionGrid.GetValidRegionAt(start); QueueNewOpenRegion(validRegionAt, openQueueParam, regionsReached); startingRegionsParam.Add(validRegionAt); return; } else { for (int index = 0; index < 8; ++index) { IntVec3 intVec = start + GenAdj.AdjacentCells[index]; if (intVec.InBounds(map) && pathGrid.WalkableFast(intVec)) { Region validRegionAt2 = regionGrid.GetValidRegionAt(intVec); if (validRegionAt2 != null && !regionsReached.Contains(validRegionAt2)) { QueueNewOpenRegion(validRegionAt2, openQueueParam, regionsReached); startingRegionsParam.Add(validRegionAt2); } } } } }
public static void ReApplyThingToListerThings(IntVec3 cell, Thing thing) { if (cell == IntVec3.Invalid || thing == null || thing.Map == null || !thing.Spawned) { return; } Map map = thing.Map; // From ThingUtility.UpdateRegionListers(..) RegionGrid regionGrid = map.regionGrid; Region region = null; if (cell.InBounds(map)) { region = regionGrid.GetValidRegionAt(cell); } if (region != null) { if (!region.ListerThings.Contains(thing)) { region.ListerThings.Add(thing); //Log.Warning("ReAdded Robot to region.ListerThings.."); } } }
public TrailblazerPather_HAStar(PathfindData pathfindData) : base(pathfindData) { regionGrid = pathfindData.map.regionGrid; int regions = regionGrid.AllRegions.Count(); // Worst case scenario - a large region where every single edge cell links to a different neighboring region maxLinks = Region.GridSize * 4 * regions; rraOpenSet = new Priority_Queue.FastPriorityQueue <LinkNode>(maxLinks); rraClosedSet = new Dictionary <LinkNode, int>(); destRegions.AddRange(from cell in pathfindData.DestRect.Cells let region = regionGrid.GetValidRegionAt(cell) where region != null select region); // Initialize the RRA* algorithm LinkNode.ClearCaches(); IEnumerable <LinkNode> initialNodes = (from region in destRegions from link in region.links from node in LinkNode.Both(link) select node).Distinct(); foreach (LinkNode node in initialNodes) { rraClosedSet[node] = RRAHeuristic(node, destCell); rraOpenSet.Enqueue(node, rraClosedSet[node]); } }
public static void ReApplyThingToListerThings(IntVec3 cell, Thing thing) { bool flag = cell == IntVec3.Invalid || thing == null || thing.Map == null || !thing.Spawned; if (!flag) { Map map = thing.Map; RegionGrid regionGrid = map.regionGrid; Region region = null; bool flag2 = GenGrid.InBounds(cell, map); if (flag2) { region = regionGrid.GetValidRegionAt(cell); } bool flag3 = region != null; if (flag3) { bool flag4 = !region.ListerThings.Contains(thing); if (flag4) { region.ListerThings.Add(thing); } } } }
public static void ReApplyThingToListerThings(IntVec3 cell, Thing thing) { if ((((cell != IntVec3.Invalid) && (thing != null)) && (thing.Map != null)) && thing.Spawned) { Map map = thing.Map; RegionGrid regionGrid = map.regionGrid; Region validRegionAt = null; if (cell.InBounds(map)) { validRegionAt = regionGrid.GetValidRegionAt(cell); } if ((validRegionAt != null) && !validRegionAt.ListerThings.Contains(thing)) { validRegionAt.ListerThings.Add(thing); } } }
private static bool CheckCellBasedReachability( IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams, RegionGrid regionGrid, Reachability __instance, List <Region> this_startingRegions, ReachabilityCache this_cache, List <Region> this_destRegions) { IntVec3 foundCell = IntVec3.Invalid; Region[] directRegionGrid = regionGrid.DirectGrid; PathGrid pathGrid = map(__instance).pathGrid; CellIndices cellIndices = map(__instance).cellIndices; map(__instance).floodFiller.FloodFill(start, (Predicate <IntVec3>)(c => { int index = cellIndices.CellToIndex(c); if ((traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) && c.GetTerrain(map(__instance)).IsWater) { return(false); } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater) { if (!pathGrid.WalkableFast(index)) { Building edifice = c.GetEdifice(map(__instance)); if (edifice == null || !PathFinder.IsDestroyable((Thing)edifice)) { return(false); } } } else if (traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater) { Log.ErrorOnce("Do not use this method for non-cell based modes!", 938476762, false); if (!pathGrid.WalkableFast(index)) { return(false); } } Region region = directRegionGrid[index]; return(region == null || region.Allows(traverseParams, false)); }), (Func <IntVec3, bool>)(c => { if (!ReachabilityImmediate.CanReachImmediate(c, dest, map(__instance), peMode, traverseParams.pawn)) { return(false); } foundCell = c; return(true); }), int.MaxValue, false, (IEnumerable <IntVec3>)null); if (foundCell.IsValid) { if (CanUseCache(traverseParams.mode)) { Region validRegionAt = regionGrid.GetValidRegionAt(foundCell); if (validRegionAt != null) { for (int index = 0; index < this_startingRegions.Count; ++index) { this_cache.AddCachedResult(this_startingRegions[index].Room, validRegionAt.Room, traverseParams, true); } } } return(true); } if (CanUseCache(traverseParams.mode)) { for (int index1 = 0; index1 < this_startingRegions.Count; ++index1) { for (int index2 = 0; index2 < this_destRegions.Count; ++index2) { this_cache.AddCachedResult(this_startingRegions[index1].Room, this_destRegions[index2].Room, traverseParams, false); } } } return(false); }