static bool Prefix(ref bool __result, IncidentWorker_FarmAnimalsWanderIn __instance, IncidentParms parms) { Map map = (Map)parms.target; object[] parameters = new object[] { map, null }; bool flag = (bool)TryFindRandomPawnKindInfo.Invoke(__instance, parameters); if (!flag) { return(false); } PawnKindDef kind = (PawnKindDef)parameters[1]; // Check this AFTER getting a pawn kind if (!RCellFinderExtended.TryFindRandomPawnEntryCell(out IntVec3 result, map, kind, CellFinder.EdgeRoadChance_Animal)) { return(false); } int num = Mathf.Clamp(GenMath.RoundRandom(2.5f / kind.RaceProps.baseBodySize), 2, 10); for (int i = 0; i < num; i++) { IntVec3 loc = CellFinderExtended.RandomClosewalkCellNear(result, map, kind, 12); Pawn pawn = PawnGenerator.GeneratePawn(kind); GenSpawn.Spawn(pawn, loc, map, Rot4.Random); pawn.SetFaction(Faction.OfPlayer); } SendStandardLetterInfo.Invoke(__instance, new object[] { "LetterLabelFarmAnimalsWanderIn".Translate(kind.GetLabelPlural()).CapitalizeFirst(), "LetterFarmAnimalsWanderIn".Translate(kind.GetLabelPlural()), LetterDefOf.PositiveEvent, parms, new LookTargets(result, map), new NamedArgument[0] { } }); return(false); }
public static bool Prefix(ref List <Pawn> __result, IncidentWorker_NeutralGroup __instance, IncidentParms parms) { Map map = (Map)parms.target; List <Pawn> list = PawnGroupMakerUtility.GeneratePawns(IncidentParmsUtility.GetDefaultPawnGroupMakerParms((PawnGroupKindDef)PawnGroupKindDefInfo.Invoke(__instance, new object[] { }), parms, ensureCanGenerateAtLeastOnePawn: true), warnOnZeroResults: false).ToList(); foreach (Pawn item in list) { IntVec3 loc = CellFinderExtended.RandomClosewalkCellNear(parms.spawnCenter, map, item.kindDef, 5); GenSpawn.Spawn(item, loc, map); } __result = list; return(false); }
public static bool Prefix(Caravan caravan, Map map, CaravanEnterMode enterMode, CaravanDropInventoryMode dropInventoryMode = CaravanDropInventoryMode.DoNotDrop, bool draftColonists = false, Predicate <IntVec3> extraCellValidator = null) { if (enterMode == CaravanEnterMode.None) { Log.Error("Caravan " + caravan + " tried to enter map " + map + " with enter mode " + enterMode); enterMode = CaravanEnterMode.Edge; } Predicate <IntVec3> wrapped = (IntVec3 x) => (extraCellValidator == null || extraCellValidator(x)) && map.PawnKindCanEnter(caravan.pawns.InnerListForReading.First().kindDef); IntVec3 enterCell = (IntVec3)GetEnterCellInfo.Invoke(null, new object[] { caravan, map, enterMode, wrapped }); Func <Pawn, IntVec3> spawnCellGetter = (Pawn p) => CellFinderExtended.RandomSpawnCellForPawnNear(enterCell, map, p.kindDef); EnterWithFuncInfo.Invoke(null, new object[] { caravan, map, spawnCellGetter, dropInventoryMode, draftColonists }); return(false); }
public static bool TryFindSpawnCellAroundOrNear(CellRect around, IntVec3 near, Map map, PawnKindDef kind, out IntVec3 spawnCell) { if (near.IsValid) { if (!CellFinderExtended.TryFindRandomSpawnCellForPawnNear(near, map, kind, out spawnCell, 10)) { return(false); } } else if (!CellFinder.TryFindRandomCellInsideWith(around.ExpandedBy(8), (IntVec3 x) => !around.Contains(x) && x.InBounds(map) && x.Standable(map) && !x.Fogged(map) && map.PawnKindCanEnter(kind), out spawnCell)) { return(false); } return(true); }
static bool Prefix(Transition trans) { LordToil_Travel lordToil_Travel = (LordToil_Travel)trans.target; if (!lordToil_Travel.HasDestination()) { Pawn pawn = lordToil_Travel.lord.ownedPawns.RandomElement(); if (!CellFinderExtended.TryFindRandomPawnExitCell(pawn, out IntVec3 result)) { RCellFinderExtended.TryFindRandomPawnEntryCell(out result, pawn.Map, pawn.kindDef, 0f); } lordToil_Travel.SetDestination(result); } return(false); }
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 bool __result, IntVec3 loc, Map ___map) { PawnKindDef pawnKindDef = ___map.Biome.AllWildAnimals.Where( (PawnKindDef a) => ___map.mapTemperature.SeasonAcceptableFor(a.race) && ___map.PawnKindCanEnter(a) && !a.UnreachableLocationCheck(___map, loc) ).RandomElementByWeight((PawnKindDef def) => ___map.Biome.CommonalityOfAnimal(def) / def.wildGroupSize.Average); if (pawnKindDef == null) { Log.Error("No spawnable animals right now."); __result = false; return(false); } int randomInRange = pawnKindDef.wildGroupSize.RandomInRange; int radius = Mathf.CeilToInt(Mathf.Sqrt(pawnKindDef.wildGroupSize.max)); for (int i = 0; i < randomInRange; i++) { IntVec3 loc2 = CellFinderExtended.RandomClosewalkCellNear(loc, ___map, pawnKindDef, radius); GenSpawn.Spawn(PawnGenerator.GeneratePawn(pawnKindDef), loc2, ___map); } __result = true; return(false); }
public static bool Prefix(ref IntVec3 __result, Pawn pawn, Pawn downedPawn) { __result = CellFinderExtended.RandomClosewalkCellNear(pawn.mindState.duty.focusSecond.Cell, pawn.Map, pawn.kindDef, 6, (IntVec3 x) => x.Standable(pawn.Map) && StoreUtility.IsGoodStoreCell(x, pawn.Map, downedPawn, pawn, pawn.Faction)); return(false); }
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); }