private static List <BackstoryCategoryFilter> GetBackstoryCategoryFiltersFor(Pawn pawn, FactionDef faction) { if (!pawn.kindDef.backstoryFiltersOverride.NullOrEmpty()) { return(pawn.kindDef.backstoryFiltersOverride); } List <BackstoryCategoryFilter> list = new List <BackstoryCategoryFilter>(); if (pawn.kindDef.backstoryFilters != null) { list.AddRange(pawn.kindDef.backstoryFilters); } if (faction != null && !faction.backstoryFilters.NullOrEmpty()) { for (int i = 0; i < faction.backstoryFilters.Count; i++) { BackstoryCategoryFilter item = faction.backstoryFilters[i]; if (!list.Contains(item)) { list.Add(item); } } } if (!list.NullOrEmpty()) { return(list); } Log.ErrorOnce(string.Concat("PawnKind ", pawn.kindDef, " generating with factionDef ", faction, ": no backstoryCategories in either."), 1871521); return(new List <BackstoryCategoryFilter> { FallbackCategoryGroup }); }
private static bool TryGetRandomUnusedSolidBioFor(List <BackstoryCategoryFilter> backstoryCategories, PawnKindDef kind, Gender gender, string requiredLastName, out PawnBio result) { BackstoryCategoryFilter categoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality); if (categoryFilter == null) { categoryFilter = FallbackCategoryGroup; } if (Rand.Value < 0.5f) { tmpNames.Clear(); tmpNames.AddRange(Prefs.PreferredNames); tmpNames.Shuffle(); foreach (string tmpName in tmpNames) { foreach (PawnBio allBio in SolidBioDatabase.allBios) { if (tmpName == allBio.name.ToString() && IsBioUseable(allBio, categoryFilter, kind, gender, requiredLastName)) { result = allBio; return(true); } } } } return((from bio in SolidBioDatabase.allBios.TakeRandom(20) where IsBioUseable(bio, categoryFilter, kind, gender, requiredLastName) select bio).TryRandomElementByWeight(BioSelectionWeight, out result)); }
public static List <Backstory> ShuffleableBackstoryList(BackstorySlot slot, BackstoryCategoryFilter group) { Pair <BackstorySlot, BackstoryCategoryFilter> key = new Pair <BackstorySlot, BackstoryCategoryFilter>(slot, group); if (!shuffleableBackstoryList.ContainsKey(key)) { shuffleableBackstoryList[key] = allBackstories.Values.Where((Backstory bs) => bs.shuffleable && bs.slot == slot && group.Matches(bs)).ToList(); } return(shuffleableBackstoryList[key]); }
private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, Backstory backstoryOtherSlot, List <BackstoryCategoryFilter> backstoryCategories, FactionDef factionType) { BackstoryCategoryFilter backstoryCategoryFilter = backstoryCategories.RandomElementByWeight((BackstoryCategoryFilter c) => c.commonality); if (backstoryCategoryFilter == null) { backstoryCategoryFilter = FallbackCategoryGroup; } if (!(from bs in BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategoryFilter).TakeRandom(20) where (slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)) ? true : false select bs).TryRandomElementByWeight(BackstorySelectionWeight, out backstory)) { Log.Error(string.Concat("No shuffled ", slot, " found for ", pawn.ToStringSafe(), " of ", factionType.ToStringSafe(), ". Choosing random.")); backstory = BackstoryDatabase.allBackstories.Where((KeyValuePair <string, Backstory> kvp) => kvp.Value.slot == slot).RandomElement().Value; } }
private static bool IsBioUseable(PawnBio bio, BackstoryCategoryFilter categoryFilter, PawnKindDef kind, Gender gender, string requiredLastName) { if (bio.gender != GenderPossibility.Either) { if (gender == Gender.Male && bio.gender != 0) { return(false); } if (gender == Gender.Female && bio.gender != GenderPossibility.Female) { return(false); } } if (!requiredLastName.NullOrEmpty() && bio.name.Last != requiredLastName) { return(false); } if (kind.factionLeader && !bio.pirateKing) { return(false); } if (!categoryFilter.Matches(bio)) { return(false); } if (bio.name.UsedThisGame) { return(false); } if (kind.requiredWorkTags != 0) { if (bio.childhood != null && (bio.childhood.workDisables & kind.requiredWorkTags) != 0) { return(false); } if (bio.adulthood != null && (bio.adulthood.workDisables & kind.requiredWorkTags) != 0) { return(false); } } return(true); }