public static Name GeneratePawnName(Pawn pawn, NameStyle style = NameStyle.Full, string forcedLastName = null)
 {
     if (style == NameStyle.Full)
     {
         RulePackDef nameGenerator = pawn.RaceProps.GetNameGenerator(pawn.gender);
         if (nameGenerator != null)
         {
             string name = NameGenerator.GenerateName(nameGenerator, (string x) => !new NameSingle(x, false).UsedThisGame, false, null);
             return(new NameSingle(name, false));
         }
         if (pawn.Faction != null && pawn.Faction.def.pawnNameMaker != null)
         {
             string rawName = NameGenerator.GenerateName(pawn.Faction.def.pawnNameMaker, delegate(string x)
             {
                 NameTriple nameTriple4 = NameTriple.FromString(x);
                 nameTriple4.ResolveMissingPieces(forcedLastName);
                 return(!nameTriple4.UsedThisGame);
             }, false, null);
             NameTriple nameTriple = NameTriple.FromString(rawName);
             nameTriple.CapitalizeNick();
             nameTriple.ResolveMissingPieces(forcedLastName);
             return(nameTriple);
         }
         if (pawn.RaceProps.nameCategory != PawnNameCategory.NoName)
         {
             if (Rand.Value < 0.5f)
             {
                 NameTriple nameTriple2 = PawnBioAndNameGenerator.TryGetRandomUnusedSolidName(pawn.gender, forcedLastName);
                 if (nameTriple2 != null)
                 {
                     return(nameTriple2);
                 }
             }
             return(PawnBioAndNameGenerator.GeneratePawnName_Shuffled(pawn, forcedLastName));
         }
         Log.Error("No name making method for " + pawn);
         NameTriple nameTriple3 = NameTriple.FromString(pawn.def.label);
         nameTriple3.ResolveMissingPieces(null);
         return(nameTriple3);
     }
     else
     {
         if (style == NameStyle.Numeric)
         {
             int    num = 1;
             string text;
             while (true)
             {
                 text = pawn.KindLabel + " " + num.ToString();
                 if (!NameUseChecker.NameSingleIsUsed(text))
                 {
                     break;
                 }
                 num++;
             }
             return(new NameSingle(text, true));
         }
         throw new InvalidOperationException();
     }
 }
Пример #2
0
        /// <summary>
        /// Creates a cutebold name.
        /// </summary>
        /// <param name="nameMaker">The given name rules.</param>
        /// <param name="forcedLastName">The forced last name.</param>
        /// <returns>Returns a new cutebold name.</returns>
        private static NameTriple CuteboldNameResolver(RulePackDef nameMaker, string forcedLastName)
        {
            NameTriple name = NameTriple.FromString(NameGenerator.GenerateName(nameMaker, null, false, null, null));

            name.CapitalizeNick();
            name.ResolveMissingPieces(forcedLastName);

            return(name);
        }
        private static Name NameResolvedFrom(RulePackDef nameMaker, string forcedLastName)
        {
            NameTriple nameTriple = NameTriple.FromString(NameGenerator.GenerateName(nameMaker, delegate(string x)
            {
                NameTriple nameTriple2 = NameTriple.FromString(x);
                nameTriple2.ResolveMissingPieces(forcedLastName);
                return(!nameTriple2.UsedThisGame);
            }));

            nameTriple.CapitalizeNick();
            nameTriple.ResolveMissingPieces(forcedLastName);
            return(nameTriple);
        }
Пример #4
0
        private Pawn getTanya()
        {
            PawnGenerationRequest request = new PawnGenerationRequest(DefDatabase <PawnKindDef> .GetNamed("ra2_AlliedTanya", true), Faction.OfPlayer, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, true, 1f, false, true, true, false, false, false, false, null, null, null, null, null, Gender.Female, null, null);
            Pawn item = PawnGenerator.GeneratePawn(request);

            Pawn_StoryTracker ps   = item.story;
            HairDef           hair = DefDatabase <HairDef> .GetNamed("Curly");

            ps.childhood        = null;
            ps.adulthood        = null;
            ps.traits.allTraits = new List <Trait>();
            ps.traits.GainTrait(new Trait(DefDatabase <TraitDef> .GetNamed("ra2_MakeSoldier", true)));
            ps.traits.GainTrait(new Trait(TraitDefOf.Psychopath));
            Pawn_WorkSettings pws = item.workSettings;

            pws.DisableAll();

            NameTriple triple = NameTriple.FromString(item.kindDef.label);

            triple.ResolveMissingPieces("Adams".Translate());
            item.Name = triple;

            Pawn_SkillTracker skt = item.skills;

            foreach (SkillRecord sr in skt.skills)
            {
                sr.Level = 20;
            }

            item.inventory.DestroyAll();
            ps.bodyType  = BodyTypeDefOf.Female;
            ps.hairDef   = hair;
            ps.hairColor = new UnityEngine.Color(1, 0.8f, 0);

            //st.SkinColor = new UnityEngine.Color(0.98f,0.76f,0.71f);
            ps.melanin = 0f;


            Pawn_EquipmentTracker pe = item.equipment;

            pe.Remove(pe.Primary);
            pe.AddEquipment((ThingWithComps)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("ra2_Gun_Tanya", true)));


            //item.story = st;
            return(item);
        }
Пример #5
0
        public override void PostSpawnSetup()
        {
            base.PostSpawnSetup();
            this.psykerPowerManager = new PsykerPowerManager(this);
            ChaosFollowerPawnKindDef pdef = this.psyker.kindDef as ChaosFollowerPawnKindDef;

            if (pdef != null && pdef.RenamePawns)
            {
                string rawName = NameGenerator.GenerateName(pdef.OverridingNameRulePack, delegate(string x)
                {
                    NameTriple nameTriple4 = NameTriple.FromString(x);
                    nameTriple4.ResolveMissingPieces(null);
                    return(!nameTriple4.UsedThisGame);
                }, false);
                NameTriple nameTriple = NameTriple.FromString(rawName);
                nameTriple.CapitalizeNick();
                nameTriple.ResolveMissingPieces(null);
                psyker.Name = nameTriple;
            }
        }
        private static Pawn getTanya(IncidentParms parms)
        {
            PawnGenerationRequest request = new PawnGenerationRequest(DefDatabase <PawnKindDef> .GetNamed("ra2_AlliedTanya", true), parms.faction, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, true, 1f, false, true, true, false, false, false, false, null, null, null, null, null, Gender.Female, null, null);
            Pawn item = PawnGenerator.GeneratePawn(request);

            Pawn_StoryTracker st   = item.story;
            HairDef           hair = DefDatabase <HairDef> .GetNamed("Curly");

            Dictionary <String, Backstory> bsdb = BackstoryDatabase.allBackstories;
            Backstory child = bsdb.TryGetValue("YouthSoldier99");
            Backstory old   = bsdb.TryGetValue("VeteranSoldier2");

            st.adulthood = old;
            st.childhood = child;

            NameTriple triple = NameTriple.FromString(item.kindDef.label);

            triple.ResolveMissingPieces("Adams".Translate());
            item.Name = triple;

            Pawn_SkillTracker skt = item.skills;

            foreach (SkillRecord sr in skt.skills)
            {
                sr.Level = 20;
            }


            st.bodyType  = BodyTypeDefOf.Female;
            st.hairDef   = hair;
            st.hairColor = new UnityEngine.Color(1, 0.8f, 0);

            //st.SkinColor = new UnityEngine.Color(0.98f,0.76f,0.71f);
            st.melanin = 0f;



            //item.story = st;
            return(item);
        }
Пример #7
0
        // RimWorld.PawnBioAndNameGenerator
        public static void GeneratePawnName(Pawn pawn, NameStyle style, string forcedLastName, ref Name __result)
        {
            if (pawn != null && pawn.Faction != null && pawn.Faction.def.defName == "RE_Player")
            {
                var ruleMaker = pawn.gender ==
                                Gender.Female ?
                                DefDatabase <RulePackDef> .GetNamed("RE_STARSNamerFemale")
                    :
                                DefDatabase <RulePackDef> .GetNamed("RE_STARSNamerMale");

                string rawName = NameGenerator.GenerateName(ruleMaker, delegate(string x)
                {
                    NameTriple nameTriple4 = NameTriple.FromString(x);
                    nameTriple4.ResolveMissingPieces(forcedLastName);
                    return(!nameTriple4.UsedThisGame);
                });
                NameTriple nameTriple = NameTriple.FromString(rawName);
                nameTriple.CapitalizeNick();
                nameTriple.ResolveMissingPieces(forcedLastName);
                __result = nameTriple;
            }
        }
Пример #8
0
        public IEnumerable <NameTriple> ToNameTriples()
        {
            if (this.amount > 0 &&
                this.nickNameDatabaseChance > 0f &&
                this.nickNameDatabaseChance <= 1.0f &&
                this.firstRandomNameDefs != null &&
                this.lastRandomNameDefs != null)
            {
                IEnumerable <string> firstNames = from def in this.firstRandomNameDefs
                                                  from str in def.shuffledNames
                                                  select str;
                IEnumerable <string> lastNames = from def in this.lastRandomNameDefs
                                                 from str in def.shuffledNames
                                                 select str;
                HashSet <string> nameSet  = new HashSet <string>();
                NameBank         nameBank = PawnNameDatabaseShuffled.BankOf(PawnNameCategory.HumanStandard);
                for (int i = 0; i < this.amount; i++)
                {
                    foreach (string last in lastNames)
                    {
                        //Thread.Sleep(1);
                        string first     = firstNames.RandomElement();
                        int    threshold = 0;
                        while (!nameSet.Add($"{first}"))
                        {
                            first = firstNames.RandomElement();
                            threshold++;
                            if (threshold > 99)
                            {
                                break;
                            }
                        }
                        string nick = null;
                        if (Rand.Chance(this.nickNameDatabaseChance))
                        {
                            float  f = Rand.Value;
                            Gender gender;
                            if (this.gender == GenderPossibility.Male)
                            {
                                if (f < 0.66666666f)
                                {
                                    gender = Gender.Male;
                                }
                                else
                                {
                                    gender = Gender.None;
                                }
                            }
                            else if (this.gender == GenderPossibility.Female)
                            {
                                if (f < 0.66666666f)
                                {
                                    gender = Gender.Female;
                                }
                                else
                                {
                                    gender = Gender.None;
                                }
                            }
                            else
                            {
                                if (f < 0.33333333f)
                                {
                                    gender = Gender.Male;
                                }
                                else if (f < 0.66666666f)
                                {
                                    gender = Gender.Female;
                                }
                                else
                                {
                                    gender = Gender.None;
                                }
                            }
                            nick = nameBank.GetName(PawnNameSlot.Nick, gender);
                        }
                        NameTriple name = new NameTriple(first, nick, last);
                        name.ResolveMissingPieces();
                        yield return(name);

                        i++;
                    }
                }
            }
        }
        public static Name GeneratePawnName(Pawn pawn, NameStyle style = NameStyle.Full, string forcedLastName = null)
        {
            switch (style)
            {
            case NameStyle.Full:
            {
                if (pawn.story != null)
                {
                    if (pawn.story.childhood != null && pawn.story.childhood.NameMaker != null)
                    {
                        return(NameResolvedFrom(pawn.story.childhood.NameMaker, forcedLastName));
                    }
                    if (pawn.story.adulthood != null && pawn.story.adulthood.NameMaker != null)
                    {
                        return(NameResolvedFrom(pawn.story.adulthood.NameMaker, forcedLastName));
                    }
                }
                RulePackDef nameGenerator = pawn.RaceProps.GetNameGenerator(pawn.gender);
                if (nameGenerator != null)
                {
                    return(new NameSingle(NameGenerator.GenerateName(nameGenerator, (string x) => !new NameSingle(x).UsedThisGame)));
                }
                if (pawn.Faction != null)
                {
                    RulePackDef nameMaker = pawn.Faction.def.GetNameMaker(pawn.gender);
                    if (nameMaker != null)
                    {
                        return(NameResolvedFrom(nameMaker, forcedLastName));
                    }
                }
                if (pawn.RaceProps.nameCategory != 0)
                {
                    if (Rand.Value < 0.5f)
                    {
                        NameTriple nameTriple = TryGetRandomUnusedSolidName(pawn.gender, forcedLastName);
                        if (nameTriple != null)
                        {
                            return(nameTriple);
                        }
                    }
                    return(GeneratePawnName_Shuffled(pawn, forcedLastName));
                }
                Log.Error("No name making method for " + pawn);
                NameTriple nameTriple2 = NameTriple.FromString(pawn.def.label);
                nameTriple2.ResolveMissingPieces();
                return(nameTriple2);
            }

            case NameStyle.Numeric:
                try
                {
                    foreach (Pawn item in PawnsFinder.AllMapsWorldAndTemporary_AliveOrDead)
                    {
                        NameSingle nameSingle = item.Name as NameSingle;
                        if (nameSingle != null)
                        {
                            usedNamesTmp.Add(nameSingle.Name);
                        }
                    }
                    int    num = 1;
                    string text;
                    while (true)
                    {
                        text = $"{pawn.KindLabel} {num.ToString()}";
                        if (!usedNamesTmp.Contains(text))
                        {
                            break;
                        }
                        num++;
                    }
                    return(new NameSingle(text, numerical: true));
                }
                finally
                {
                    usedNamesTmp.Clear();
                }

            default:
                throw new InvalidOperationException();
            }
        }
Пример #10
0
        public static bool Prefix(Pawn pawn, ref Name __result, NameStyle style = 0, string forcedLastName = null)
        {
            if (style != NameStyle.Full)
            {
                return(true);
            }
            RulePackDef nameGenerator = pawn.RaceProps.GetNameGenerator(pawn.gender);

            if (nameGenerator != null)
            {
                if (nameGenerator.defName.Contains("NamerAnimalGeneric"))
                {
                    if (pawn.Faction != null && (pawn.Faction.def.defName.Contains("Tribe") || pawn.Faction.def.defName == "TribalRaiders"))
                    {
                        string        name;
                        RTPN_NameBank nameBank = RTPN_Initializer.BankOf(PawnNameCategory.HumanStandard);
                        name = nameBank.GetName(RTPN_NameSlot.Tribal, pawn.gender);
                        if (Rand.Value < 0.33f)
                        {
                            string subname1;
                            string subname2;
                            float  nickDesc = Rand.Value;
                            if (nickDesc < 0.25)
                            {
                                subname1 = nameBank.GetName(RTPN_NameSlot.Desc, Gender.Female);
                            }
                            else
                            {
                                subname1 = nameBank.GetName(RTPN_NameSlot.Desc, Gender.Male);
                            }
                            float nickObject = Rand.Value;
                            if (nickObject < 0.33)
                            {
                                subname2 = nameBank.GetName(RTPN_NameSlot.Object, Gender.Male);
                            }
                            else if (nickObject < 0.67)
                            {
                                subname2 = nameBank.GetName(RTPN_NameSlot.Object, Gender.Female);
                            }
                            else
                            {
                                subname2 = nameBank.GetName(RTPN_NameSlot.Object, Gender.None);
                            }
                            if (Rand.Value < 0.1)
                            {
                                name = subname2;
                            }
                            else
                            {
                                name = string.Concat(subname1, " ", subname2);
                            }
                        }
                        __result = new NameSingle(name, false);
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                return(true);
            }
            if (pawn.Faction != null && pawn.Faction.def.pawnNameMaker != null)
            {
                if (pawn.Faction.def.pawnNameMaker.defName.Contains("NamerPersonTribal"))
                {
                    string        name1;
                    string        name2;
                    string        name3;
                    RTPN_NameBank nameBank = RTPN_Initializer.BankOf(PawnNameCategory.HumanStandard);
                    name3 = nameBank.GetName(RTPN_NameSlot.Tribal, pawn.gender);
                    name1 = nameBank.GetName(RTPN_NameSlot.Tribal, pawn.gender);
                    int num = 0;
                    do
                    {
                        num++;
                        if (Rand.Value >= 0.33f)
                        {
                            name2 = (Rand.Value >= 0.67f ? name3 : name1);
                        }
                        else
                        {
                            string subname1;
                            string subname2;
                            float  nickDesc = Rand.Value;
                            if (nickDesc < 0.25)
                            {
                                subname1 = nameBank.GetName(RTPN_NameSlot.Desc, Gender.Female);
                            }
                            else
                            {
                                subname1 = nameBank.GetName(RTPN_NameSlot.Desc, Gender.Male);
                            }
                            float nickObject = Rand.Value;
                            if (nickObject < 0.33)
                            {
                                subname2 = nameBank.GetName(RTPN_NameSlot.Object, Gender.Male);
                            }
                            else if (nickObject < 0.67)
                            {
                                subname2 = nameBank.GetName(RTPN_NameSlot.Object, Gender.Female);
                            }
                            else
                            {
                                subname2 = nameBank.GetName(RTPN_NameSlot.Object, Gender.None);
                            }
                            if (Rand.Value < 0.1)
                            {
                                name2 = subname2;
                            }
                            else
                            {
                                name2 = string.Concat(subname1, " ", subname2);
                            }
                        }
                    }while (num < 50 && NameUseChecker.AllPawnsNamesEverUsed.Any <Name>((Name x) => {
                        NameTriple nameTriple = x as NameTriple;
                        return(nameTriple == null ? false : nameTriple.Nick == name2);
                    }));
                    name1 = name1 + " '" + name2 + "'";
                    NameTriple fullName = NameTriple.FromString(name1 + " " + name3);
                    fullName.CapitalizeNick();
                    fullName.ResolveMissingPieces(null);
                    __result = fullName;
                    return(false);
                }
            }
            return(true);
        }