public static IntVec3 FindSiegePositionFrom(IntVec3 entrySpot, Map map) { if (!entrySpot.IsValid) { IntVec3 intVec; if (!CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map), map, CellFinder.EdgeRoadChance_Ignore, out intVec)) { intVec = CellFinder.RandomCell(map); } Log.Error("Tried to find a siege position from an invalid cell. Using " + intVec, false); return(intVec); } IntVec3 result; for (int i = 70; i >= 20; i -= 10) { if (RCellFinder_Zombiefied.TryFindSiegePosition(entrySpot, (float)i, map, out result)) { return(result); } } if (RCellFinder_Zombiefied.TryFindSiegePosition(entrySpot, 100f, map, out result)) { return(result); } Log.Error(string.Concat(new object[] { "Could not find siege spot from ", entrySpot, ", using ", entrySpot }), false); return(entrySpot); }
public static bool TryFindBestExitSpot(Pawn pawn, out IntVec3 spot, TraverseMode mode = TraverseMode.ByPawn) { if (mode == TraverseMode.PassAllDestroyableThings && !pawn.Map.reachability.CanReachMapEdge(pawn.Position, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, true))) { return(RCellFinder_Zombiefied.TryFindRandomPawnEntryCell(out spot, pawn.Map, 0f, true, delegate(IntVec3 x) { Pawn pawn2 = pawn; LocalTargetInfo dest = x; PathEndMode peMode = PathEndMode.OnCell; Danger maxDanger = Danger.Deadly; TraverseMode mode2 = mode; return pawn2.CanReach(dest, peMode, maxDanger, false, mode2); })); } int num = 0; int num2 = 0; IntVec3 intVec2; while (true) { num2++; if (num2 > 30) { break; } IntVec3 intVec; bool flag = CellFinder.TryFindRandomCellNear(pawn.Position, pawn.Map, num, null, out intVec, -1); num += 4; if (flag) { int num3 = intVec.x; intVec2 = new IntVec3(0, 0, intVec.z); if (pawn.Map.Size.z - intVec.z < num3) { num3 = pawn.Map.Size.z - intVec.z; intVec2 = new IntVec3(intVec.x, 0, pawn.Map.Size.z - 1); } if (pawn.Map.Size.x - intVec.x < num3) { num3 = pawn.Map.Size.x - intVec.x; intVec2 = new IntVec3(pawn.Map.Size.x - 1, 0, intVec.z); } if (intVec.z < num3) { intVec2 = new IntVec3(intVec.x, 0, 0); } if (intVec2.Standable(pawn.Map) && pawn.CanReach(intVec2, PathEndMode.OnCell, Danger.Deadly, true, mode)) { goto Block_9; } } } spot = pawn.Position; return(false); Block_9: spot = intVec2; return(true); }
public static bool TryFindRandomCellNearTheCenterOfTheMapWith(Predicate <IntVec3> validator, Map map, out IntVec3 result) { int startingSearchRadius = Mathf.Clamp(Mathf.Max(map.Size.x, map.Size.z) / 20, 3, 25); return(RCellFinder_Zombiefied.TryFindRandomCellNearWith(map.Center, validator, map, out result, startingSearchRadius, 2147483647)); }
public static bool TryFindRandomSpotJustOutsideColony(Pawn searcher, out IntVec3 result) { return(RCellFinder_Zombiefied.TryFindRandomSpotJustOutsideColony(searcher.Position, searcher.Map, searcher, out result, null)); }
public static bool TryFindRandomSpotJustOutsideColony(IntVec3 originCell, Map map, out IntVec3 result) { return(RCellFinder_Zombiefied.TryFindRandomSpotJustOutsideColony(originCell, map, null, out result, null)); }
public static IntVec3 RandomWanderDestFor(Pawn pawn, IntVec3 root, float radius, Func <Pawn, IntVec3, IntVec3, bool> validator, Danger maxDanger) { if (radius > 12f) { Log.Warning(string.Concat(new object[] { "wanderRadius of ", radius, " is greater than Region.GridSize of ", 12, " and will break." }), false); } bool flag = UnityData.isDebugBuild && DebugViewSettings.drawDestSearch; if (root.GetRegion(pawn.Map, RegionType.Set_Passable) != null) { int maxRegions = Mathf.Max((int)radius / 3, 13); CellFinder.AllRegionsNear(RCellFinder_Zombiefied.regions, root.GetRegion(pawn.Map, RegionType.Set_Passable), maxRegions, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), (Region reg) => reg.extentsClose.ClosestDistSquaredTo(root) <= radius * radius, null, RegionType.Set_Passable); if (flag) { pawn.Map.debugDrawer.FlashCell(root, 0.6f, "root", 50); } if (RCellFinder_Zombiefied.regions.Count > 0) { for (int i = 0; i < 35; i++) { IntVec3 intVec = IntVec3.Invalid; for (int j = 0; j < 5; j++) { IntVec3 randomCell = RCellFinder_Zombiefied.regions.RandomElementByWeight((Region reg) => (float)reg.CellCount).RandomCell; if ((float)randomCell.DistanceToSquared(root) <= radius * radius) { intVec = randomCell; break; } } if (!intVec.IsValid) { if (flag) { pawn.Map.debugDrawer.FlashCell(intVec, 0.32f, "distance", 50); } } else { if (RCellFinder_Zombiefied.CanWanderToCell(intVec, pawn, root, validator, i, maxDanger)) { if (flag) { pawn.Map.debugDrawer.FlashCell(intVec, 0.9f, "go!", 50); } RCellFinder_Zombiefied.regions.Clear(); return(intVec); } if (flag) { pawn.Map.debugDrawer.FlashCell(intVec, 0.6f, "validation", 50); } } } } RCellFinder_Zombiefied.regions.Clear(); } IntVec3 position; if (!CellFinder.TryFindRandomCellNear(root, pawn.Map, Mathf.FloorToInt(radius), (IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.None, false, TraverseMode.ByPawn) && !c.IsForbidden(pawn) && (validator == null || validator(pawn, c, root)), out position, -1) && !CellFinder.TryFindRandomCellNear(root, pawn.Map, Mathf.FloorToInt(radius), (IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.None, false, TraverseMode.ByPawn) && !c.IsForbidden(pawn), out position, -1) && !CellFinder.TryFindRandomCellNear(root, pawn.Map, Mathf.FloorToInt(radius), (IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn), out position, -1) && !CellFinder.TryFindRandomCellNear(root, pawn.Map, 20, (IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.None, false, TraverseMode.ByPawn) && !c.IsForbidden(pawn), out position, -1) && !CellFinder.TryFindRandomCellNear(root, pawn.Map, 30, (IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn), out position, -1) && !CellFinder.TryFindRandomCellNear(pawn.Position, pawn.Map, 5, (IntVec3 c) => c.InBounds(pawn.Map) && pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn), out position, -1)) { position = pawn.Position; } if (flag) { pawn.Map.debugDrawer.FlashCell(position, 0.4f, "fallback", 50); } return(position); }