private static NameTriple GeneratePawnName_Shuffled(Pawn pawn, string forcedLastName = null)
        {
            PawnNameCategory pawnNameCategory = pawn.RaceProps.nameCategory;

            if (pawnNameCategory == PawnNameCategory.NoName)
            {
                Log.Message("Can't create a name of type NoName. Defaulting to HumanStandard.");
                pawnNameCategory = PawnNameCategory.HumanStandard;
            }
            NameBank nameBank = PawnNameDatabaseShuffled.BankOf(pawnNameCategory);
            string   name     = nameBank.GetName(PawnNameSlot.First, pawn.gender);
            string   text;

            if (forcedLastName != null)
            {
                text = forcedLastName;
            }
            else
            {
                text = nameBank.GetName(PawnNameSlot.Last, Gender.None);
            }
            int    num = 0;
            string nick;

            do
            {
                num++;
                if (Rand.Value < 0.15f)
                {
                    Gender gender = pawn.gender;
                    if (Rand.Value < 0.5f)
                    {
                        gender = Gender.None;
                    }
                    nick = nameBank.GetName(PawnNameSlot.Nick, gender);
                }
                else if (Rand.Value < 0.5f)
                {
                    nick = name;
                }
                else
                {
                    nick = text;
                }
            }while (num < 50 && NameUseChecker.AllPawnsNamesEverUsed.Any(delegate(Name x)
            {
                NameTriple nameTriple = x as NameTriple;
                return(nameTriple != null && nameTriple.Nick == nick);
            }));
            return(new NameTriple(name, nick, text));
        }
Beispiel #2
0
        static PawnNameDatabaseShuffled()
        {
            PawnNameDatabaseShuffled.banks = new Dictionary <PawnNameCategory, NameBank>();
            foreach (PawnNameCategory pawnNameCategory in Enum.GetValues(typeof(PawnNameCategory)))
            {
                if (pawnNameCategory != PawnNameCategory.NoName)
                {
                    PawnNameDatabaseShuffled.banks.Add(pawnNameCategory, new NameBank(pawnNameCategory));
                }
            }
            NameBank nameBank = PawnNameDatabaseShuffled.BankOf(PawnNameCategory.HumanStandard);

            nameBank.AddNamesFromFile(PawnNameSlot.First, Gender.Male, "First_Male");
            nameBank.AddNamesFromFile(PawnNameSlot.First, Gender.Female, "First_Female");
            nameBank.AddNamesFromFile(PawnNameSlot.Nick, Gender.Male, "Nick_Male");
            nameBank.AddNamesFromFile(PawnNameSlot.Nick, Gender.Female, "Nick_Female");
            nameBank.AddNamesFromFile(PawnNameSlot.Nick, Gender.None, "Nick_Unisex");
            nameBank.AddNamesFromFile(PawnNameSlot.Last, Gender.None, "Last");
            foreach (NameBank current in PawnNameDatabaseShuffled.banks.Values)
            {
                current.ErrorCheck();
            }
        }
        static PawnNameDatabaseShuffled()
        {
            IEnumerator enumerator = Enum.GetValues(typeof(PawnNameCategory)).GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object           obj = enumerator.Current;
                    PawnNameCategory pawnNameCategory = (PawnNameCategory)obj;
                    if (pawnNameCategory != PawnNameCategory.NoName)
                    {
                        PawnNameDatabaseShuffled.banks.Add(pawnNameCategory, new NameBank(pawnNameCategory));
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            NameBank nameBank = PawnNameDatabaseShuffled.BankOf(PawnNameCategory.HumanStandard);

            nameBank.AddNamesFromFile(PawnNameSlot.First, Gender.Male, "First_Male");
            nameBank.AddNamesFromFile(PawnNameSlot.First, Gender.Female, "First_Female");
            nameBank.AddNamesFromFile(PawnNameSlot.Nick, Gender.Male, "Nick_Male");
            nameBank.AddNamesFromFile(PawnNameSlot.Nick, Gender.Female, "Nick_Female");
            nameBank.AddNamesFromFile(PawnNameSlot.Nick, Gender.None, "Nick_Unisex");
            nameBank.AddNamesFromFile(PawnNameSlot.Last, Gender.None, "Last");
            foreach (NameBank nameBank2 in PawnNameDatabaseShuffled.banks.Values)
            {
                nameBank2.ErrorCheck();
            }
        }
Beispiel #4
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++;
                    }
                }
            }
        }