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(); }
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) { int ticksGame = Find.TickManager.TicksGame; IncidentQueue incidentQueue = Find.Storyteller.incidentQueue; List <IIncidentTarget> allIncidentTargets = Find.Storyteller.AllIncidentTargets; StorytellerUtility.tmpOldStoryStates.Clear(); for (int i = 0; i < allIncidentTargets.Count; i++) { IIncidentTarget incidentTarget = allIncidentTargets[i]; StorytellerUtility.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 = (onlyThisComp == null) ? Find.Storyteller.MakeIncidentsForInterval() : Find.Storyteller.MakeIncidentsForInterval(onlyThisComp, Find.Storyteller.AllIncidentTargets); foreach (FiringIncident current in enumerable) { if (current == null) { Log.Error("Null incident generated.", false); } if (!currentMapOnly || current.parms.target == Find.CurrentMap) { current.parms.target.StoryState.Notify_IncidentFired(current); allIncidents.Add(new Pair <IncidentDef, IncidentParms>(current.def, current.parms)); current.parms.target.StoryState.Notify_IncidentFired(current); if (!incCountsForTarget.ContainsKey(current.parms.target)) { incCountsForTarget[current.parms.target] = 0; } Dictionary <IIncidentTarget, int> dictionary; IIncidentTarget target; (dictionary = incCountsForTarget)[target = current.parms.target] = dictionary[target] + 1; string text = " "; if (current.def.category == IncidentCategoryDefOf.ThreatBig || current.def.category == IncidentCategoryDefOf.RaidBeacon) { threatBigCount++; text = "T"; } else if (current.def.category == IncidentCategoryDefOf.ThreatSmall) { text = "S"; } int num2 = Find.Storyteller.storytellerComps.IndexOf(current.source); incCountsForComp[num2]++; if (outputSb != null) { outputSb.AppendLine(string.Concat(new object[] { "M", num2, " ", text, " ", Find.TickManager.TicksGame.TicksToDays().ToString("F1"), "d [", Find.TickManager.TicksGame / 1000, "]", current })); } } } Find.TickManager.DebugSetTicksGame(Find.TickManager.TicksGame + 1000); } Find.TickManager.DebugSetTicksGame(ticksGame); Find.Storyteller.incidentQueue = incidentQueue; for (int k = 0; k < allIncidentTargets.Count; k++) { StorytellerUtility.tmpOldStoryStates[allIncidentTargets[k]].CopyTo(allIncidentTargets[k].StoryState); } StorytellerUtility.tmpOldStoryStates.Clear(); }
public static void DebugLogTestFutureIncidents(bool visibleMapOnly) { int ticksGame = Find.TickManager.TicksGame; IncidentQueue incidentQueue = Find.Storyteller.incidentQueue; List <IIncidentTarget> allIncidentTargets = Find.Storyteller.AllIncidentTargets; StorytellerUtility.tmpOldStoryStates.Clear(); for (int i = 0; i < allIncidentTargets.Count; i++) { IIncidentTarget incidentTarget = allIncidentTargets[i]; StorytellerUtility.tmpOldStoryStates.Add(incidentTarget, incidentTarget.StoryState); new StoryState(incidentTarget).CopyTo(incidentTarget.StoryState); } Find.Storyteller.incidentQueue = new IncidentQueue(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Test future incidents for " + Find.Storyteller.def + ":"); int[] array = new int[Find.Storyteller.storytellerComps.Count]; Dictionary <IIncidentTarget, int> dictionary = new Dictionary <IIncidentTarget, int>(); int num = 0; for (int j = 0; j < 6000; j++) { foreach (FiringIncident item in Find.Storyteller.MakeIncidentsForInterval()) { if (!visibleMapOnly || item.parms.target == Find.VisibleMap) { if (!dictionary.ContainsKey(item.parms.target)) { dictionary[item.parms.target] = 0; } Dictionary <IIncidentTarget, int> dictionary2; IIncidentTarget target; (dictionary2 = dictionary)[target = item.parms.target] = dictionary2[target] + 1; string text = " "; if (item.def.category == IncidentCategory.ThreatBig || item.def.category == IncidentCategory.RaidBeacon) { num++; text = "T"; } int num2 = Find.Storyteller.storytellerComps.IndexOf(item.source); array[num2]++; stringBuilder.AppendLine("M" + num2 + " " + text + " " + Find.TickManager.TicksGame.TicksToDays().ToString("F1") + "d " + item); item.parms.target.StoryState.Notify_IncidentFired(item); } } Find.TickManager.DebugSetTicksGame(Find.TickManager.TicksGame + 1000); } stringBuilder.AppendLine(); stringBuilder.AppendLine("Target totals:"); foreach (KeyValuePair <IIncidentTarget, int> item2 in from kvp in dictionary orderby kvp.Value select kvp) { stringBuilder.AppendLine(string.Format(" {0}: {1}", item2.Value, item2.Key)); } stringBuilder.AppendLine(); stringBuilder.AppendLine("Incident totals:"); for (int k = 0; k < array.Length; k++) { float f = (float)array[k] / (float)array.Sum(); float num3 = (float)((float)array[k] / 100.0); float num4 = (float)(1.0 / num3); stringBuilder.AppendLine(" M" + k + ": " + array[k] + " (" + f.ToStringPercent("F2") + " of total, avg " + num3.ToString("F2") + " per day, avg interval " + num4 + ")"); } stringBuilder.AppendLine("Total threats: " + num); stringBuilder.AppendLine("Total threats avg per day: " + ((float)((float)num / 100.0)).ToString("F2")); stringBuilder.AppendLine("Overall: " + array.Sum()); stringBuilder.AppendLine("Overall avg per day: " + ((float)((float)array.Sum() / 100.0)).ToString("F2")); Log.Message(stringBuilder.ToString()); Find.TickManager.DebugSetTicksGame(ticksGame); Find.Storyteller.incidentQueue = incidentQueue; for (int l = 0; l < allIncidentTargets.Count; l++) { StorytellerUtility.tmpOldStoryStates[allIncidentTargets[l]].CopyTo(allIncidentTargets[l].StoryState); } StorytellerUtility.tmpOldStoryStates.Clear(); }