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 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; } }