private static Pawn TryGenerateNewNakedPawn(ref PawnGenerationRequest request, out string error, bool ignoreScenarioRequirements) { error = null; Pawn pawn = (Pawn)ThingMaker.MakeThing(request.KindDef.race, null); PawnGenerator.pawnsBeingGenerated.Add(new PawnGenerator.PawnGenerationStatus(pawn, null)); Pawn result; try { pawn.kindDef = request.KindDef; pawn.SetFactionDirect(request.Faction); PawnComponentsUtility.CreateInitialComponents(pawn); if (request.FixedGender.HasValue) { pawn.gender = request.FixedGender.Value; } else if (pawn.RaceProps.hasGenders) { if (Rand.Value < 0.5f) { pawn.gender = Gender.Male; } else { pawn.gender = Gender.Female; } } else { pawn.gender = Gender.None; } PawnGenerator.GenerateRandomAge(pawn, request); pawn.needs.SetInitialLevels(); if (!request.Newborn && request.CanGeneratePawnRelations) { PawnGenerator.GeneratePawnRelations(pawn, ref request); } if (pawn.RaceProps.Humanlike) { pawn.story.melanin = ((!request.FixedMelanin.HasValue) ? PawnSkinColors.RandomMelanin(request.Faction) : request.FixedMelanin.Value); pawn.story.crownType = ((Rand.Value >= 0.5f) ? CrownType.Narrow : CrownType.Average); pawn.story.hairColor = PawnHairColors.RandomHairColor(pawn.story.SkinColor, pawn.ageTracker.AgeBiologicalYears); PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName); pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, request.Faction.def); PawnGenerator.GenerateTraits(pawn, request); PawnGenerator.GenerateBodyType(pawn); PawnGenerator.GenerateSkills(pawn); } PawnGenerator.GenerateInitialHediffs(pawn, request); if (pawn.workSettings != null && request.Faction.IsPlayer) { pawn.workSettings.EnableAndInitialize(); } if (request.Faction != null && pawn.RaceProps.Animal) { pawn.GenerateNecessaryName(); } if (!request.AllowDead && (pawn.Dead || pawn.Destroyed)) { PawnGenerator.DiscardGeneratedPawn(pawn); error = "Generated dead pawn."; result = null; } else if (!request.AllowDowned && pawn.Downed) { PawnGenerator.DiscardGeneratedPawn(pawn); error = "Generated downed pawn."; result = null; } else if (request.MustBeCapableOfViolence && ((pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent)) || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))) { PawnGenerator.DiscardGeneratedPawn(pawn); error = "Generated pawn incapable of violence."; result = null; } else if (!ignoreScenarioRequirements && request.Context == PawnGenerationContext.PlayerStarter && !Find.Scenario.AllowPlayerStartingPawn(pawn)) { PawnGenerator.DiscardGeneratedPawn(pawn); error = "Generated pawn doesn't meet scenario requirements."; result = null; } else if (request.Validator != null && !request.Validator(pawn)) { PawnGenerator.DiscardGeneratedPawn(pawn); error = "Generated pawn didn't pass validator check."; result = null; } else { for (int i = 0; i < PawnGenerator.pawnsBeingGenerated.Count - 1; i++) { if (PawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime == null) { PawnGenerator.pawnsBeingGenerated[i] = new PawnGenerator.PawnGenerationStatus(PawnGenerator.pawnsBeingGenerated[i].Pawn, new List <Pawn>()); } PawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime.Add(pawn); } result = pawn; } } finally { PawnGenerator.pawnsBeingGenerated.RemoveLast <PawnGenerator.PawnGenerationStatus>(); } return(result); }