private Pawn GeneratePawn(Slate slate, Faction faction = null)
        {
            PawnKindDef result = mustBeOfKind.GetValue(slate);

            if (faction == null && !mustHaveNoFaction.GetValue(slate))
            {
                if (!TryFindFactionForPawnGeneration(slate, out faction))
                {
                    Log.Error("QuestNode_GetPawn tried generating pawn but couldn't find a proper faction for new pawn.");
                }
                else if (result == null)
                {
                    result = faction.RandomPawnKind();
                }
            }
            RoyalTitleDef fixedTitle;

            if (mustHaveRoyalTitleInCurrentFaction.GetValue(slate))
            {
                if (!seniorityRange.TryGetValue(slate, out FloatRange senRange))
                {
                    senRange = FloatRange.Zero;
                }
                IEnumerable <RoyalTitleDef> source = DefDatabase <RoyalTitleDef> .AllDefsListForReading.Where((RoyalTitleDef t) => faction.def.RoyalTitlesAllInSeniorityOrderForReading.Contains(t) && (senRange.max <= 0f || senRange.IncludesEpsilon(t.seniority)));

                if (requireResearchedBedroomFurnitureIfRoyal.GetValue(slate) && source.Any((RoyalTitleDef x) => PlayerHasResearchedBedroomRequirementsFor(x)))
                {
                    source = source.Where((RoyalTitleDef x) => PlayerHasResearchedBedroomRequirementsFor(x));
                }
                fixedTitle = source.RandomElementByWeight((RoyalTitleDef t) => t.commonality);
                if (mustBeOfKind.GetValue(slate) == null && !DefDatabase <PawnKindDef> .AllDefsListForReading.Where((PawnKindDef k) => k.titleRequired != null && k.titleRequired == fixedTitle).TryRandomElement(out result))
                {
                    DefDatabase <PawnKindDef> .AllDefsListForReading.Where((PawnKindDef k) => k.titleSelectOne != null && k.titleSelectOne.Contains(fixedTitle)).TryRandomElement(out result);
                }
            }
            else
            {
                fixedTitle = null;
            }
            if (result == null)
            {
                result = DefDatabase <PawnKindDef> .AllDefsListForReading.Where((PawnKindDef kind) => kind.race.race.Humanlike).RandomElement();
            }
            Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(result, faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: true, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, allowAddictions: true, inhabitant: false, certainlyBeenInCryptosleep: false, forceRedressWorldPawnIfFormerColonist: false, worldPawnFactionDoesntMatter: false, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null, fixedTitle));

            Find.WorldPawns.PassToWorld(pawn);
            if (pawn.royalty != null && pawn.royalty.AllTitlesForReading.Any())
            {
                QuestPart_Hyperlinks questPart_Hyperlinks = new QuestPart_Hyperlinks();
                questPart_Hyperlinks.pawns.Add(pawn);
                QuestGen.quest.AddPart(questPart_Hyperlinks);
            }
            return(pawn);
        }
Exemple #2
0
        private bool TryFindMap(Slate slate, out Map map)
        {
            if (!preferMapWithMinFreeColonists.TryGetValue(slate, out var minCount))
            {
                minCount = 1;
            }
            IEnumerable <Map> source = Find.Maps.Where((Map x) => x.IsPlayerHome && IsAcceptableMap(x, slate));

            if (!source.Where((Map x) => x.mapPawns.FreeColonists.Count >= minCount).TryRandomElement(out map))
            {
                return(source.Where((Map x) => x.mapPawns.FreeColonists.Any()).TryRandomElement(out map));
            }
            return(true);
        }
        private void SetVars(Slate slate)
        {
            float x   = slate.Get("points", 0f);
            float num = pointsCurve.GetValue(slate).Evaluate(x);

            if (roundRandom.GetValue(slate))
            {
                num = GenMath.RoundRandom(num);
            }
            if (challengeRating.TryGetValue(slate, out int value))
            {
                switch (value)
                {
                case 1:
                    num = Mathf.Min(num, maxCountOneStar.GetValue(slate));
                    break;

                case 2:
                    num = Mathf.Min(num, maxCountTwoStar.GetValue(slate));
                    break;

                default:
                    num = Mathf.Min(num, maxCountThreeStar.GetValue(slate));
                    break;
                }
            }
            SimpleCurve value2 = chancesCurve.GetValue(slate);
            int         num2   = value2.Points.Count - 1;

            while (num2 >= 0)
            {
                if (value2.Points[num2].x > num)
                {
                    value2.Points[num2] = new CurvePoint(0f, 0f);
                    num2--;
                    continue;
                }
                value2.Points.Insert(num2 + 1, new CurvePoint(num + 1f, 0f));
                break;
            }
            float num3 = Rand.ByCurve(value2);

            if (roundRandom.GetValue(slate))
            {
                num3 = GenMath.RoundRandom(num3);
            }
            slate.Set(storeAs.GetValue(slate), Mathf.Clamp(num3, 1f, num));
        }