public static bool CanReachImmediate(IntVec3 start, LocalTargetInfo target, Map map, PathEndMode peMode, Pawn pawn) { if (!target.IsValid) { return(false); } target = (LocalTargetInfo)GenPath.ResolvePathMode(pawn, target.ToTargetInfo(map), ref peMode); if (target.HasThing) { Thing thing = target.Thing; if (thing.Spawned) { if (thing.Map != map) { return(false); } goto IL_00d3; } if (pawn != null) { if (pawn.carryTracker.innerContainer.Contains(thing)) { return(true); } if (pawn.inventory.innerContainer.Contains(thing)) { return(true); } if (pawn.apparel != null && pawn.apparel.Contains(thing)) { return(true); } if (pawn.equipment != null && pawn.equipment.Contains(thing)) { return(true); } } return(false); } goto IL_00d3; IL_00d3: if (!target.HasThing || (target.Thing.def.size.x == 1 && target.Thing.def.size.z == 1)) { if (start == target.Cell) { return(true); } } else if (start.IsInside(target.Thing)) { return(true); } if (peMode == PathEndMode.Touch && TouchPathEndModeUtility.IsAdjacentOrInsideAndAllowedToTouch(start, target, map)) { return(true); } return(false); }
public static bool ThingFromRegionListerReachable(Thing thing, Region region, PathEndMode peMode, Pawn traveler) { Map map = region.Map; if (peMode == PathEndMode.ClosestTouch) { peMode = GenPath.ResolveClosestTouchPathMode(traveler, map, thing.Position); } switch (peMode) { case PathEndMode.None: return(false); case PathEndMode.Touch: return(true); case PathEndMode.OnCell: if (thing.def.size.x == 1 && thing.def.size.z == 1) { if (thing.Position.GetRegion(map) == region) { return(true); } } else { CellRect.CellRectIterator iterator = thing.OccupiedRect().GetIterator(); while (!iterator.Done()) { if (iterator.Current.GetRegion(map) == region) { return(true); } iterator.MoveNext(); } } return(false); case PathEndMode.InteractionCell: if (thing.InteractionCell.GetRegion(map) == region) { return(true); } return(false); default: Log.Error("Unsupported PathEndMode: " + peMode); return(false); } }
static bool Prefix(ref Pawn_PathFollower __instance, LocalTargetInfo dest, PathEndMode peMode, Pawn ___pawn) { if (___pawn.Map?.Parent is City) { dest = (LocalTargetInfo)GenPath.ResolvePathMode(___pawn, dest.ToTargetInfo(___pawn.Map), ref peMode); if (dest.HasThing && dest.ThingDestroyed) { Log.Warning(___pawn + " pathing to destroyed thing " + dest.Thing); // ReSharper disable once PossibleNullReferenceException typeof(Pawn_PathFollower).GetMethod("PatherFailed", BindingFlags.NonPublic).Invoke(__instance, new object[] { }); return(false); } } return(true); }
public bool CanReach(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams) { if (this.working) { Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233, false); return(false); } if (traverseParams.pawn != null) { if (!traverseParams.pawn.Spawned) { return(false); } if (traverseParams.pawn.Map != this.map) { Log.Error(string.Concat(new object[] { "Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=", traverseParams.pawn, " pawn.Map=", traverseParams.pawn.Map, " map=", this.map }), false); return(false); } } if (ReachabilityImmediate.CanReachImmediate(start, dest, this.map, peMode, traverseParams.pawn)) { return(true); } if (!dest.IsValid) { return(false); } if (dest.HasThing && dest.Thing.Map != this.map) { return(false); } if (!start.InBounds(this.map) || !dest.Cell.InBounds(this.map)) { return(false); } if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { Room room = RegionAndRoomQuery.RoomAtFast(start, this.map, RegionType.Set_Passable); if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, this.map, RegionType.Set_Passable)) { return(true); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { TraverseParms traverseParams2 = traverseParams; traverseParams2.mode = TraverseMode.PassDoors; if (this.CanReach(start, dest, peMode, traverseParams2)) { return(true); } } dest = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(this.map), ref peMode); this.working = true; bool result; try { this.pathGrid = this.map.pathGrid; this.regionGrid = this.map.regionGrid; this.reachedIndex += 1u; this.destRegions.Clear(); if (peMode == PathEndMode.OnCell) { Region region = dest.Cell.GetRegion(this.map, RegionType.Set_Passable); if (region != null && region.Allows(traverseParams, true)) { this.destRegions.Add(region); } } else if (peMode == PathEndMode.Touch) { TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, this.map, this.destRegions); } if (this.destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { this.FinalizeCheck(); result = false; } else { this.destRegions.RemoveDuplicates <Region>(); this.openQueue.Clear(); this.numRegionsOpened = 0; this.DetermineStartRegions(start); if (this.openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { this.FinalizeCheck(); result = false; } else { if (this.startingRegions.Any <Region>() && this.destRegions.Any <Region>() && this.CanUseCache(traverseParams.mode)) { BoolUnknown cachedResult = this.GetCachedResult(traverseParams); if (cachedResult == BoolUnknown.True) { this.FinalizeCheck(); result = true; return(result); } if (cachedResult == BoolUnknown.False) { this.FinalizeCheck(); result = false; return(result); } if (cachedResult != BoolUnknown.Unknown) { } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) { bool flag = this.CheckCellBasedReachability(start, dest, peMode, traverseParams); this.FinalizeCheck(); result = flag; } else { bool flag2 = this.CheckRegionBasedReachability(traverseParams); this.FinalizeCheck(); result = flag2; } } } } finally { this.working = false; } return(result); }
public static bool CanReach(Reachability __instance, ref bool __result, IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams) { Map map = __instance.map; //if (working) //{ //Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233); //return false; //} if (traverseParams.pawn != null) { if (!traverseParams.pawn.Spawned) { __result = false; return(false); } if (traverseParams.pawn.Map != map) { Log.Error(string.Concat("Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=", traverseParams.pawn, " pawn.Map=", traverseParams.pawn.Map, " map=", map)); __result = false; return(false); } } if (ReachabilityImmediate.CanReachImmediate(start, dest, map, peMode, traverseParams.pawn)) { __result = true; return(false); } if (!dest.IsValid) { __result = false; return(false); } if (dest.HasThing && dest.Thing.Map != map) { __result = false; return(false); } if (!start.InBounds(map) || !dest.Cell.InBounds(map)) { __result = false; return(false); } if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { #if RW12 Room room = RegionAndRoomQuery.RoomAtFast(start, map); if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, map)) #endif #if RW13 District district = RegionAndRoomQuery.DistirctAtFast(start, map); if (district != null && district == RegionAndRoomQuery.DistirctAtFast(dest.Cell, map)) #endif { __result = true; return(false); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { TraverseParms traverseParams2 = traverseParams; traverseParams2.mode = TraverseMode.PassDoors; bool canReachResult = false; CanReach(__instance, ref canReachResult, start, dest, peMode, traverseParams2); if (canReachResult) { __result = true; return(false); } } dest = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(map), ref peMode); //working = true; try { #if RW12 __instance.pathGrid = map.pathGrid; PathGrid pathGrid = map.pathGrid; #endif #if RW13 __instance.pathGrid = map.pathing.For(traverseParams).pathGrid; PathGrid pathGrid = __instance.pathGrid; #endif __instance.regionGrid = map.regionGrid; RegionGrid regionGrid = map.regionGrid; destRegions.Clear(); switch (peMode) { case PathEndMode.OnCell: { Region region = dest.Cell.GetRegion(map); if (region != null && region.Allows(traverseParams, isDestination: true)) { destRegions.Add(region); } break; } case PathEndMode.Touch: TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, map, destRegions); break; } if (destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { __result = false; return(false); } destRegions.RemoveDuplicates(); regionsReached.Clear(); openQueue.Clear(); startingRegions.Clear(); DetermineStartRegions(map, start, startingRegions, pathGrid, regionGrid, openQueue, regionsReached); if (openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { __result = false; return(false); } if (startingRegions.Any() && destRegions.Any() && __instance.CanUseCache(traverseParams.mode)) { switch (GetCachedResult(__instance, traverseParams, startingRegions, destRegions)) { case BoolUnknown.True: __result = true; return(false); case BoolUnknown.False: __result = false; return(false); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) { bool result = __instance.CheckCellBasedReachability(start, dest, peMode, traverseParams); __result = result; return(false); } bool result2 = CheckRegionBasedReachability(__instance, traverseParams, openQueue, regionsReached, startingRegions, destRegions); __result = result2; return(false); } finally { //working = false; } }
public bool CanReach(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams) { if (working) { Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233); return(false); } if (traverseParams.pawn != null) { if (!traverseParams.pawn.Spawned) { return(false); } if (traverseParams.pawn.Map != map) { Log.Error(string.Concat("Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=", traverseParams.pawn, " pawn.Map=", traverseParams.pawn.Map, " map=", map)); return(false); } } if (ReachabilityImmediate.CanReachImmediate(start, dest, map, peMode, traverseParams.pawn)) { return(true); } if (!dest.IsValid) { return(false); } if (dest.HasThing && dest.Thing.Map != map) { return(false); } if (!start.InBounds(map) || !dest.Cell.InBounds(map)) { return(false); } if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { Room room = RegionAndRoomQuery.RoomAtFast(start, map); if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, map)) { return(true); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { TraverseParms traverseParams2 = traverseParams; traverseParams2.mode = TraverseMode.PassDoors; if (CanReach(start, dest, peMode, traverseParams2)) { return(true); } } dest = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(map), ref peMode); working = true; try { pathGrid = map.pathGrid; regionGrid = map.regionGrid; reachedIndex++; destRegions.Clear(); switch (peMode) { case PathEndMode.OnCell: { Region region = dest.Cell.GetRegion(map); if (region != null && region.Allows(traverseParams, isDestination: true)) { destRegions.Add(region); } break; } case PathEndMode.Touch: TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, map, destRegions); break; } if (destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { FinalizeCheck(); return(false); } destRegions.RemoveDuplicates(); openQueue.Clear(); numRegionsOpened = 0; DetermineStartRegions(start); if (openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { FinalizeCheck(); return(false); } if (startingRegions.Any() && destRegions.Any() && CanUseCache(traverseParams.mode)) { switch (GetCachedResult(traverseParams)) { case BoolUnknown.True: FinalizeCheck(); return(true); case BoolUnknown.False: FinalizeCheck(); return(false); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) { bool result = CheckCellBasedReachability(start, dest, peMode, traverseParams); FinalizeCheck(); return(result); } bool result2 = CheckRegionBasedReachability(traverseParams); FinalizeCheck(); return(result2); } finally { working = false; } }
public static bool CanReach(Reachability __instance, ref bool __result, IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams) { /* * if (working) * { * Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233); * return false; * } */ Map this_map = map(__instance); if (traverseParams.pawn != null) { if (!traverseParams.pawn.Spawned) { __result = false; return(false); } if (traverseParams.pawn.Map != this_map) { Log.Error("Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=" + (object)traverseParams.pawn + " pawn.Map=" + (object)traverseParams.pawn.Map + " map=" + (object)map(__instance), false); __result = false; return(false); } } if (ReachabilityImmediate.CanReachImmediate(start, dest, this_map, peMode, traverseParams.pawn)) { __result = true; return(false); } if (!dest.IsValid || dest.HasThing && dest.Thing.Map != this_map || (!start.InBounds(this_map) || !dest.Cell.InBounds(this_map))) { __result = false; return(false); } if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && (traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater)) { Room room = RegionAndRoomQuery.RoomAtFast(start, this_map, RegionType.Set_Passable); if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, this_map, RegionType.Set_Passable)) { __result = true; return(false); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { TraverseParms traverseParams1 = traverseParams; traverseParams1.mode = TraverseMode.PassDoors; if (__instance.CanReach(start, dest, peMode, traverseParams1)) { __result = true; return(false); } } dest = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(this_map), ref peMode); //working = true; try { uint this_reachedIndex; //Replaced reachedIndex lock (reachedIndexLock) //Added { this_reachedIndex = offsetReachedIndex; //Added offsetReachedIndex += 100000; //Added } HashSet <Region> regionsReached = new HashSet <Region>(); //Added PathGrid pathGrid = this_map.pathGrid; //Replaced pathGrid RegionGrid regionGrid = this_map.regionGrid; //Replaced regionGrid ++this_reachedIndex; //Replaced reachedIndex //this_destRegions.Clear(); List <Region> this_destRegions = new List <Region>(); //Replaced destRegions switch (peMode) { case PathEndMode.OnCell: Region region = dest.Cell.GetRegion(this_map, RegionType.Set_Passable); if (region != null && region.Allows(traverseParams, true)) { this_destRegions.Add(region); break; } break; case PathEndMode.Touch: TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, this_map, this_destRegions); break; } if (this_destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { //this.FinalizeCheck(); __result = false; return(false); } this_destRegions.RemoveDuplicates <Region>(); //this_openQueue.Clear(); Queue <Region> this_openQueue = new Queue <Region>(); //Replaced openQueue int this_numRegionsOpened = 0; //Replaced numRegionsOpened List <Region> this_startingRegions = new List <Region>(); DetermineStartRegions2(__instance, start, this_startingRegions, pathGrid, regionGrid, this_reachedIndex, this_openQueue, ref this_numRegionsOpened, regionsReached); if (this_openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { //this.FinalizeCheck(); __result = false; return(false); } ReachabilityCache this_cache = cache(__instance); if (this_startingRegions.Any <Region>() && this_destRegions.Any <Region>() && CanUseCache(traverseParams.mode)) { switch (GetCachedResult2(traverseParams, this_startingRegions, this_destRegions, this_cache)) { case BoolUnknown.True: //this.FinalizeCheck(); __result = true; return(false); case BoolUnknown.False: //this.FinalizeCheck(); __result = false; return(false); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) { int num = CheckCellBasedReachability(start, dest, peMode, traverseParams, regionGrid, __instance, this_startingRegions, this_cache, this_destRegions ) ? 1 : 0; //this.FinalizeCheck(); __result = num != 0; return(false); } int num1 = CheckRegionBasedReachability(traverseParams, this_openQueue, this_reachedIndex, this_destRegions, this_startingRegions, this_cache, ref this_numRegionsOpened, regionsReached ) ? 1 : 0; //this.FinalizeCheck(); __result = num1 != 0; return(false); } finally { } }
public void StartPath(LocalTargetInfo dest, PathEndMode peMode) { if (!pawn.Drafted) { PatherFailed(); return; } if (pawn.IsBoat()) { dest = (LocalTargetInfo)GenPathVehicles.ResolvePathMode(pawn, dest.ToTargetInfo(pawn.Map), ref peMode); if (dest.HasThing && dest.ThingDestroyed) { Log.Error(pawn + " pathing to destroyed thing " + dest.Thing); PatherFailed(); return; } //Add Building and Position Recoverable extras if (!GenGridVehicles.Walkable(pawn.Position, pawn.Map.GetCachedMapComponent <VehicleMapping>())) { return; } if (Moving && curPath != null && destination == dest && this.peMode == peMode) { return; } if (!pawn.Map.GetCachedMapComponent <VehicleMapping>().VehicleReachability?.CanReachShip(pawn.Position, dest, peMode, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)) ?? false) { PatherFailed(); return; } this.peMode = peMode; destination = dest; if ((GenGridVehicles.Walkable(nextCell, pawn.Map.GetCachedMapComponent <VehicleMapping>()) || WillCollideWithPawnOnNextPathCell()) || nextCellCostLeft == nextCellCostTotal) { ResetToCurrentPosition(); } PawnDestinationReservationManager.PawnDestinationReservation pawnDestinationReservation = pawn.Map.pawnDestinationReservationManager. MostRecentReservationFor(pawn); if (!(pawnDestinationReservation is null) && ((Destination.HasThing && pawnDestinationReservation.target != Destination.Cell) || (pawnDestinationReservation.job != pawn.CurJob && pawnDestinationReservation.target != Destination.Cell))) { pawn.Map.pawnDestinationReservationManager.ObsoleteAllClaimedBy(pawn); } if (VehicleReachabilityImmediate.CanReachImmediateShip(pawn, dest, peMode)) { PatherArrived(); return; } if (curPath != null) { curPath.ReleaseToPool(); } curPath = null; moving = true; pawn.jobs.posture = PawnPosture.Standing; return; } else { dest = (LocalTargetInfo)GenPath.ResolvePathMode(pawn, dest.ToTargetInfo(pawn.Map), ref peMode); if (dest.HasThing && dest.ThingDestroyed) { Log.Error(pawn + " pathing to destroyed thing " + dest.Thing); PatherFailed(); return; } if (!PawnCanOccupy(pawn.Position) && !TryRecoverFromUnwalkablePosition(true)) { return; } if (moving && curPath != null && destination == dest && this.peMode == peMode) { return; } if (!pawn.Map.reachability.CanReach(pawn.Position, dest, peMode, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false))) { PatherFailed(); return; } this.peMode = peMode; destination = dest; if (!IsNextCellWalkable() || NextCellDoorToWaitForOrManuallyOpen() != null || nextCellCostLeft == nextCellCostTotal) { ResetToCurrentPosition(); } PawnDestinationReservationManager.PawnDestinationReservation pawnDestinationReservation = pawn.Map.pawnDestinationReservationManager.MostRecentReservationFor(pawn); if (pawnDestinationReservation != null && ((destination.HasThing && pawnDestinationReservation.target != destination.Cell) || (pawnDestinationReservation.job != pawn.CurJob && pawnDestinationReservation.target != destination.Cell))) { pawn.Map.pawnDestinationReservationManager.ObsoleteAllClaimedBy(pawn); } if (AtDestinationPosition()) { PatherArrived(); return; } if (pawn.Downed) { Log.Error(pawn.LabelCap + " tried to path while downed. This should never happen. curJob=" + pawn.CurJob.ToStringSafe()); PatherFailed(); return; } if (curPath != null) { curPath.ReleaseToPool(); } curPath = null; moving = true; pawn.jobs.posture = PawnPosture.Standing; } }