public static void DebugLogTestFutureIncidents(ThreatsGeneratorParams parms) { StringBuilder stringBuilder = new StringBuilder(); DebugGetFutureIncidents(20, currentMapOnly: true, out Dictionary <IIncidentTarget, int> incCountsForTarget, out int[] incCountsForComp, out List <Pair <IncidentDef, IncidentParms> > allIncidents, out int threatBigCount, stringBuilder, null, parms); new StringBuilder(); string header = "Test future incidents for ThreatsGenerator " + parms + " (" + 20 + " days, difficulty " + Find.Storyteller.difficulty + ")"; DebugLogIncidentsInternal(allIncidents, threatBigCount, incCountsForTarget, incCountsForComp, 20, stringBuilder.ToString(), header); }
public static void DebugLogTestFutureIncidents(ThreatsGeneratorParams parms) { StringBuilder stringBuilder = new StringBuilder(); DebugGetFutureIncidents(20, currentMapOnly: true, out var incCountsForTarget, out var incCountsForComp, out var allIncidents, out var threatBigCount, stringBuilder, null, parms); new StringBuilder(); string header = string.Concat("Test future incidents for ThreatsGenerator ", parms, " (", 20, " days, difficulty ", Find.Storyteller.difficulty, ")"); DebugLogIncidentsInternal(allIncidents, threatBigCount, incCountsForTarget, incCountsForComp, 20, stringBuilder.ToString(), header); }
public static IEnumerable <FiringIncident> MakeIntervalIncidents(ThreatsGeneratorParams parms, IIncidentTarget target, int startTick) { float threatsGeneratorThreatCountFactor = Find.Storyteller.difficulty.threatsGeneratorThreatCountFactor; int incCount = IncidentCycleUtility.IncidentCountThisInterval(target, parms.randSeed, (float)startTick / 60000f, parms.onDays, parms.offDays, parms.minSpacingDays, parms.numIncidentsRange.min * threatsGeneratorThreatCountFactor, parms.numIncidentsRange.max * threatsGeneratorThreatCountFactor); for (int i = 0; i < incCount; i++) { FiringIncident firingIncident = MakeThreat(parms, target); if (firingIncident != null) { yield return(firingIncident); } } }
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); }
private static FiringIncident MakeThreat(ThreatsGeneratorParams parms, IIncidentTarget target) { IncidentParms incParms = GetIncidentParms(parms, target); if (!(from x in GetPossibleIncidents(parms.allowedThreats) where x.Worker.CanFireNow(incParms) select x).TryRandomElementByWeight((IncidentDef x) => x.Worker.BaseChanceThisGame, out IncidentDef result)) { return(null); } return(new FiringIncident { def = result, parms = incParms }); }
public static bool AnyIncidentPossible(ThreatsGeneratorParams parms, IIncidentTarget target) { IncidentParms incParms = GetIncidentParms(parms, target); return(GetPossibleIncidents(parms.allowedThreats).Any((IncidentDef x) => x.Worker.BaseChanceThisGame > 0f && x.Worker.CanFireNow(incParms))); }
public static void DebugGetFutureIncidents(int numTestDays, bool currentMapOnly, out Dictionary <IIncidentTarget, int> incCountsForTarget, out int[] incCountsForComp, out List <Pair <IncidentDef, IncidentParms> > allIncidents, out int threatBigCount, StringBuilder outputSb = null, StorytellerComp onlyThisComp = null, ThreatsGeneratorParams onlyThisThreatsGenerator = null, QuestPart onlyThisQuestPart = null) { int ticksGame = Find.TickManager.TicksGame; IncidentQueue incidentQueue = Find.Storyteller.incidentQueue; List <IIncidentTarget> allIncidentTargets = Find.Storyteller.AllIncidentTargets; tmpOldStoryStates.Clear(); for (int i = 0; i < allIncidentTargets.Count; i++) { IIncidentTarget incidentTarget = allIncidentTargets[i]; tmpOldStoryStates.Add(incidentTarget, incidentTarget.StoryState); new StoryState(incidentTarget).CopyTo(incidentTarget.StoryState); } Find.Storyteller.incidentQueue = new IncidentQueue(); int num = numTestDays * 60; incCountsForComp = new int[Find.Storyteller.storytellerComps.Count]; incCountsForTarget = new Dictionary <IIncidentTarget, int>(); allIncidents = new List <Pair <IncidentDef, IncidentParms> >(); threatBigCount = 0; for (int j = 0; j < num; j++) { IEnumerable <FiringIncident> enumerable = (onlyThisThreatsGenerator != null) ? ThreatsGenerator.MakeIntervalIncidents(onlyThisThreatsGenerator, Find.CurrentMap, ticksGame) : ((onlyThisComp != null) ? Find.Storyteller.MakeIncidentsForInterval(onlyThisComp, Find.Storyteller.AllIncidentTargets) : ((onlyThisQuestPart == null) ? Find.Storyteller.MakeIncidentsForInterval() : (from x in Find.Storyteller.MakeIncidentsForInterval() where x.sourceQuestPart == onlyThisQuestPart select x))); foreach (FiringIncident item in enumerable) { if (item == null) { Log.Error("Null incident generated."); } if (!currentMapOnly || item.parms.target == Find.CurrentMap) { item.parms.target.StoryState.Notify_IncidentFired(item); allIncidents.Add(new Pair <IncidentDef, IncidentParms>(item.def, item.parms)); if (!incCountsForTarget.ContainsKey(item.parms.target)) { incCountsForTarget[item.parms.target] = 0; } incCountsForTarget[item.parms.target]++; string text; if (item.def.category != IncidentCategoryDefOf.ThreatBig) { text = ((item.def.category != IncidentCategoryDefOf.ThreatSmall) ? " " : "S "); } else { threatBigCount++; text = "T "; } string text2; if (onlyThisThreatsGenerator != null) { text2 = ""; } else { int num2 = Find.Storyteller.storytellerComps.IndexOf(item.source); if (num2 >= 0) { incCountsForComp[num2]++; text2 = "M" + num2 + " "; } else { text2 = ""; } } text2 = text2.PadRight(4); outputSb?.AppendLine(text2 + text + (Find.TickManager.TicksGame.TicksToDays().ToString("F1") + "d").PadRight(6) + " " + item); } } Find.TickManager.DebugSetTicksGame(Find.TickManager.TicksGame + 1000); } Find.TickManager.DebugSetTicksGame(ticksGame); Find.Storyteller.incidentQueue = incidentQueue; for (int k = 0; k < allIncidentTargets.Count; k++) { tmpOldStoryStates[allIncidentTargets[k]].CopyTo(allIncidentTargets[k].StoryState); } tmpOldStoryStates.Clear(); }