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); }
private static bool IsValidCandidateToRedress(Pawn pawn, PawnGenerationRequest request) { if (pawn.def != request.KindDef.race) { return(false); } if (!request.WorldPawnFactionDoesntMatter && pawn.Faction != request.Faction) { return(false); } if (!request.AllowDead && (pawn.Dead || pawn.Destroyed)) { return(false); } if (!request.AllowDowned && pawn.Downed) { return(false); } if (pawn.health.hediffSet.BleedRateTotal > 0.001f) { return(false); } if (!request.CanGeneratePawnRelations && pawn.RaceProps.IsFlesh && pawn.relations.RelatedToAnyoneOrAnyoneRelatedToMe) { return(false); } if (!request.AllowGay && pawn.RaceProps.Humanlike && pawn.story.traits.HasTrait(TraitDefOf.Gay)) { return(false); } if (request.Validator != null && !request.Validator(pawn)) { return(false); } if (request.FixedBiologicalAge.HasValue && pawn.ageTracker.AgeBiologicalYearsFloat != request.FixedBiologicalAge) { return(false); } if (request.FixedChronologicalAge.HasValue && (float)pawn.ageTracker.AgeChronologicalYears != request.FixedChronologicalAge) { return(false); } if (request.FixedGender.HasValue && pawn.gender != request.FixedGender) { return(false); } if (request.FixedLastName != null && ((NameTriple)pawn.Name).Last != request.FixedLastName) { return(false); } if (request.FixedMelanin.HasValue && pawn.story != null && pawn.story.melanin != request.FixedMelanin) { return(false); } if (request.MustBeCapableOfViolence) { if (pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent)) { return(false); } if (pawn.RaceProps.ToolUser && !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { return(false); } } return(true); }