public static bool TryFindStartAndEndCells(this IncidentWorker_HerdMigration hm, Map map, PawnKindDef kind, out IntVec3 start, out IntVec3 end) { if (!RCellFinderExtended.TryFindRandomPawnEntryCell(out start, map, kind, CellFinder.EdgeRoadChance_Animal)) { end = IntVec3.Invalid; return(false); } end = IntVec3.Invalid; for (int i = 0; i < 8; i++) { IntVec3 startLocal = start; if (!CellFinderExtended.TryFindRandomEdgeCellWith((IntVec3 x) => map.reachability.CanReach(startLocal, x, PathEndMode.OnCell, TraverseMode.NoPassClosedDoors, Danger.Deadly), map, kind, CellFinder.EdgeRoadChance_Ignore, out IntVec3 result)) { break; } if (!end.IsValid || result.DistanceToSquared(start) > end.DistanceToSquared(start)) { end = result; } } return(end.IsValid); }
static bool Prefix(ref SignalAction_Ambush __instance, SignalArgs args) { Map map = __instance.Map; if (__instance.points <= 0f) { return(false); } List <Pawn> list = new List <Pawn>(); foreach (Pawn item in (IEnumerable <Pawn>)GenerateAmbushPawnsInfo.Invoke(__instance, new object[] { })) { // Skip out if the pawn isn't suitable for the map if (!map.PawnKindCanEnter(item.kindDef)) { Find.WorldPawns.PassToWorld(item); break; } IntVec3 result; if (__instance.spawnPawnsOnEdge) { // Changed to CellFinderExtended if (!CellFinderExtended.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(map) && !x.Fogged(map) && map.reachability.CanReachColony(x), map, item.kindDef, CellFinder.EdgeRoadChance_Ignore, out result)) { Find.WorldPawns.PassToWorld(item); break; } } // TODO: PawnKind aware find cell around else if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(__instance.spawnAround, __instance.spawnNear, map, out result)) { Find.WorldPawns.PassToWorld(item); break; } GenSpawn.Spawn(item, result, map); if (!__instance.spawnPawnsOnEdge) { for (int i = 0; i < 10; i++) { MoteMaker.ThrowAirPuffUp(item.DrawPos, map); } } list.Add(item); } if (!list.Any()) { return(false); } if (__instance.ambushType == SignalActionAmbushType.Manhunters) { for (int j = 0; j < list.Count; j++) { list[j].mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent); } } else { Faction faction = list[0].Faction; LordMaker.MakeNewLord(faction, new LordJob_AssaultColony(faction), map, list); } if (!__instance.spawnPawnsOnEdge) { for (int k = 0; k < list.Count; k++) { list[k].jobs.StartJob(JobMaker.MakeJob(JobDefOf.Wait, 120)); list[k].Rotation = Rot4.Random; } } Find.LetterStack.ReceiveLetter("LetterLabelAmbushInExistingMap".Translate(), "LetterAmbushInExistingMap".Translate(Faction.OfPlayer.def.pawnsPlural).CapitalizeFirst(), LetterDefOf.ThreatBig, list[0]); return(false); }