Esempio n. 1
0
        public void IssueDecree(bool causedByMentalBreak, string mentalBreakReason = null)
        {
            if (!ModLister.RoyaltyInstalled)
            {
                Log.ErrorOnce("Decrees are a Royalty-specific game system. If you want to use this code please check ModLister.RoyaltyInstalled before calling it. See rules on the Ludeon forum for more info.", 281653);
                return;
            }
            IIncidentTarget mapHeld = pawn.MapHeld;
            IIncidentTarget target  = mapHeld ?? Find.World;

            if (PossibleDecreeQuests.TryRandomElementByWeight((QuestScriptDef x) => NaturalRandomQuestChooser.GetNaturalDecreeSelectionWeight(x, target.StoryState), out QuestScriptDef result))
            {
                lastDecreeTicks = Find.TickManager.TicksGame;
                Slate slate = new Slate();
                slate.Set("points", StorytellerUtility.DefaultThreatPointsNow(target));
                slate.Set("asker", pawn);
                Quest quest = QuestUtility.GenerateQuestAndMakeAvailable(result, slate);
                target.StoryState.RecordDecreeFired(result);
                string str  = (!causedByMentalBreak) ? ((string)"LetterLabelRandomDecree".Translate(pawn)) : ((string)("WildDecree".Translate() + ": " + pawn.LabelShortCap));
                string text = (!causedByMentalBreak) ? ((string)"LetterRandomDecree".Translate(pawn)) : ((string)"LetterDecreeMentalBreak".Translate(pawn));
                if (mentalBreakReason != null)
                {
                    text = text + "\n\n" + mentalBreakReason;
                }
                text += "\n\n" + "LetterDecree_Quest".Translate(quest.name);
                ChoiceLetter let = LetterMaker.MakeLetter(str, text, IncidentDefOf.GiveQuest_Random.letterDef, LookTargets.Invalid, null, quest);
                Find.LetterStack.ReceiveLetter(let);
            }
        }
Esempio n. 2
0
 protected override void ResolveRaidPoints(IncidentParms parms)
 {
     if (parms.points <= 0f)
     {
         parms.points = StorytellerUtility.DefaultThreatPointsNow(parms.target);
     }
 }
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            float num = 1f;

            if (Props.acceptFractionByDaysPassedCurve != null)
            {
                num *= Props.acceptFractionByDaysPassedCurve.Evaluate(GenDate.DaysPassedFloat);
            }
            if (Props.acceptPercentFactorPerThreatPointsCurve != null)
            {
                num *= Props.acceptPercentFactorPerThreatPointsCurve.Evaluate(StorytellerUtility.DefaultThreatPointsNow(target));
            }
            if (Props.acceptPercentFactorPerProgressScoreCurve != null)
            {
                num *= Props.acceptPercentFactorPerProgressScoreCurve.Evaluate(StorytellerUtility.GetProgressScore(target));
            }
            int incCount = IncidentCycleUtility.IncidentCountThisInterval(target, Find.Storyteller.storytellerComps.IndexOf(this), Props.minDaysPassed, Props.onDays, Props.offDays, Props.minSpacingDays, Props.numIncidentsRange.min, Props.numIncidentsRange.max, num);

            for (int i = 0; i < incCount; i++)
            {
                FiringIncident firingIncident = GenerateIncident(target);
                if (firingIncident != null)
                {
                    yield return(firingIncident);
                }
            }
        }
Esempio n. 4
0
 public override float PullRecord()
 {
     if (Find.AnyPlayerHomeMap == null)
     {
         return(0f);
     }
     return(StorytellerUtility.DefaultThreatPointsNow(Find.AnyPlayerHomeMap) / 10f);
 }
 // Token: 0x06000ECE RID: 3790 RVA: 0x0006ECE7 File Offset: 0x0006D0E7
 protected override void ResolveRaidPoints(IncidentParms parms)
 {
     if (parms.points <= 0f)
     {
         Log.Error("RaidEnemy is resolving raid points. They should always be set before initiating the incident.", false);
         parms.points = StorytellerUtility.DefaultThreatPointsNow(parms.target);
     }
 }
Esempio n. 6
0
 public string DebugString()
 {
     if (Time.frameCount % 60 == 0)
     {
         StringBuilder stringBuilder = new StringBuilder();
         stringBuilder.AppendLine("GLOBAL STORYTELLER STATS");
         stringBuilder.AppendLine("------------------------");
         stringBuilder.AppendLine("Storyteller: ".PadRight(40) + def.label);
         stringBuilder.AppendLine("Adaptation days: ".PadRight(40) + Find.StoryWatcher.watcherAdaptation.AdaptDays.ToString("F1"));
         stringBuilder.AppendLine("Adapt points factor: ".PadRight(40) + Find.StoryWatcher.watcherAdaptation.TotalThreatPointsFactor.ToString("F2"));
         stringBuilder.AppendLine("Time points factor: ".PadRight(40) + Find.Storyteller.def.pointsFactorFromDaysPassed.Evaluate(GenDate.DaysPassed).ToString("F2"));
         stringBuilder.AppendLine();
         stringBuilder.AppendLine("Ally incident fraction (neutral or ally): ".PadRight(40) + StorytellerUtility.AllyIncidentFraction(fullAlliesOnly: false).ToString("F2"));
         stringBuilder.AppendLine("Ally incident fraction (ally only): ".PadRight(40) + StorytellerUtility.AllyIncidentFraction(fullAlliesOnly: true).ToString("F2"));
         stringBuilder.AppendLine();
         stringBuilder.AppendLine(StorytellerUtilityPopulation.DebugReadout().TrimEndNewlines());
         IIncidentTarget incidentTarget = Find.WorldSelector.SingleSelectedObject as IIncidentTarget;
         if (incidentTarget == null)
         {
             incidentTarget = Find.CurrentMap;
         }
         if (incidentTarget != null)
         {
             Map map = incidentTarget as Map;
             stringBuilder.AppendLine();
             stringBuilder.AppendLine("STATS FOR INCIDENT TARGET: " + incidentTarget);
             stringBuilder.AppendLine("------------------------");
             stringBuilder.AppendLine("Progress score: ".PadRight(40) + StorytellerUtility.GetProgressScore(incidentTarget).ToString("F2"));
             stringBuilder.AppendLine("Base points: ".PadRight(40) + StorytellerUtility.DefaultThreatPointsNow(incidentTarget).ToString("F0"));
             stringBuilder.AppendLine("Points factor random range: ".PadRight(40) + incidentTarget.IncidentPointsRandomFactorRange);
             stringBuilder.AppendLine("Wealth: ".PadRight(40) + incidentTarget.PlayerWealthForStoryteller.ToString("F0"));
             if (map != null)
             {
                 stringBuilder.AppendLine("- Items: ".PadRight(40) + map.wealthWatcher.WealthItems.ToString("F0"));
                 stringBuilder.AppendLine("- Buildings: ".PadRight(40) + map.wealthWatcher.WealthBuildings.ToString("F0"));
                 stringBuilder.AppendLine("- Floors: ".PadRight(40) + map.wealthWatcher.WealthFloorsOnly.ToString("F0"));
                 stringBuilder.AppendLine("- Pawns: ".PadRight(40) + map.wealthWatcher.WealthPawns.ToString("F0"));
             }
             stringBuilder.AppendLine("Pawn count human: ".PadRight(40) + incidentTarget.PlayerPawnsForStoryteller.Where((Pawn p) => p.def.race.Humanlike).Count());
             stringBuilder.AppendLine("Pawn count animal: ".PadRight(40) + incidentTarget.PlayerPawnsForStoryteller.Where((Pawn p) => p.def.race.Animal).Count());
             if (map != null)
             {
                 stringBuilder.AppendLine("StoryDanger: ".PadRight(40) + map.dangerWatcher.DangerRating);
                 stringBuilder.AppendLine("FireDanger: ".PadRight(40) + map.fireWatcher.FireDanger.ToString("F2"));
                 stringBuilder.AppendLine("LastThreatBigTick days ago: ".PadRight(40) + (Find.TickManager.TicksGame - map.storyState.LastThreatBigTick).ToStringTicksToDays());
             }
         }
         stringBuilder.AppendLine();
         stringBuilder.AppendLine("LIST OF ALL INCIDENT TARGETS");
         stringBuilder.AppendLine("------------------------");
         for (int i = 0; i < AllIncidentTargets.Count; i++)
         {
             stringBuilder.AppendLine(i + ". " + AllIncidentTargets[i].ToString());
         }
         debugStringCached = stringBuilder.ToString();
     }
     return(debugStringCached);
 }
Esempio n. 7
0
        private static DiaOption RequestAICoreQuest(Map map, Faction faction, Pawn negotiator)
        {
            TaggedString taggedString = "RequestAICoreInformation".Translate(ThingDefOf.AIPersonaCore.label, 1500.ToString());

            if (faction.PlayerGoodwill < 40)
            {
                DiaOption diaOption = new DiaOption(taggedString);
                diaOption.Disable("NeedGoodwill".Translate(40.ToString("F0")));
                return(diaOption);
            }
            bool  num   = PlayerItemAccessibilityUtility.ItemStashHas(ThingDefOf.AIPersonaCore);
            Slate slate = new Slate();

            slate.Set("points", StorytellerUtility.DefaultThreatPointsNow(Find.World));
            slate.Set("asker", faction.leader);
            slate.Set("itemStashSingleThing", ThingDefOf.AIPersonaCore);
            bool flag = QuestScriptDefOf.OpportunitySite_ItemStash.CanRun(slate);

            if (num || !flag)
            {
                DiaOption diaOption2 = new DiaOption(taggedString);
                diaOption2.Disable("NoKnownAICore".Translate(1500));
                return(diaOption2);
            }
            if (AmountSendableSilver(map) < 1500)
            {
                DiaOption diaOption3 = new DiaOption(taggedString);
                diaOption3.Disable("NeedSilverLaunchable".Translate(1500));
                return(diaOption3);
            }
            return(new DiaOption(taggedString)
            {
                action = delegate
                {
                    Quest quest = QuestUtility.GenerateQuestAndMakeAvailable(QuestScriptDefOf.OpportunitySite_ItemStash, slate);
                    if (!quest.hidden)
                    {
                        QuestUtility.SendLetterQuestAvailable(quest);
                    }
                    TradeUtility.LaunchThingsOfType(ThingDefOf.Silver, 1500, map, null);
                    Current.Game.GetComponent <GameComponent_OnetimeNotification>().sendAICoreRequestReminder = false;
                },
                link = new DiaNode("RequestAICoreInformationResult".Translate(faction.leader).CapitalizeFirst())
                {
                    options =
                    {
                        OKToRoot(faction, negotiator)
                    }
                }
            });
        }
Esempio n. 8
0
        private static IncidentParms GetIncidentParms(ThreatsGeneratorParams parms, IIncidentTarget target)
        {
            IncidentParms incidentParms = new IncidentParms();

            incidentParms.target = target;
            incidentParms.points = (parms.threatPoints ?? (StorytellerUtility.DefaultThreatPointsNow(target) * parms.currentThreatPointsFactor));
            if (parms.minThreatPoints.HasValue)
            {
                incidentParms.points = Mathf.Max(incidentParms.points, parms.minThreatPoints.Value);
            }
            incidentParms.faction = parms.faction;
            incidentParms.forced  = true;
            return(incidentParms);
        }
        protected override void DoConditionAndLetter(IncidentParms parms, Map map, int duration, Gender gender, float points)
        {
            if (points < 0f)
            {
                points = StorytellerUtility.DefaultThreatPointsNow(map);
            }
            PsychicDroneLevel level = (points < 800f) ? PsychicDroneLevel.BadLow : ((!(points < 2000f)) ? PsychicDroneLevel.BadHigh : PsychicDroneLevel.BadMedium);
            GameCondition_PsychicEmanation gameCondition_PsychicEmanation = (GameCondition_PsychicEmanation)GameConditionMaker.MakeCondition(GameConditionDefOf.PsychicDrone, duration);

            gameCondition_PsychicEmanation.gender = gender;
            gameCondition_PsychicEmanation.level  = level;
            map.gameConditionManager.RegisterCondition(gameCondition_PsychicEmanation);
            SendStandardLetter(gameCondition_PsychicEmanation.LabelCap, gameCondition_PsychicEmanation.LetterText, gameCondition_PsychicEmanation.def.letterDef, parms, LookTargets.Invalid);
        }
Esempio n. 10
0
        public static IncidentParms DefaultParmsNow(IncidentCategoryDef incCat, IIncidentTarget target)
        {
            if (incCat == null)
            {
                Log.Warning("Trying to get default parms for null incident category.", false);
            }
            IncidentParms incidentParms = new IncidentParms();

            incidentParms.target = target;
            if (incCat.needsParmsPoints)
            {
                incidentParms.points = StorytellerUtility.DefaultThreatPointsNow(target);
            }
            return(incidentParms);
        }
Esempio n. 11
0
        protected override void DoConditionAndLetter(Map map, int duration, Gender gender, float points)
        {
            if (points < 0f)
            {
                points = StorytellerUtility.DefaultThreatPointsNow(map);
            }
            PsychicDroneLevel level = (points < 800f) ? PsychicDroneLevel.BadLow : ((!(points < 2000f)) ? PsychicDroneLevel.BadHigh : PsychicDroneLevel.BadMedium);
            GameCondition_PsychicEmanation gameCondition_PsychicEmanation = (GameCondition_PsychicEmanation)GameConditionMaker.MakeCondition(GameConditionDefOf.PsychicDrone, duration);

            gameCondition_PsychicEmanation.gender = gender;
            gameCondition_PsychicEmanation.level  = level;
            map.gameConditionManager.RegisterCondition(gameCondition_PsychicEmanation);
            string label = "LetterLabelPsychicDrone".Translate() + " (" + level.GetLabel() + ", " + gender.GetLabel() + ")";
            string text  = "LetterIncidentPsychicDrone".Translate(gender.ToString().Translate().ToLower(), level.GetLabel());

            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NegativeEvent);
        }
Esempio n. 12
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map = (Map)parms.target;
            IntVec3 intVec;
            bool    result;

            if (!this.TryFindEntryCell(map, out intVec))
            {
                result = false;
            }
            else
            {
                PawnKindDef thrumbo = PawnKindDefOf.Thrumbo;
                float       num     = StorytellerUtility.DefaultThreatPointsNow(map);
                int         num2    = GenMath.RoundRandom(num / thrumbo.combatPower);
                int         max     = Rand.RangeInclusive(2, 4);
                num2 = Mathf.Clamp(num2, 1, max);
                int     num3    = Rand.RangeInclusive(90000, 150000);
                IntVec3 invalid = IntVec3.Invalid;
                if (!RCellFinder.TryFindRandomCellOutsideColonyNearTheCenterOfTheMap(intVec, map, 10f, out invalid))
                {
                    invalid = IntVec3.Invalid;
                }
                Pawn pawn = null;
                for (int i = 0; i < num2; i++)
                {
                    IntVec3 loc = CellFinder.RandomClosewalkCellNear(intVec, map, 10, null);
                    pawn = PawnGenerator.GeneratePawn(thrumbo, null);
                    GenSpawn.Spawn(pawn, loc, map, Rot4.Random, WipeMode.Vanish, false);
                    pawn.mindState.exitMapAfterTick = Find.TickManager.TicksGame + num3;
                    if (invalid.IsValid)
                    {
                        pawn.mindState.forcedGotoPosition = CellFinder.RandomClosewalkCellNear(invalid, map, 10, null);
                    }
                }
                Find.LetterStack.ReceiveLetter("LetterLabelThrumboPasses".Translate(new object[]
                {
                    thrumbo.label
                }).CapitalizeFirst(), "LetterThrumboPasses".Translate(new object[]
                {
                    thrumbo.label
                }), LetterDefOf.PositiveEvent, pawn, null, null);
                result = true;
            }
            return(result);
        }
        public static IncidentParms DefaultParmsNow(IncidentCategoryDef incCat, IIncidentTarget target)
        {
            if (incCat == null)
            {
                Log.Warning("Trying to get default parms for null incident category.", false);
            }
            IncidentParms incidentParms = new IncidentParms();

            incidentParms.target = target;
            if (incCat.needsParmsPoints)
            {
                incidentParms.points = StorytellerUtility.DefaultThreatPointsNow(target);
                if (target is Map && incCat == IncidentCategoryDefOf.ThreatBig)
                {
                    switch (Find.StoryWatcher.statsRecord.numThreatBigs)
                    {
                    case 0:
                        incidentParms.points                  = 38f;
                        incidentParms.raidForceOneIncap       = true;
                        incidentParms.raidNeverFleeIndividual = true;
                        break;

                    case 1:
                        incidentParms.points *= 0.5f;
                        break;

                    case 2:
                        incidentParms.points *= 0.7f;
                        break;

                    case 3:
                        incidentParms.points *= 0.8f;
                        break;

                    case 4:
                        incidentParms.points *= 0.9f;
                        break;

                    default:
                        incidentParms.points *= 1f;
                        break;
                    }
                }
            }
            return(incidentParms);
        }
Esempio n. 14
0
 public override void Notify_QuestSignalReceived(Signal signal)
 {
     base.Notify_QuestSignalReceived(signal);
     if (signal.tag == inSignal && mapParent != null && mapParent.HasMap)
     {
         IncidentParms incidentParms = new IncidentParms();
         incidentParms.forced  = true;
         incidentParms.quest   = quest;
         incidentParms.target  = mapParent.Map;
         incidentParms.points  = (useCurrentThreatPoints ? StorytellerUtility.DefaultThreatPointsNow(mapParent.Map) : pointsRange.RandomInRange);
         incidentParms.faction = faction;
         IncidentDef incidentDef = ((faction != null && !faction.HostileTo(Faction.OfPlayer)) ? IncidentDefOf.RaidFriendly : IncidentDefOf.RaidEnemy);
         if (incidentDef.Worker.CanFireNow(incidentParms, forced: true))
         {
             incidentDef.Worker.TryExecute(incidentParms);
         }
     }
 }
Esempio n. 15
0
        protected override void DoConditionAndLetter(Map map, int duration, Gender gender, float points)
        {
            if (points < 0f)
            {
                points = StorytellerUtility.DefaultThreatPointsNow(map);
            }
            PsychicDroneLevel level;

            if (points < 800f)
            {
                level = PsychicDroneLevel.BadLow;
            }
            else if (points < 2000f)
            {
                level = PsychicDroneLevel.BadMedium;
            }
            else
            {
                level = PsychicDroneLevel.BadHigh;
            }
            GameCondition_PsychicEmanation gameCondition_PsychicEmanation = (GameCondition_PsychicEmanation)GameConditionMaker.MakeCondition(GameConditionDefOf.PsychicDrone, duration, 0);

            gameCondition_PsychicEmanation.gender = gender;
            gameCondition_PsychicEmanation.level  = level;
            map.gameConditionManager.RegisterCondition(gameCondition_PsychicEmanation);
            string label = string.Concat(new string[]
            {
                "LetterLabelPsychicDrone".Translate(),
                " (",
                level.GetLabel(),
                ", ",
                gender.GetLabel(false),
                ")"
            });
            string text = "LetterIncidentPsychicDrone".Translate(new object[]
            {
                gender.ToString().Translate().ToLower(),
                level.GetLabel()
            });

            Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NegativeEvent, null);
        }
Esempio n. 16
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if (!TryFindEntryCell(map, out IntVec3 cell))
            {
                return(false);
            }
            PawnKindDef thrumbo = PawnKindDefOf.Thrumbo;
            float       num     = StorytellerUtility.DefaultThreatPointsNow(map);
            int         value   = GenMath.RoundRandom(num / thrumbo.combatPower);
            int         max     = Rand.RangeInclusive(2, 4);

            value = Mathf.Clamp(value, 1, max);
            int     num2   = Rand.RangeInclusive(90000, 150000);
            IntVec3 result = IntVec3.Invalid;

            if (!RCellFinder.TryFindRandomCellOutsideColonyNearTheCenterOfTheMap(cell, map, 10f, out result))
            {
                result = IntVec3.Invalid;
            }
            Pawn pawn = null;

            for (int i = 0; i < value; i++)
            {
                IntVec3 loc = CellFinder.RandomClosewalkCellNear(cell, map, 10);
                pawn = PawnGenerator.GeneratePawn(thrumbo);
                GenSpawn.Spawn(pawn, loc, map, Rot4.Random);
                pawn.mindState.exitMapAfterTick = Find.TickManager.TicksGame + num2;
                if (result.IsValid)
                {
                    pawn.mindState.forcedGotoPosition = CellFinder.RandomClosewalkCellNear(result, map, 10);
                }
            }
            Find.LetterStack.ReceiveLetter("LetterLabelThrumboPasses".Translate(thrumbo.label).CapitalizeFirst(), "LetterThrumboPasses".Translate(thrumbo.label), LetterDefOf.PositiveEvent, pawn);
            return(true);
        }
 public virtual SiteCoreOrPartParams GenerateDefaultParams()
 {
     return(new SiteCoreOrPartParams
     {
         randomValue = Rand.Int,
         threatPoints = SiteCoreOrPartWorkerBase.CurrentThreatPointsToSiteThreatPoints.Evaluate(StorytellerUtility.DefaultThreatPointsNow(Find.World))
     });
 }
Esempio n. 18
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            float difficultyFactor = (!Props.applyRaidBeaconThreatMtbFactor) ? 1f : Find.Storyteller.difficulty.raidBeaconThreatCountFactor;
            float acceptFraction   = 1f;

            if (Props.acceptFractionByDaysPassedCurve != null)
            {
                acceptFraction *= Props.acceptFractionByDaysPassedCurve.Evaluate(GenDate.DaysPassedFloat);
            }
            if (Props.acceptPercentFactorPerThreatPointsCurve != null)
            {
                acceptFraction *= Props.acceptPercentFactorPerThreatPointsCurve.Evaluate(StorytellerUtility.DefaultThreatPointsNow(target));
            }
            int            incCount = IncidentCycleUtility.IncidentCountThisInterval(target, Find.Storyteller.storytellerComps.IndexOf(this), Props.minDaysPassed, Props.onDays, Props.offDays, Props.minSpacingDays, Props.numIncidentsRange.min * difficultyFactor, Props.numIncidentsRange.max * difficultyFactor, acceptFraction);
            int            i        = 0;
            FiringIncident fi;

            while (true)
            {
                if (i >= incCount)
                {
                    yield break;
                }
                fi = GenerateIncident(target);
                if (fi != null)
                {
                    break;
                }
                i++;
            }
            yield return(fi);

            /*Error: Unable to find new state assignment for yield return*/;
        }
Esempio n. 19
0
 public string DebugString()
 {
     if (Time.frameCount % 60 == 0)
     {
         StringBuilder stringBuilder = new StringBuilder();
         stringBuilder.AppendLine("Storyteller : " + this.def.label);
         stringBuilder.AppendLine("------------- Global threats data ---------------");
         stringBuilder.AppendLine("   Adaptation days: " + Find.StoryWatcher.watcherAdaptation.AdaptDays.ToString("F1"));
         stringBuilder.AppendLine("   Adapt points factor: " + Find.StoryWatcher.watcherAdaptation.TotalThreatPointsFactor.ToString("F2"));
         stringBuilder.AppendLine("   Time points factor: " + Find.Storyteller.def.pointsFactorFromDaysPassed.Evaluate((float)GenDate.DaysPassed).ToString("F2"));
         stringBuilder.AppendLine("   Num raids enemy: " + Find.StoryWatcher.statsRecord.numRaidsEnemy);
         stringBuilder.AppendLine("   Ally incident fraction (neutral or ally): " + StorytellerUtility.AllyIncidentFraction(false).ToString("F2"));
         stringBuilder.AppendLine("   Ally incident fraction (ally only): " + StorytellerUtility.AllyIncidentFraction(true).ToString("F2"));
         stringBuilder.AppendLine();
         stringBuilder.AppendLine("-------------- Global population data --------------");
         stringBuilder.AppendLine(StorytellerUtilityPopulation.DebugReadout().TrimEndNewlines());
         stringBuilder.AppendLine("   Greatest population: " + Find.StoryWatcher.statsRecord.greatestPopulation);
         stringBuilder.AppendLine("------------- All incident targets --------------");
         for (int i = 0; i < this.AllIncidentTargets.Count; i++)
         {
             stringBuilder.AppendLine("   " + this.AllIncidentTargets[i].ToString());
         }
         IIncidentTarget incidentTarget = Find.WorldSelector.SingleSelectedObject as IIncidentTarget;
         if (incidentTarget == null)
         {
             incidentTarget = Find.CurrentMap;
         }
         if (incidentTarget != null)
         {
             Map map = incidentTarget as Map;
             stringBuilder.AppendLine();
             stringBuilder.AppendLine("---------- Selected: " + incidentTarget + " --------");
             stringBuilder.AppendLine("   Wealth: " + incidentTarget.PlayerWealthForStoryteller.ToString("F0"));
             if (map != null)
             {
                 stringBuilder.AppendLine(string.Concat(new string[]
                 {
                     "   (Items: ",
                     map.wealthWatcher.WealthItems.ToString("F0"),
                     " Buildings: ",
                     map.wealthWatcher.WealthBuildings.ToString("F0"),
                     " (Floors: ",
                     map.wealthWatcher.WealthFloorsOnly.ToString("F0"),
                     ") Pawns: ",
                     map.wealthWatcher.WealthPawns.ToString("F0"),
                     ")"
                 }));
             }
             stringBuilder.AppendLine("   IncidentPointsRandomFactorRange: " + incidentTarget.IncidentPointsRandomFactorRange);
             stringBuilder.AppendLine("   Pawns-Humanlikes: " + (from p in incidentTarget.PlayerPawnsForStoryteller
                                                                 where p.def.race.Humanlike
                                                                 select p).Count <Pawn>());
             stringBuilder.AppendLine("   Pawns-Animals: " + (from p in incidentTarget.PlayerPawnsForStoryteller
                                                              where p.def.race.Animal
                                                              select p).Count <Pawn>());
             if (map != null)
             {
                 stringBuilder.AppendLine("   StoryDanger: " + map.dangerWatcher.DangerRating);
                 stringBuilder.AppendLine("   FireDanger: " + map.fireWatcher.FireDanger.ToString("F2"));
                 stringBuilder.AppendLine("   LastThreatBigTick days ago: " + (Find.TickManager.TicksGame - map.storyState.LastThreatBigTick).ToStringTicksToDays("F1"));
             }
             stringBuilder.AppendLine("   Current points (ignoring early raid factors): " + StorytellerUtility.DefaultThreatPointsNow(incidentTarget).ToString("F0"));
             stringBuilder.AppendLine("   Current points for specific IncidentMakers:");
             for (int j = 0; j < this.storytellerComps.Count; j++)
             {
                 IncidentParms incidentParms = this.storytellerComps[j].GenerateParms(IncidentCategoryDefOf.ThreatBig, incidentTarget);
                 stringBuilder.AppendLine("      " + this.storytellerComps[j].GetType().ToString().Substring(23) + ": " + incidentParms.points.ToString("F0"));
             }
         }
         this.debugStringCached = stringBuilder.ToString();
     }
     return(this.debugStringCached);
 }
Esempio n. 20
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            float difficultyFactor = (!this.Props.applyRaidBeaconThreatMtbFactor) ? 1f : Find.Storyteller.difficulty.raidBeaconThreatCountFactor;
            float acceptFraction   = 1f;

            if (this.Props.acceptFractionByDaysPassedCurve != null)
            {
                acceptFraction *= this.Props.acceptFractionByDaysPassedCurve.Evaluate(GenDate.DaysPassedFloat);
            }
            if (this.Props.acceptPercentFactorPerThreatPointsCurve != null)
            {
                acceptFraction *= this.Props.acceptPercentFactorPerThreatPointsCurve.Evaluate(StorytellerUtility.DefaultThreatPointsNow(target));
            }
            int incCount = IncidentCycleUtility.IncidentCountThisInterval(target, Find.Storyteller.storytellerComps.IndexOf(this), this.Props.minDaysPassed, this.Props.onDays, this.Props.offDays, this.Props.minSpacingDays, this.Props.numIncidentsRange.min * difficultyFactor, this.Props.numIncidentsRange.max * difficultyFactor, acceptFraction);

            for (int i = 0; i < incCount; i++)
            {
                FiringIncident fi = this.GenerateIncident(target);
                if (fi != null)
                {
                    yield return(fi);
                }
            }
        }
Esempio n. 21
0
        public virtual void DebugTablesIncidentChances()
        {
            DebugTables.MakeTablesDialog(from d in DefDatabase <IncidentDef> .AllDefs
                                         orderby d.category.defName descending, IncidentChanceFinal(d) descending
                                         select d, new TableDataGetter <IncidentDef>("defName", (IncidentDef d) => d.defName), new TableDataGetter <IncidentDef>("category", (IncidentDef d) => d.category), new TableDataGetter <IncidentDef>("can fire", (IncidentDef d) => CanFireLocal(d).ToStringCheckBlank()), new TableDataGetter <IncidentDef>("base\nchance", (IncidentDef d) => d.baseChance.ToString("F2")), new TableDataGetter <IncidentDef>("base\nchance\nwith\nRoyalty", (IncidentDef d) => (!(d.baseChanceWithRoyalty >= 0f)) ? "-" : d.baseChanceWithRoyalty.ToString("F2")), new TableDataGetter <IncidentDef>("base\nchance\nthis\ngame", (IncidentDef d) => d.Worker.BaseChanceThisGame.ToString("F2")), new TableDataGetter <IncidentDef>("final\nchance", (IncidentDef d) => IncidentChanceFinal(d).ToString("F2")), new TableDataGetter <IncidentDef>("final\nchance\npossible", (IncidentDef d) => (!CanFireLocal(d)) ? "-" : IncidentChanceFinal(d).ToString("F2")), new TableDataGetter <IncidentDef>("Factor from:\ncurrent pop", (IncidentDef d) => IncidentChanceFactor_CurrentPopulation(d).ToString()), new TableDataGetter <IncidentDef>("Factor from:\npop intent", (IncidentDef d) => IncidentChanceFactor_PopulationIntent(d).ToString()), new TableDataGetter <IncidentDef>("default target", (IncidentDef d) => (GetDefaultTarget(d) == null) ? "-" : GetDefaultTarget(d).ToString()), new TableDataGetter <IncidentDef>("current\npop", (IncidentDef d) => PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_Colonists.Count().ToString()), new TableDataGetter <IncidentDef>("pop\nintent", (IncidentDef d) => StorytellerUtilityPopulation.PopulationIntent.ToString("F2")), new TableDataGetter <IncidentDef>("cur\npoints", (IncidentDef d) => (GetDefaultTarget(d) == null) ? "-" : StorytellerUtility.DefaultThreatPointsNow(GetDefaultTarget(d)).ToString("F0")));
            bool CanFireLocal(IncidentDef d)
            {
                IIncidentTarget incidentTarget = GetDefaultTarget(d);

                if (incidentTarget == null)
                {
                    return(false);
                }
                IncidentParms parms = StorytellerUtility.DefaultParmsNow(d.category, incidentTarget);

                return(d.Worker.CanFireNow(parms));
            }

            IIncidentTarget GetDefaultTarget(IncidentDef d)
            {
                if (d.TargetAllowed(Find.CurrentMap))
                {
                    return(Find.CurrentMap);
                }
                if (d.TargetAllowed(Find.World))
                {
                    return(Find.World);
                }
                return(null);
            }
        }
Esempio n. 22
0
 public string DebugString()
 {
     if (Time.frameCount % 60 == 0)
     {
         StringBuilder stringBuilder = new StringBuilder();
         stringBuilder.AppendLine("Storyteller : " + this.def.label);
         stringBuilder.AppendLine("------------- Global threats data ---------------");
         stringBuilder.AppendLine("   NumRaidsEnemy: " + Find.StoryWatcher.statsRecord.numRaidsEnemy);
         stringBuilder.AppendLine("   TotalThreatPointsFactor: " + Find.StoryWatcher.watcherRampUp.TotalThreatPointsFactor.ToString("F5"));
         stringBuilder.AppendLine("      ShortTermFactor: " + Find.StoryWatcher.watcherRampUp.ShortTermFactor.ToString("F5"));
         stringBuilder.AppendLine("      LongTermFactor: " + Find.StoryWatcher.watcherRampUp.LongTermFactor.ToString("F5"));
         stringBuilder.AppendLine("   AllyAssistanceMTBMultiplier (ally): " + StorytellerUtility.AllyIncidentMTBMultiplier(false).ToString());
         stringBuilder.AppendLine("   AllyAssistanceMTBMultiplier (non-hostile): " + StorytellerUtility.AllyIncidentMTBMultiplier(true).ToString());
         stringBuilder.AppendLine();
         stringBuilder.AppendLine("-------------- Global population data --------------");
         stringBuilder.AppendLine(this.intenderPopulation.DebugReadout);
         stringBuilder.AppendLine("------------- All incident targets --------------");
         for (int i = 0; i < this.AllIncidentTargets.Count; i++)
         {
             stringBuilder.AppendLine("   " + this.AllIncidentTargets[i].ToString());
         }
         IIncidentTarget incidentTarget = Find.WorldSelector.SingleSelectedObject as IIncidentTarget;
         if (incidentTarget == null)
         {
             incidentTarget = Find.CurrentMap;
         }
         if (incidentTarget != null)
         {
             stringBuilder.AppendLine();
             stringBuilder.AppendLine("---------- Selected: " + incidentTarget + " --------");
             stringBuilder.AppendLine("   Wealth: " + incidentTarget.PlayerWealthForStoryteller.ToString("F0"));
             stringBuilder.AppendLine("   IncidentPointsRandomFactorRange: " + incidentTarget.IncidentPointsRandomFactorRange);
             stringBuilder.AppendLine("   Pawns-Humanlikes: " + (from p in incidentTarget.PlayerPawnsForStoryteller
                                                                 where p.def.race.Humanlike
                                                                 select p).Count <Pawn>());
             stringBuilder.AppendLine("   Pawns-Animals: " + (from p in incidentTarget.PlayerPawnsForStoryteller
                                                              where p.def.race.Animal
                                                              select p).Count <Pawn>());
             Map map = incidentTarget as Map;
             if (map != null)
             {
                 stringBuilder.AppendLine("   StoryDanger: " + map.dangerWatcher.DangerRating);
                 stringBuilder.AppendLine("   FireDanger: " + map.fireWatcher.FireDanger.ToString("F2"));
                 stringBuilder.AppendLine("   DaysSinceSeriousDamage: " + map.damageWatcher.DaysSinceSeriousDamage.ToString("F1"));
                 stringBuilder.AppendLine("   LastThreatBigQueueTick: " + map.storyState.LastThreatBigTick.ToStringTicksToPeriod());
             }
             stringBuilder.AppendLine("   Current points (ignoring early raid factors): " + StorytellerUtility.DefaultThreatPointsNow(incidentTarget).ToString("F0"));
             stringBuilder.AppendLine("   Current points for specific IncidentMakers:");
             for (int j = 0; j < this.storytellerComps.Count; j++)
             {
                 IncidentParms incidentParms = this.storytellerComps[j].GenerateParms(IncidentCategoryDefOf.ThreatBig, incidentTarget);
                 stringBuilder.AppendLine("      " + this.storytellerComps[j].GetType().ToString().Substring(23) + ": " + incidentParms.points.ToString("F0"));
             }
         }
         this.debugStringCached = stringBuilder.ToString();
     }
     return(this.debugStringCached);
 }
Esempio n. 23
0
 public static float DefaultSiteThreatPointsNow()
 {
     return(SiteTuning.ThreatPointsToSiteThreatPointsCurve.Evaluate(StorytellerUtility.DefaultThreatPointsNow(Find.World)) * SiteTuning.SitePointRandomFactorRange.RandomInRange);
 }