Beispiel #1
0
        public static Faction NewGeneratedFaction(FactionDef facDef)
        {
            Faction faction = new Faction();

            faction.def               = facDef;
            faction.loadID            = Find.UniqueIDsManager.GetNextFactionID();
            faction.colorFromSpectrum = FactionGenerator.NewRandomColorFromSpectrum(faction);
            if (!facDef.isPlayer)
            {
                if (facDef.fixedName != null)
                {
                    faction.Name = facDef.fixedName;
                }
                else
                {
                    faction.Name = NameGenerator.GenerateName(facDef.factionNameMaker, from fac in Find.FactionManager.AllFactionsVisible
                                                              select fac.Name, false, null);
                }
            }
            faction.centralMelanin = Rand.Value;
            foreach (Faction other in Find.FactionManager.AllFactionsListForReading)
            {
                faction.TryMakeInitialRelationsWith(other);
            }
            if (!facDef.hidden && !facDef.isPlayer)
            {
                Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                settlement.SetFaction(faction);
                settlement.Tile = TileFinder.RandomSettlementTileFor(faction, false, null);
                settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, null);
                Find.WorldObjects.Add(settlement);
            }
            faction.GenerateNewLeader();
            return(faction);
        }
Beispiel #2
0
        private static bool TryGiveSolidBioTo(Pawn pawn, string requiredLastName, FactionDef factionType)
        {
            PawnBio pawnBio = PawnBioAndNameGenerator.TryGetRandomUnusedSolidBioFor(factionType.backstoryCategory, pawn.kindDef, pawn.gender, requiredLastName);
            bool    result;

            if (pawnBio == null)
            {
                result = false;
            }
            else
            {
                if (pawnBio.name.First == "Tynan" && pawnBio.name.Last == "Sylvester")
                {
                    if (Rand.Value < 0.5f)
                    {
                        pawnBio = PawnBioAndNameGenerator.TryGetRandomUnusedSolidBioFor(factionType.backstoryCategory, pawn.kindDef, pawn.gender, requiredLastName);
                    }
                }
                if (pawnBio == null)
                {
                    result = false;
                }
                else
                {
                    pawn.Name            = pawnBio.name;
                    pawn.story.childhood = pawnBio.childhood;
                    if (pawn.ageTracker.AgeBiologicalYearsFloat >= 20f)
                    {
                        pawn.story.adulthood = pawnBio.adulthood;
                    }
                    result = true;
                }
            }
            return(result);
        }
Beispiel #3
0
        public static HairDef RandomHairDefFor(Pawn pawn, FactionDef factionType)
        {
            IEnumerable <HairDef> source = from hair in DefDatabase <HairDef> .AllDefs
                                           where hair.hairTags.SharesElementWith(factionType.hairTags)
                                           select hair;

            return(source.RandomElementByWeight((HairDef hair) => PawnHairChooser.HairChoiceLikelihoodFor(hair, pawn)));
        }
 private static void GiveShuffledBioTo(Pawn pawn, FactionDef factionType, string requiredLastName)
 {
     pawn.Name = PawnBioAndNameGenerator.GeneratePawnName(pawn, NameStyle.Full, requiredLastName);
     PawnBioAndNameGenerator.FillBackstorySlotShuffled(pawn, BackstorySlot.Childhood, ref pawn.story.childhood, factionType);
     if (pawn.ageTracker.AgeBiologicalYearsFloat >= 20f)
     {
         PawnBioAndNameGenerator.FillBackstorySlotShuffled(pawn, BackstorySlot.Adulthood, ref pawn.story.adulthood, factionType);
     }
 }
Beispiel #5
0
 private static void GiveShuffledBioTo(Pawn pawn, FactionDef factionType, string requiredLastName, List <string> backstoryCategories)
 {
     pawn.Name = GeneratePawnName(pawn, NameStyle.Full, requiredLastName);
     FillBackstorySlotShuffled(pawn, BackstorySlot.Childhood, ref pawn.story.childhood, backstoryCategories, factionType);
     if (pawn.ageTracker.AgeBiologicalYearsFloat >= 20f)
     {
         FillBackstorySlotShuffled(pawn, BackstorySlot.Adulthood, ref pawn.story.adulthood, backstoryCategories, factionType);
     }
 }
Beispiel #6
0
        public static Faction NewGeneratedFactionWithRelations(FactionDef facDef, List <FactionRelation> relations)
        {
            Faction faction = NewGeneratedFaction(facDef);

            for (int i = 0; i < relations.Count; i++)
            {
                faction.SetRelation(relations[i]);
            }
            return(faction);
        }
Beispiel #7
0
 public Faction FirstFactionOfDef(FactionDef facDef)
 {
     for (int i = 0; i < allFactions.Count; i++)
     {
         if (allFactions[i].def == facDef)
         {
             return(allFactions[i]);
         }
     }
     return(null);
 }
Beispiel #8
0
        public static HairDef RandomHairDefFor(Pawn pawn, FactionDef factionType)
        {
            IEnumerable <string> enumerable  = HairTagsFromBackstory(pawn);
            IEnumerable <string> enumerable2 = HairTagsFromPawnKind(pawn);
            IEnumerable <string> chosen      = (enumerable2.Count() > 0) ? enumerable2 : enumerable;

            if (chosen.Count() == 0)
            {
                chosen = factionType.hairTags;
            }
            return(DefDatabase <HairDef> .AllDefs.Where((HairDef hair) => hair.hairTags.SharesElementWith(chosen)).RandomElementByWeight((HairDef hair) => HairChoiceLikelihoodFor(hair, pawn)));
        }
Beispiel #9
0
        public int MaxAllowedPsylinkLevel(FactionDef faction)
        {
            int result = 0;

            for (int i = 0; i < faction.royalImplantRules.Count; i++)
            {
                RoyalImplantRule royalImplantRule = faction.royalImplantRules[i];
                if (royalImplantRule.implantHediff == HediffDefOf.PsychicAmplifier && royalImplantRule.minTitle.Awardable && royalImplantRule.minTitle.seniority <= seniority)
                {
                    result = royalImplantRule.maxLevel;
                }
            }
            return(result);
        }
 public static Faction DefaultFactionFrom(FactionDef ft)
 {
     if (ft == null)
     {
         return(null);
     }
     if (ft.isPlayer)
     {
         return(Faction.OfPlayer);
     }
     if (Find.FactionManager.AllFactions.Where((Faction fac) => fac.def == ft).TryRandomElement(out var result))
     {
         return(result);
     }
     return(null);
 }
Beispiel #11
0
 public override void DoEditInterface(Listing_ScenEdit listing)
 {
     if (Widgets.ButtonText(listing.GetScenPartRect(this, ScenPart.RowHeight), factionDef.LabelCap))
     {
         List <FloatMenuOption> list = new List <FloatMenuOption>();
         foreach (FactionDef item in DefDatabase <FactionDef> .AllDefs.Where((FactionDef d) => d.isPlayer))
         {
             FactionDef localFd = item;
             list.Add(new FloatMenuOption(localFd.LabelCap, delegate
             {
                 factionDef = localFd;
             }));
         }
         Find.WindowStack.Add(new FloatMenu(list));
     }
 }
Beispiel #12
0
        public static Faction NewGeneratedFaction(FactionDef facDef)
        {
            Faction faction = new Faction();

            faction.def               = facDef;
            faction.loadID            = Find.UniqueIDsManager.GetNextFactionID();
            faction.colorFromSpectrum = NewRandomColorFromSpectrum(faction);
            if (!facDef.isPlayer)
            {
                if (facDef.fixedName != null)
                {
                    faction.Name = facDef.fixedName;
                }
                else
                {
                    string text = "";
                    for (int i = 0; i < 10; i++)
                    {
                        string text2 = NameGenerator.GenerateName(facDef.factionNameMaker, Find.FactionManager.AllFactionsVisible.Select((Faction fac) => fac.Name));
                        if (text2.Length <= 20)
                        {
                            text = text2;
                        }
                    }
                    if (text.NullOrEmpty())
                    {
                        text = NameGenerator.GenerateName(facDef.factionNameMaker, Find.FactionManager.AllFactionsVisible.Select((Faction fac) => fac.Name));
                    }
                    faction.Name = text;
                }
            }
            faction.centralMelanin = Rand.Value;
            foreach (Faction item in Find.FactionManager.AllFactionsListForReading)
            {
                faction.TryMakeInitialRelationsWith(item);
            }
            if (!faction.Hidden && !facDef.isPlayer)
            {
                Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                settlement.SetFaction(faction);
                settlement.Tile = TileFinder.RandomSettlementTileFor(faction);
                settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement);
                Find.WorldObjects.Add(settlement);
            }
            faction.TryGenerateNewLeader();
            return(faction);
        }
Beispiel #13
0
 public static Faction DefaultFactionFrom(FactionDef ft)
 {
     if (ft == null)
     {
         return(null);
     }
     if (ft.isPlayer)
     {
         return(Faction.OfPlayer);
     }
     if ((from fac in Find.FactionManager.AllFactions
          where fac.def == ft
          select fac).TryRandomElement(out Faction result))
     {
         return(result);
     }
     return(null);
 }
Beispiel #14
0
        public override void DoEditInterface(Listing_ScenEdit listing)
        {
            Rect scenPartRect = listing.GetScenPartRect(this, ScenPart.RowHeight);

            if (Widgets.ButtonText(scenPartRect, this.factionDef.LabelCap, true, false, true))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (FactionDef current in from d in DefDatabase <FactionDef> .AllDefs
                         where d.isPlayer
                         select d)
                {
                    FactionDef localFd = current;
                    list.Add(new FloatMenuOption(localFd.LabelCap, delegate
                    {
                        this.factionDef = localFd;
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list));
            }
        }
Beispiel #15
0
        private static List <string> GetBackstoryCategoriesFor(Pawn pawn, FactionDef faction)
        {
            List <string> list = new List <string>();

            if (pawn.kindDef.backstoryCategories != null)
            {
                list.AddRange(pawn.kindDef.backstoryCategories);
            }
            if (faction != null && faction.backstoryCategories != null)
            {
                for (int i = 0; i < faction.backstoryCategories.Count; i++)
                {
                    string item = faction.backstoryCategories[i];
                    if (!list.Contains(item))
                    {
                        list.Add(item);
                    }
                }
            }
            return(list);
        }
Beispiel #16
0
 public static void EnsureRequiredEnemies(Faction player)
 {
     using (IEnumerator <FactionDef> enumerator = DefDatabase <FactionDef> .AllDefs.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             FactionDef facDef = enumerator.Current;
             if (facDef.mustStartOneEnemy && Find.World.factionManager.AllFactions.Any((Faction f) => f.def == facDef) && !Find.World.factionManager.AllFactions.Any((Faction f) => f.def == facDef && f.HostileTo(player)))
             {
                 Faction faction = (from f in Find.World.factionManager.AllFactions
                                    where f.def == facDef
                                    select f).RandomElement <Faction>();
                 int num            = faction.GoodwillWith(player);
                 int randomInRange  = DiplomacyTuning.ForcedStartingEnemyGoodwillRange.RandomInRange;
                 int goodwillChange = randomInRange - num;
                 faction.TryAffectGoodwillWith(player, goodwillChange, false, false, null, null);
                 faction.TrySetRelationKind(player, FactionRelationKind.Hostile, false, null, null);
             }
         }
     }
 }
        public static void GenerateFactionsIntoWorld()
        {
            int i = 0;

            foreach (FactionDef current in DefDatabase <FactionDef> .AllDefs)
            {
                for (int j = 0; j < current.requiredCountAtGameStart; j++)
                {
                    Faction faction = FactionGenerator.NewGeneratedFaction(current);
                    Find.FactionManager.Add(faction);
                    if (!current.hidden)
                    {
                        i++;
                    }
                }
            }
            while (i < 5)
            {
                FactionDef facDef = (from fa in DefDatabase <FactionDef> .AllDefs
                                     where fa.canMakeRandomly && Find.FactionManager.AllFactions.Count((Faction f) => f.def == fa) < fa.maxCountAtGameStart
                                     select fa).RandomElement <FactionDef>();
                Faction faction2 = FactionGenerator.NewGeneratedFaction(facDef);
                Find.World.factionManager.Add(faction2);
                i++;
            }
            int num = GenMath.RoundRandom((float)Find.WorldGrid.TilesCount / 100000f * FactionGenerator.SettlementsPer100kTiles.RandomInRange);

            num -= Find.WorldObjects.Settlements.Count;
            for (int k = 0; k < num; k++)
            {
                Faction faction3 = (from x in Find.World.factionManager.AllFactionsListForReading
                                    where !x.def.isPlayer && !x.def.hidden
                                    select x).RandomElementByWeight((Faction x) => x.def.settlementGenerationWeight);
                Settlement settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                settlement.SetFaction(faction3);
                settlement.Tile = TileFinder.RandomSettlementTileFor(faction3, false, null);
                settlement.Name = SettlementNameGenerator.GenerateSettlementName(settlement, null);
                Find.WorldObjects.Add(settlement);
            }
        }
Beispiel #18
0
        public static void GenerateFactionsIntoWorld()
        {
            int i = 0;

            foreach (FactionDef allDef in DefDatabase <FactionDef> .AllDefs)
            {
                for (int j = 0; j < allDef.requiredCountAtGameStart; j++)
                {
                    Faction faction = FactionGenerator.NewGeneratedFaction(allDef);
                    Find.FactionManager.Add(faction);
                    if (!allDef.hidden)
                    {
                        i++;
                    }
                }
            }
            for (; i < 5; i++)
            {
                FactionDef facDef = (from fa in DefDatabase <FactionDef> .AllDefs
                                     where fa.canMakeRandomly && Find.FactionManager.AllFactions.Count((Faction f) => f.def == fa) < fa.maxCountAtGameStart
                                     select fa).RandomElement();
                Faction faction2 = FactionGenerator.NewGeneratedFaction(facDef);
                Find.World.factionManager.Add(faction2);
            }
            int num = GenMath.RoundRandom((float)((float)Find.WorldGrid.TilesCount / 100000.0 * FactionGenerator.FactionBasesPer100kTiles.RandomInRange));

            num -= Find.WorldObjects.FactionBases.Count;
            for (int k = 0; k < num; k++)
            {
                Faction faction3 = (from x in Find.World.factionManager.AllFactionsListForReading
                                    where !x.def.isPlayer && !x.def.hidden
                                    select x).RandomElementByWeight((Faction x) => x.def.baseSelectionWeight);
                FactionBase factionBase = (FactionBase)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.FactionBase);
                factionBase.SetFaction(faction3);
                factionBase.Tile = TileFinder.RandomFactionBaseTileFor(faction3, false, null);
                factionBase.Name = FactionBaseNameGenerator.GenerateFactionBaseName(factionBase);
                Find.WorldObjects.Add(factionBase);
            }
        }
Beispiel #19
0
 public override void Randomize()
 {
     this.factionDef = (from fd in DefDatabase <FactionDef> .AllDefs
                        where fd.isPlayer
                        select fd).RandomElement <FactionDef>();
 }
Beispiel #20
0
 private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, List <string> backstoryCategories, FactionDef factionType)
 {
     tmpBackstories.Clear();
     BackstoryDatabase.ShuffleableBackstoryList(slot, backstoryCategories, tmpBackstories);
     if (!tmpBackstories.TakeRandom(20).Where(delegate(Backstory bs)
     {
         if (slot == BackstorySlot.Adulthood && bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables))
         {
             return(false);
         }
         return(true);
     }).TryRandomElementByWeight(BackstorySelectionWeight, out backstory))
     {
         Log.Error("No shuffled " + slot + " found for " + pawn.ToStringSafe() + " of " + factionType.ToStringSafe() + ". Defaulting.");
         backstory = (from kvp in BackstoryDatabase.allBackstories
                      where kvp.Value.slot == slot
                      select kvp).RandomElement().Value;
     }
     tmpBackstories.Clear();
 }
Beispiel #21
0
 public static void GiveAppropriateBioAndNameTo(Pawn pawn, string requiredLastName, FactionDef factionType)
 {
     if (Rand.Value < 0.25f || pawn.kindDef.factionLeader)
     {
         bool flag = PawnBioAndNameGenerator.TryGiveSolidBioTo(pawn, requiredLastName, factionType);
         if (flag)
         {
             return;
         }
     }
     PawnBioAndNameGenerator.GiveShuffledBioTo(pawn, factionType, requiredLastName);
 }
Beispiel #22
0
        private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, FactionDef factionType)
        {
            IEnumerable <Backstory> source = from bs in BackstoryDatabase.ShuffleableBackstoryList(slot, factionType.backstoryCategory).TakeRandom(20)
                                             where slot != BackstorySlot.Adulthood || !bs.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables)
                                             select bs;

            if (PawnBioAndNameGenerator.< > f__mg$cache0 == null)
            {
                PawnBioAndNameGenerator.< > f__mg$cache0 = new Func <Backstory, float>(PawnBioAndNameGenerator.BackstorySelectionWeight);
            }
            if (!source.TryRandomElementByWeight(PawnBioAndNameGenerator.< > f__mg$cache0, out backstory))
            {
                Log.Error(string.Concat(new object[]
                {
                    "No shuffled ",
                    slot,
                    " found for ",
                    pawn.ToStringSafe <Pawn>(),
                    " of ",
                    factionType.ToStringSafe <FactionDef>(),
                    ". Defaulting."
                }), false);
                backstory = (from kvp in BackstoryDatabase.allBackstories
                             where kvp.Value.slot == slot
                             select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
            }
        }
Beispiel #23
0
 public override void Randomize()
 {
     factionDef = DefDatabase <FactionDef> .AllDefs.Where((FactionDef fd) => fd.isPlayer).RandomElement();
 }
Beispiel #24
0
        public override void PostMapGenerate(Map map)
        {
            if (Find.GameInitData == null)
            {
                return;
            }
            string str1 = Path.Combine(Path.Combine(GenFilePaths.SaveDataFolderPath, "Ships"), shipFactionName + ".rwship");
            string actualFactionName = shipFactionName;
            bool   isVersion2        = false;

            if (File.Exists(str1 + "2")) //woo 2.0
            {
                str1      += "2";
                isVersion2 = true;
            }
            Scribe.loader.InitLoading(str1);

            FactionDef     factionDef = Faction.OfPlayer.def;
            ShipDefinition ship       = null;

            ShipInteriorMod.Log("Loading base managers...");
            Scribe_Deep.Look(ref Current.Game.uniqueIDsManager, false, "uniqueIDsManager", new object[0]);
            Scribe_Deep.Look(ref Current.Game.tickManager, false, "tickManager", new object[0]);
            Scribe_Deep.Look(ref Current.Game.drugPolicyDatabase, false, "drugPolicyDatabase", new object[0]);
            Scribe_Deep.Look(ref Current.Game.outfitDatabase, false, "outfitDatabase", new object[0]);

            //spawn a temp pawn.
            Pawn tmpPawn = StartingPawnUtility.NewGeneratedStartingPawn();

            //Advancing time
            ShipInteriorMod.Log("Advancing time...");
            Current.Game.tickManager.DebugSetTicksGame(Current.Game.tickManager.TicksAbs + 3600000 * Rand.RangeInclusive(Mod.minTravelTime.Value, Mod.maxTravelTime.Value));

            if (isVersion2)
            {
                Scribe_Values.Look(ref actualFactionName, "playerFactionName");
                Scribe_Deep.Look(ref ship, "shipDefinition");
            }
            else
            {
                ship = new ShipDefinition();
                //load the data the more cludgey way.
                ship.ExposeData();
            }

            highCorner = ship.Max;
            lowCorner  = ship.Min;

            IntVec3 spot   = MapGenerator.PlayerStartSpot;
            int     width  = highCorner.x - lowCorner.x;
            int     height = highCorner.z - lowCorner.z;

            //try to position us over the start location
            spot.x -= width / 2;
            spot.z -= height / 2;

            //now offset the corners and the parts to the spot.
            int offsetx = spot.x - lowCorner.x;
            int offsety = spot.z - lowCorner.z;

            lowCorner.x  += offsetx;
            lowCorner.z  += offsety;
            highCorner.x += offsetx;
            highCorner.z += offsety;

            tmpPawn.Position = lowCorner - new IntVec3(3, 0, 3);
            tmpPawn.SpawnSetup(map, false);

            ShipInteriorMod.Log("Low Corner: " + lowCorner.x + ", " + lowCorner.y + ", " + lowCorner.z);
            ShipInteriorMod.Log("High Corner: " + highCorner.x + ", " + highCorner.y + ", " + highCorner.z);
            ShipInteriorMod.Log("Map Size: " + map.Size.x + ", " + map.Size.y + ", " + map.Size.z);

            ship.AdaptToNewGame(map, offsetx, offsety, "Landing", true, Handler);

            new MapScanner()
            .DestroyThings(-2, 2)
            .ForPoints((point, m) => m.roofGrid.SetRoof(point, null), -2, 2)
            .ForPoints((point, m) => m.terrainGrid.SetTerrain(point, TerrainDefOf.Gravel))
            .Unfog(-3, 3)
            .QueueAsLongEvent(map, lowCorner, highCorner, "Landing_Clean", true, Handler);

            ship.SpawnInNewGame(map, "Landing", true, Handler);


            LongEventHandler.QueueLongEvent(() =>
            {
                ShipInteriorMod.Log("Loading managers...");
                Scribe_Deep.Look(ref Current.Game.researchManager, false, "researchManager", new object[0]);
                Scribe_Deep.Look(ref Current.Game.taleManager, false, "taleManager", new object[0]);
                Scribe_Deep.Look(ref Current.Game.playLog, false, "playLog", new object[0]);
                Scribe.loader.FinalizeLoading();
                tmpPawn.DeSpawn();

                Faction.OfPlayer.Name = actualFactionName;

                ShipInteriorMod.Log("Done.");
            }, "Landing_Managers", true, Handler);
        }
Beispiel #25
0
 private static bool <GenerateFactionsIntoWorld> m__0(FactionDef fa)
 {
     return(fa.canMakeRandomly && Find.FactionManager.AllFactions.Count((Faction f) => f.def == fa) < fa.maxCountAtGameStart);
 }
Beispiel #26
0
 private static void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, FactionDef factionType)
 {
     if (!(from kvp in BackstoryDatabase.allBackstories.Where(delegate(KeyValuePair <string, Backstory> kvp)
     {
         if (kvp.Value.shuffleable && kvp.Value.spawnCategories.Contains(factionType.backstoryCategory) && kvp.Value.slot == slot)
         {
             if (slot == BackstorySlot.Adulthood && kvp.Value.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables))
             {
                 return(false);
             }
             return(true);
         }
         return(false);
     })
           select kvp.Value).TryRandomElementByWeight <Backstory>((Func <Backstory, float>)PawnBioAndNameGenerator.BackstorySelectionWeight, out backstory))
     {
         Log.Error("No shuffled " + slot + " found for " + pawn + " of " + factionType + ". Defaulting.");
         backstory = (from kvp in BackstoryDatabase.allBackstories
                      where kvp.Value.slot == slot
                      select kvp).RandomElement().Value;
     }
 }
        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 void FillBackstorySlotShuffled(Pawn pawn, BackstorySlot slot, ref Backstory backstory, FactionDef factionType)
 {
     if (!(from kvp in BackstoryDatabase.allBackstories
           where kvp.Value.shuffleable && kvp.Value.spawnCategories.Contains(factionType.backstoryCategory) && kvp.Value.slot == slot && (slot != BackstorySlot.Adulthood || !kvp.Value.requiredWorkTags.OverlapsWithOnAnyWorkType(pawn.story.childhood.workDisables))
           select kvp.Value).TryRandomElementByWeight(new Func <Backstory, float>(PawnBioAndNameGenerator.BackstorySelectionWeight), out backstory))
     {
         Log.Error(string.Concat(new object[]
         {
             "No shuffled ",
             slot,
             " found for ",
             pawn,
             " of ",
             factionType,
             ". Defaulting."
         }));
         backstory = (from kvp in BackstoryDatabase.allBackstories
                      where kvp.Value.slot == slot
                      select kvp).RandomElement <KeyValuePair <string, Backstory> >().Value;
     }
 }
        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;
            }
        }
Beispiel #30
0
        public static void GiveAppropriateBioAndNameTo(Pawn pawn, string requiredLastName, FactionDef factionType)
        {
            List <string> backstoryCategoriesFor = GetBackstoryCategoriesFor(pawn, factionType);

            if ((!(Rand.Value < 0.25f) && !pawn.kindDef.factionLeader) || !TryGiveSolidBioTo(pawn, requiredLastName, backstoryCategoriesFor))
            {
                GiveShuffledBioTo(pawn, factionType, requiredLastName, backstoryCategoriesFor);
            }
        }