Example #1
0
        // see PawnGenerator
        private void generate_pawn()
        {
            Gender gender;

            if (Rand.Value < 0.5f)
            {
                gender = Gender.Male;
            }
            else
            {
                gender = Gender.Female;
            }

            Faction f = Faction.OfPlayer;

            float melanin = PawnSkinColors.RandomMelanin(f);

            skinColor = PawnSkinColors.GetSkinColor(melanin);
            int age = 20;

            hairColor = PawnHairColors.RandomHairColor(skinColor, age);
            hairDef   = RandomHairDefFor(gender, f.def);

            crownType = Rand.Value >= 0.5f ? CrownType.Narrow : CrownType.Average;

            headGraphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(
                gender, skinColor, crownType).GraphicPath;

            bodyType = BodyType.Male;
        }
Example #2
0
        public static void FinalizeZombieGeneration(Zombie zombie)
        {
            var graphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(zombie.gender, zombie.story.SkinColor, zombie.story.crownType).GraphicPath;

            Traverse.Create(zombie.story).Field("headGraphicPath").SetValue(graphicPath);

            var request = new PawnGenerationRequest(zombie.kindDef);

            PawnApparelGenerator.GenerateStartingApparelFor(zombie, request);
            zombie.apparel.WornApparel.Do(apparel =>
            {
                Color[] colors =
                {
                    "442a0a".HexColor(),
                    "615951".HexColor(),
                    "1f4960".HexColor(),
                    "182a64".HexColor(),
                    "73000d".HexColor(),
                    "2c422a".HexColor(),
                    "332341".HexColor()
                };
                (colors.Clone() as Color[]).Do(c =>
                {
                    c.r *= Rand.Range(0.2f, 1f);
                    c.g *= Rand.Range(0.2f, 1f);
                    c.b *= Rand.Range(0.2f, 1f);
                    colors.Add(c);
                });
                colors.Add("000000".HexColor());

                apparel.SetColor(colors[Rand.Range(0, colors.Length)]);
            });
        }
Example #3
0
        public PawnGraphicRenderer(float melanin)
        {
            Color     skinColor = PawnSkinColors.GetSkinColor(this.melanin = melanin);
            Gender    gender    = (Rand.Value < 0.5f) ? Gender.Male : Gender.Female;
            CrownType crownType = (Rand.Value < 0.5f) ? CrownType.Average : CrownType.Narrow;
            HairDef   hairDef   = RandomHairDefFor(gender);
            Color     hairColor = PawnHairColors.RandomHairColor(skinColor, 18);

            headGraphic = GraphicDatabaseHeadRecords.GetHeadRandom(gender, skinColor, crownType, false);
            hairGraphic = GraphicDatabase.Get <Graphic_Multi>(hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, hairColor);
        }
Example #4
0
        //Patch for Caravan/Worldmap death
        //TBF

        //Patch death messages
        //TBF

        //Change Appearance, Traits and memories of pawns
        static void Regenerate(Pawn __instance)
        {
            // Health State Changes ----------------------------------------------------------------------------------------------------------

            //Resurrect the __instance
            ResurrectionUtility.Resurrect(__instance);

            //Remove all bad hediffs
            foreach (Hediff h in __instance.health.hediffSet.GetHediffs <Hediff>())
            {
                if (h.def.isBad)
                {
                    __instance.health.RemoveHediff(h);
                }
            }

            //Add resurrection sickness
            __instance.health.AddHediff(HediffDef.Named("ResurrectionSickness"));

            //Remove current RegenHediff and add the next
            BodyPartRecord heart = __instance.health.hediffSet.GetNotMissingParts().First(bpr => bpr.def == BodyPartDefOf.Heart);

            HediffDef Regen1Def  = HediffDef.Named("Regeneration01");
            HediffDef Regen2Def  = HediffDef.Named("Regeneration02");
            HediffDef Regen3Def  = HediffDef.Named("Regeneration03");
            HediffDef Regen4Def  = HediffDef.Named("Regeneration04");
            HediffDef Regen5Def  = HediffDef.Named("Regeneration05");
            HediffDef Regen6Def  = HediffDef.Named("Regeneration06");
            HediffDef Regen7Def  = HediffDef.Named("Regeneration07");
            HediffDef Regen8Def  = HediffDef.Named("Regeneration08");
            HediffDef Regen9Def  = HediffDef.Named("Regeneration09");
            HediffDef Regen10Def = HediffDef.Named("Regeneration10");
            HediffDef Regen11Def = HediffDef.Named("Regeneration11");
            HediffDef Regen12Def = HediffDef.Named("Regeneration12");
            HediffDef Regen13Def = HediffDef.Named("Regeneration13");

            if (__instance.health.hediffSet.HasHediff(Regen1Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen1Def)); __instance.health.AddHediff(Regen2Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen2Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen2Def)); __instance.health.AddHediff(Regen3Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen3Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen3Def)); __instance.health.AddHediff(Regen4Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen4Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen4Def)); __instance.health.AddHediff(Regen5Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen5Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen5Def)); __instance.health.AddHediff(Regen6Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen6Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen6Def)); __instance.health.AddHediff(Regen7Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen7Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen7Def)); __instance.health.AddHediff(Regen8Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen8Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen8Def)); __instance.health.AddHediff(Regen9Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen9Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen9Def)); __instance.health.AddHediff(Regen10Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen10Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen10Def)); __instance.health.AddHediff(Regen11Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen11Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen11Def)); __instance.health.AddHediff(Regen12Def, heart);
            }
            else if (__instance.health.hediffSet.HasHediff(Regen12Def))
            {
                __instance.health.RemoveHediff(__instance.health.hediffSet.GetFirstHediffOfDef(Regen12Def)); __instance.health.AddHediff(Regen13Def, heart);
            }

            // Visual Changes ----------------------------------------------------------------------------------------------------------

            //Gender
            __instance.gender = GenderSwap(__instance.gender);

            //Skintone
            __instance.story.melanin = 0.01f * Rand.Range(10, 200);

            //Head
            var graphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(__instance.gender, __instance.story.SkinColor, __instance.story.crownType).GraphicPath;

            Traverse.Create(__instance.story).Field("headGraphicPath").SetValue(graphicPath);

            //Hair
            __instance.story.hairDef   = PawnHairChooser.RandomHairDefFor(__instance, FactionDefOf.PlayerColony);
            __instance.story.hairColor = HairColor();

            //Body
            __instance.story.bodyType = BodySwap(__instance.gender);

            //Redraw the __instance to trigger the above affects
            __instance.Drawer.renderer.graphics.nakedGraphic = null;

            // Bio Changes ----------------------------------------------------------------------------------------------------------

            //randomise traits
            __instance.story.traits.allTraits.Clear();
            int i    = 0;
            int rInt = Rand.RangeInclusive(1, 3);

            while (i < rInt)
            {
                TraitDef random = DefDatabase <TraitDef> .GetRandom();

                Trait trait = new Trait(random, PawnGenerator.RandomTraitDegree(random), false);
                __instance.story.traits.GainTrait(trait);
                Trait trait2 = new Trait(random, PawnGenerator.RandomTraitDegree(random), false);
                __instance.story.traits.GainTrait(trait2);
                i++;
            }

            //Add Memory
            __instance.needs.mood.thoughts.memories.TryGainMemory(RegenerationThoughtDefs.RecentlyRegenerated, null);

            //Add debuff thought to all related colonists
            foreach (Pawn p in __instance.relations.RelatedPawns)
            {
                //Log.Warning("related to: " + p.Name);
                try
                {
                    if (!p.health.Dead)
                    {
                        p.needs.mood.thoughts.memories.TryGainMemory(RegenerationThoughtDefs.KnownColonistRegeneratedSocial, __instance);
                        p.needs.mood.thoughts.memories.TryGainMemory(RegenerationThoughtDefs.KnownColonistRegenerated);
                    }
                }
                catch
                {
                    Log.Warning("Couldn't add social debuff to " + p.Name);
                }
            }

            // Visual effects -------------------------------------------------------------------------------------------------------

            //Glow effect (ugly approach, look at cleaning this up)
            MoteMaker.ThrowAirPuffUp(__instance.DrawPos, __instance.Map);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
            MoteMaker.ThrowFireGlow(__instance.Position, __instance.Map, 3f);
        }
        //public static AIPawn GeneratePawn(PawnKindDef kindDef, Faction faction, Map map, Gender gender = Gender.Female, int tries = 0)
        public static AIPawn GenerateAIPawn(ref PawnGenerationRequest request, Map map, int tries = 0)
        {
            BackstoryHelper.AddNewBackstoriesToDatabase(); // First add the new backstories to the database

            //Log.Error("0");

            AIPawn pawnAI = (AIPawn)ThingMaker.MakeThing(request.KindDef.race, null);

            //Log.Error("1");
            GetXMLData(pawnAI);

            //request.EnsureNonNullFaction();

            pawnAI.kindDef = request.KindDef;
            pawnAI.SetFactionDirect(request.Faction);

            PawnComponentsUtility.CreateInitialComponents(pawnAI);

            //Log.Error("2");

            // Needs to be set because of not flesh user
            if (pawnAI.ownership == null)
            {
                pawnAI.ownership = new Pawn_Ownership(pawnAI);
            }

            pawnAI.relations = new Pawn_RelationsTracker(pawnAI);
            pawnAI.guest     = new Pawn_GuestTracker(pawnAI);

            pawnAI.guilt     = new Pawn_GuiltTracker(pawnAI);
            pawnAI.royalty   = new Pawn_RoyaltyTracker(pawnAI);
            pawnAI.abilities = new Pawn_AbilityTracker(pawnAI);
            pawnAI.relations = new Pawn_RelationsTracker(pawnAI);

            if (request.FixedGender.HasValue)
            {
                pawnAI.gender = request.FixedGender.Value;
            }
            else if (pawnAI.RaceProps.hasGenders)
            {
                if (Rand.Value < 0.5f)
                {
                    pawnAI.gender = Gender.Male;
                }
                else
                {
                    pawnAI.gender = Gender.Female;
                }
            }
            else
            {
                pawnAI.gender = Gender.Female;
            }

            SetBirthday(pawnAI);
            pawnAI.needs.SetInitialLevels();


            //Log.Error("3");

            AIPawnGenerator.GenerateInitialHediffs(pawnAI);


            if (pawnAI.RaceProps.Humanlike)
            {
                pawnAI.story.melanin   = 0.1f;
                pawnAI.story.crownType = CrownType.Average;
                pawnAI.story.hairColor = PawnHairColors.RandomHairColor(pawnAI.story.SkinColor, pawnAI.ageTracker.AgeBiologicalYears);

                pawnAI.story.childhood = GetBackstory();
                //pawnAI.story.adulthood = GetBackstory();

                string headGraphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(pawnAI.gender, pawnAI.story.SkinColor, pawnAI.story.crownType, false).GraphicPath;
                // With this Reflection you can access a private variable! Here: The private string "headGraphicPath" is set
                System.Reflection.FieldInfo fi = typeof(Pawn_StoryTracker).GetField("headGraphicPath", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                fi.SetValue(pawnAI.story, headGraphicPath);

                pawnAI.story.hairDef = GetHair();

                pawnAI.story.bodyType = ((pawnAI.gender != Gender.Female) ? BodyTypeDefOf.Male : BodyTypeDefOf.Female);

                MakeSkillsFromBackstory(pawnAI);
                GiveTraitsTo(pawnAI);

                if (pawnAI.workSettings != null && (request.Faction == Faction.OfPlayer))
                {
                    pawnAI.workSettings.EnableAndInitialize();
                }
            }

            if (pawnAI.RaceProps.ToolUser)
            {
                GenerateBaseApparel(pawnAI);
            }

            pawnAI.Name = GetName(pawnAI.def, map);

            pawnAI.royalty = null;

            //Log.Error("4");
            //PawnGenerationRequest request = new PawnGenerationRequest(pawnAI.kindDef , Faction.OfPlayer, PawnGenerationContext.All, true, true, false,false, false, false, 0, false, false, false,null, 0,0, pawnAI.gender, null, null);

            //PawnInventoryGenerator.GenerateInventoryFor(pawnAI, request);

            if (!pawnAI.Dead)
            {
                return(pawnAI);
            }

            if (tries < 10)
            {
                return(GenerateAIPawn(ref request, map, tries + 1));
            }

            return(null);
        }
Example #6
0
        public static Droid GenerateDroid(Blueprint bp, Faction faction)
        {
            Droid droid = (Droid)ThingMaker.MakeThing(bp.KindDef.race);

            droid.SetFactionDirect(faction);
            droid.kindDef             = bp.KindDef;
            droid.RaceProps.corpseDef = ThingDef.Named("MD2DroidCorpse");

            #region Trackers
            droid.thinker          = new Pawn_Thinker(droid);
            droid.playerController = new Pawn_PlayerController(droid);
            droid.inventory        = new Pawn_InventoryTracker(droid);
            droid.pather           = new Pawn_PathFollower(droid);
            droid.jobs             = new Pawn_JobTracker(droid);
            droid.health           = new Pawn_HealthTracker(droid);
            droid.ageTracker       = new Pawn_AgeTracker(droid);
            droid.filth            = new Pawn_FilthTracker(droid);
            droid.mindState        = new Pawn_MindState(droid);
            droid.equipment        = new Pawn_EquipmentTracker(droid);
            droid.apparel          = new Pawn_ApparelTracker(droid);
            droid.natives          = new Pawn_NativeVerbs(droid);
            droid.meleeVerbs       = new Pawn_MeleeVerbs(droid);
            droid.carryHands       = new Pawn_CarryHands(droid);
            droid.ownership        = new Pawn_Ownership(droid);
            droid.skills           = new Pawn_SkillTracker(droid);
            droid.story            = new Pawn_StoryTracker(droid);
            droid.workSettings     = new Pawn_WorkSettings(droid);
            droid.guest            = new Pawn_GuestTracker(droid);
            droid.needs            = new Pawn_NeedsTracker(droid);
            droid.stances          = new Pawn_StanceTracker(droid);

            typeof(Pawn_NeedsTracker).GetMethod("AddNeed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(droid.needs, new object[] { DefDatabase <NeedDef> .GetNamed("Mood") });
            #endregion

            droid.gender = droid.RaceProps.hasGenders ? Gender.Male : Gender.None;

            droid.ageTracker.SetChronologicalBirthDate(GenDate.CurrentYear, GenDate.DayOfMonth);
            droid.story.skinColor       = PawnSkinColors.PaleWhiteSkin;
            droid.story.crownType       = CrownType.Narrow;
            droid.story.headGraphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(Gender.Male, droid.story.skinColor, droid.story.crownType).GraphicPath;
            droid.story.hairColor       = PawnHairColors.RandomHairColor(droid.story.skinColor, droid.ageTracker.AgeBiologicalYears);
            droid.story.name            = new PawnName()
            {
                first = "Droid",
                last  = "Droid",
                nick  = bp.Name
            };

            #region Managers

            droid.meta      = new MetaDataManager(droid, bp);
            droid.utilities = new UtilityManager(droid);

            WorkPackageDef        maintenance  = WorkPackageDef.Named("MD2MaintenancePackage");
            WorkPackageDef        firefighting = WorkPackageDef.Named("MD2FirefighterPackage");
            List <WorkPackageDef> list         = bp.WorkPackages;
            if (!list.Contains(maintenance))
            {
                list.Add(maintenance);
            }
            if (!list.Contains(firefighting))
            {
                list.Add(firefighting);
            }
            droid.work = new WorkManager(list, droid);

            droid.backstory = new BackstoryManager(droid);
            droid.backstory.SpawnSetup();

            droid.drawManager = new DrawManager(bp.BodyGraphicDef, bp.HeadGraphicDef, droid);
            droid.drawManager.SpawnSetup();

            droid.parts = new PartsManager(droid);
            #endregion

            foreach (SkillRecord sk in droid.skills.skills)
            {
                sk.level   = (bp.StartingSkillLevel > 20) ? 20 : (bp.StartingSkillLevel <= 0) ? 1 : bp.StartingSkillLevel;
                sk.passion = bp.SkillPassion;
            }
            droid.workSettings.EnableAndInitialize();

            foreach (var def in DefDatabase <WorkTypeDef> .AllDefs)
            {
                if (droid.work.Contains(def))
                {
                    droid.workSettings.SetPriority(def, 4);
                }
                else
                {
                    droid.workSettings.SetPriority(def, 0);
                    droid.workSettings.Disable(def);
                }
            }

            return(droid);
        }
Example #7
0
        public bool AddNewBaby(Pawn mother, Pawn father)
        {
            float  melanin;
            string lastname;

            if (xxx.is_human(mother))
            {
                if (xxx.is_human(father))
                {
                    melanin = ChildRelationUtility.GetRandomChildSkinColor(father.story?.melanin ?? 0f, mother.story?.melanin ?? 0f);
                    //melanin = (mother.story?.melanin ?? 0f + father.story?.melanin ?? 0f) / 2;
                    lastname = NameTriple.FromString(father.Name.ToStringFull).Last;
                }
                else
                {
                    melanin  = mother.story?.melanin ?? 0f;
                    lastname = NameTriple.FromString(mother.Name.ToStringFull).Last;
                }
            }
            else if (xxx.is_human(father))
            {
                melanin  = father.story?.melanin ?? 0f;
                lastname = NameTriple.FromString(father.Name.ToStringFull).Last;
            }
            else
            {
                melanin  = Rand.Range(0, 1.0f);
                lastname = "";
            }

            PawnGenerationRequest request = new PawnGenerationRequest(
                newborn: true,
                allowDowned: true,
                faction: mother.IsPrisoner ? null : mother.Faction,
                canGeneratePawnRelations: false,
                forceGenerateNewPawn: true,
                colonistRelationChanceFactor: 0,
                allowFood: false,
                allowAddictions: false,
                relationWithExtraPawnChanceFactor: 0,
                fixedMelanin: melanin,
                fixedLastName: lastname,
                kind: BabyPawnKindDecider(mother, father)
                //fixedIdeo: mother.Ideo,
                //forbidAnyTitle: true,
                //forceNoBackstory:true
                );

            int         division       = 1;
            HairDef     firsthair      = null;
            Color       firsthaircolor = Color.white;
            BodyTypeDef firstbody      = null;
            CrownType   firstcrown     = CrownType.Undefined;
            string      firstheadpath  = null;
            string      firstHARcrown  = null;

            while (Rand.Chance(Configurations.EnzygoticTwinsChance) && division < Configurations.MaxEnzygoticTwins)
            {
                division++;
            }
            for (int i = 0; i < division; i++)
            {
                Pawn baby = GenerateBaby(request, mother, father);
                if (division > 1)
                {
                    if (i == 0 && baby.story != null)
                    {
                        firsthair           = baby.story.hairDef;
                        firsthaircolor      = baby.story.hairColor;
                        request.FixedGender = baby.gender;
                        firstbody           = baby.story.bodyType;
                        firstcrown          = baby.story.crownType;
                        firstheadpath       = (string)baby.story.GetMemberValue("headGraphicPath");
                        if (firstheadpath == null)
                        {
                            Graphic_Multi head = GraphicDatabaseHeadRecords.GetHeadRandom(baby.gender, baby.story.SkinColor, baby.story.crownType, true);
                            if (head != null)
                            {
                                baby.story.SetMemberValue("headGraphicPath", head.GraphicPath);
                            }
                            firstheadpath = (string)baby.story.GetMemberValue("headGraphicPath");
                        }
                        if (Configurations.HARActivated && baby.IsHAR())
                        {
                            firstHARcrown = baby.GetHARCrown();
                        }
                    }
                    else
                    {
                        if (baby.story != null)
                        {
                            baby.story.hairDef   = firsthair;
                            baby.story.hairColor = firsthaircolor;
                            baby.story.bodyType  = firstbody;
                            baby.story.crownType = firstcrown;
                            baby.story.SetMemberValue("headGraphicPath", firstheadpath);

                            if (Configurations.HARActivated && baby.IsHAR())
                            {
                                baby.SetHARCrown(firstHARcrown);
                            }
                        }
                    }
                }

                if (baby != null)
                {
                    babies.Add(baby);
                }
            }



            return(true);
        }
        public static Pawn Copy(Pawn sourcePawn, PawnKindDef kindDef, Faction faction, bool forceBodyVisual = false, bool forceApparel = false, bool forceWeapon = false)
        {
            Pawn pawn = (Pawn)ThingMaker.MakeThing(kindDef.race, null);

            pawn.kindDef = kindDef;
            pawn.SetFactionDirect(faction);
            pawn.pather     = new Pawn_PathFollower(pawn);
            pawn.ageTracker = new Pawn_AgeTracker(pawn);
            pawn.health     = new Pawn_HealthTracker(pawn);
            pawn.jobs       = new Pawn_JobTracker(pawn);
            pawn.mindState  = new Pawn_MindState(pawn);
            pawn.filth      = new Pawn_FilthTracker(pawn);
            pawn.needs      = new Pawn_NeedsTracker(pawn);
            pawn.stances    = new Pawn_StanceTracker(pawn);
            pawn.InitUnsavedUniversalComponents();

            if (pawn.RaceProps.ToolUser)
            {
                pawn.equipment = new Pawn_EquipmentTracker(pawn);
                pawn.carrier   = new Pawn_CarryTracker(pawn);
                pawn.apparel   = new Pawn_ApparelTracker(pawn);
                pawn.inventory = new Pawn_InventoryTracker(pawn);
            }
            if (pawn.RaceProps.Humanlike)
            {
                pawn.ownership    = new Pawn_Ownership(pawn);
                pawn.skills       = new Pawn_SkillTracker(pawn);
                pawn.talker       = new Pawn_TalkTracker(pawn);
                pawn.story        = new Pawn_StoryTracker(pawn);
                pawn.workSettings = new Pawn_WorkSettings(pawn);
            }
            if (pawn.RaceProps.intelligence <= Intelligence.ToolUser)
            {
                pawn.caller = new Pawn_CallTracker(pawn);
            }
            PawnUtility.AddAndRemoveComponentsAsAppropriate(pawn);
            if (pawn.RaceProps.hasGenders)
            {
                if ((sourcePawn != null) &&
                    (sourcePawn.RaceProps.hasGenders) &&
                    (sourcePawn.gender != Gender.None))
                {
                    pawn.gender = sourcePawn.gender;
                }
                else
                {
                    if (Rand.Value < 0.5f)
                    {
                        pawn.gender = Gender.Male;
                    }
                    else
                    {
                        pawn.gender = Gender.Female;
                    }
                }
            }
            else
            {
                pawn.gender = Gender.None;
            }

            AbilityEffect_Revive.GenerateRandomAge_Coping(pawn, sourcePawn);
            AbilityEffect_Revive.GenerateInitialHediffs_Coping(pawn, sourcePawn);
            if (pawn.RaceProps.Humanlike)
            {
                if ((sourcePawn != null) &&
                    (forceBodyVisual))
                {
                    pawn.story.skinColor       = sourcePawn.story.skinColor;
                    pawn.story.crownType       = sourcePawn.story.crownType;
                    pawn.story.headGraphicPath = sourcePawn.story.headGraphicPath;
                    pawn.story.hairColor       = sourcePawn.story.hairColor;

                    AbilityEffect_Revive.GiveAppropriateBioTo_Coping(pawn, sourcePawn);
                    pawn.story.hairDef = sourcePawn.story.hairDef;
                    AbilityEffect_Revive.GiveRandomTraitsTo_Coping(pawn, sourcePawn);
                    pawn.story.GenerateSkillsFromBackstory();
                }
                else
                {
                    pawn.story.skinColor       = PawnSkinColors.RandomSkinColor();
                    pawn.story.crownType       = ((Rand.Value >= 0.5f) ? CrownType.Narrow : CrownType.Average);
                    pawn.story.headGraphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(pawn.gender, pawn.story.skinColor, pawn.story.crownType).GraphicPath;
                    pawn.story.hairColor       = PawnHairColors.RandomHairColor(pawn.story.skinColor, pawn.ageTracker.AgeBiologicalYears);

                    PawnBioGenerator.GiveAppropriateBioTo(pawn, faction.def);
                    pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, faction.def);
                    AbilityEffect_Revive.GiveRandomTraitsTo(pawn);
                    pawn.story.GenerateSkillsFromBackstory();
                }
            }

            AbilityEffect_Revive.GenerateStartingApparelFor_Coping(pawn, sourcePawn, forceApparel);
            AbilityEffect_Revive.TryGenerateWeaponFor_Coping(pawn, sourcePawn, forceWeapon);
            AbilityEffect_Revive.GenerateInventoryFor_Coping(pawn, sourcePawn);
            PawnUtility.AddAndRemoveComponentsAsAppropriate(pawn);
            return(pawn);
        }