private static Pawn GenerateOrRedressPawnInternal(PawnGenerationRequest request) { Pawn pawn = null; if (!request.Newborn && !request.ForceGenerateNewPawn) { if (request.ForceRedressWorldPawnIfFormerColonist) { IEnumerable <Pawn> validCandidatesToRedress = PawnGenerator.GetValidCandidatesToRedress(request); if (validCandidatesToRedress.Where(new Func <Pawn, bool>(PawnUtility.EverBeenColonistOrTameAnimal)).TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn)) { PawnGenerator.RedressPawn(pawn, request); Find.WorldPawns.RemovePawn(pawn); } } if (pawn == null && request.Inhabitant && request.Tile != -1) { SettlementBase settlement = Find.WorldObjects.WorldObjectAt <SettlementBase>(request.Tile); if (settlement != null && settlement.previouslyGeneratedInhabitants.Any <Pawn>()) { IEnumerable <Pawn> validCandidatesToRedress2 = PawnGenerator.GetValidCandidatesToRedress(request); if ((from x in validCandidatesToRedress2 where settlement.previouslyGeneratedInhabitants.Contains(x) select x).TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn)) { PawnGenerator.RedressPawn(pawn, request); Find.WorldPawns.RemovePawn(pawn); } } } if (pawn == null && Rand.Chance(PawnGenerator.ChanceToRedressAnyWorldPawn(request))) { IEnumerable <Pawn> validCandidatesToRedress3 = PawnGenerator.GetValidCandidatesToRedress(request); if (validCandidatesToRedress3.TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn)) { PawnGenerator.RedressPawn(pawn, request); Find.WorldPawns.RemovePawn(pawn); } } } bool redressed; if (pawn == null) { redressed = false; pawn = PawnGenerator.GenerateNewPawnInternal(ref request); if (pawn == null) { return(null); } if (request.Inhabitant && request.Tile != -1) { SettlementBase settlementBase = Find.WorldObjects.WorldObjectAt <SettlementBase>(request.Tile); if (settlementBase != null) { settlementBase.previouslyGeneratedInhabitants.Add(pawn); } } } else { redressed = true; } if (Find.Scenario != null) { Find.Scenario.Notify_PawnGenerated(pawn, request.Context, redressed); } return(pawn); }