public static void RecruitDifficultiesSampled() { IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs where k.RaceProps.Humanlike orderby k.combatPower select k; List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (PawnKindDef current in orderedEnumerable) { PawnKindDef kind = current; Faction fac = FactionUtility.DefaultFactionFrom(kind.defaultFactionType); if (kind == PawnKindDefOf.WildMan) { fac = null; } FloatMenuOption item = new FloatMenuOption(kind.defName + " (" + kind.baseRecruitDifficulty.ToStringPercent() + ")", delegate { Dictionary <int, int> dictionary = new Dictionary <int, int>(); for (int i = 0; i < 21; i++) { dictionary.Add(i, 0); } for (int j = 0; j < 300; j++) { Pawn pawn = PawnGenerator.GeneratePawn(kind, fac); float num = pawn.RecruitDifficulty(Faction.OfPlayer); int num2 = Mathf.RoundToInt(num * 20f); Dictionary <int, int> dictionary2; int key; (dictionary2 = dictionary)[key = num2] = dictionary2[key] + 1; pawn.Destroy(DestroyMode.Vanish); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(string.Concat(new object[] { "Sampled ", 300, "x ", kind.defName, ":" })); for (int k = 0; k < 21; k++) { int num3 = dictionary[k]; stringBuilder.AppendLine(string.Concat(new object[] { " ", (k * 5).ToString(), " ", num3, " (", ((float)num3 / 300f).ToStringPercent(), ")" })); } Log.Message(stringBuilder.ToString().TrimEndNewlines(), false); }, MenuOptionPriority.Default, null, null, 0f, null, null); list.Add(item); } Find.WindowStack.Add(new FloatMenu(list)); }
public static void PawnKindGearSampled() { IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs where k.RaceProps.ToolUser orderby k.combatPower select k; List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (PawnKindDef current in orderedEnumerable) { Faction fac = FactionUtility.DefaultFactionFrom(current.defaultFactionType); PawnKindDef kind = current; FloatMenuOption item = new FloatMenuOption(string.Concat(new object[] { kind.defName, " (", kind.combatPower, ")" }), delegate { DefMap <ThingDef, int> weapons = new DefMap <ThingDef, int>(); DefMap <ThingDef, int> apparel = new DefMap <ThingDef, int>(); DefMap <HediffDef, int> hediffs = new DefMap <HediffDef, int>(); for (int i = 0; i < 400; i++) { Pawn pawn = PawnGenerator.GeneratePawn(kind, fac); if (pawn.equipment.Primary != null) { DefMap <ThingDef, int> defMap; ThingDef def; (defMap = weapons)[def = pawn.equipment.Primary.def] = defMap[def] + 1; } foreach (Hediff current2 in pawn.health.hediffSet.hediffs) { DefMap <HediffDef, int> hediffs2; HediffDef def2; (hediffs2 = hediffs)[def2 = current2.def] = hediffs2[def2] + 1; } foreach (Apparel current3 in pawn.apparel.WornApparel) { DefMap <ThingDef, int> defMap; ThingDef def3; (defMap = apparel)[def3 = current3.def] = defMap[def3] + 1; } pawn.Destroy(DestroyMode.Vanish); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(string.Concat(new object[] { "Sampled ", 400, "x ", kind.defName, ":" })); stringBuilder.AppendLine("Weapons"); foreach (ThingDef current4 in from t in DefDatabase <ThingDef> .AllDefs orderby weapons[t] descending select t) { int num = weapons[current4]; if (num > 0) { stringBuilder.AppendLine(" " + current4.defName + " " + ((float)num / 400f).ToStringPercent()); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("Apparel"); foreach (ThingDef current5 in from t in DefDatabase <ThingDef> .AllDefs orderby apparel[t] descending select t) { int num2 = apparel[current5]; if (num2 > 0) { stringBuilder.AppendLine(" " + current5.defName + " " + ((float)num2 / 400f).ToStringPercent()); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("Tech hediffs"); foreach (HediffDef current6 in from h in DefDatabase <HediffDef> .AllDefs where h.spawnThingOnRemoved != null orderby hediffs[h] descending select h) { int num3 = hediffs[current6]; if (num3 > 0) { stringBuilder.AppendLine(" " + current6.defName + " " + ((float)num3 / 400f).ToStringPercent()); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("Addiction hediffs"); foreach (HediffDef current7 in from h in DefDatabase <HediffDef> .AllDefs where h.IsAddiction orderby hediffs[h] descending select h) { int num4 = hediffs[current7]; if (num4 > 0) { stringBuilder.AppendLine(" " + current7.defName + " " + ((float)num4 / 400f).ToStringPercent()); } } stringBuilder.AppendLine(); stringBuilder.AppendLine("Other hediffs"); foreach (HediffDef current8 in from h in DefDatabase <HediffDef> .AllDefs where h.spawnThingOnRemoved == null && !h.IsAddiction orderby hediffs[h] descending select h) { int num5 = hediffs[current8]; if (num5 > 0) { stringBuilder.AppendLine(" " + current8.defName + " " + ((float)num5 / 400f).ToStringPercent()); } } Log.Message(stringBuilder.ToString().TrimEndNewlines(), false); }, MenuOptionPriority.Default, null, null, 0f, null, null); list.Add(item); } Find.WindowStack.Add(new FloatMenu(list)); }
public static void PawnWorkDisablesSampled() { IOrderedEnumerable <PawnKindDef> orderedEnumerable = from k in DefDatabase <PawnKindDef> .AllDefs where k.RaceProps.Humanlike orderby k.combatPower select k; List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (PawnKindDef current in orderedEnumerable) { PawnKindDef kind = current; Faction fac = FactionUtility.DefaultFactionFrom(kind.defaultFactionType); FloatMenuOption item = new FloatMenuOption(string.Concat(new object[] { kind.defName, " (", kind.combatPower, ")" }), delegate { Dictionary <WorkTags, int> dictionary = new Dictionary <WorkTags, int>(); for (int i = 0; i < 1000; i++) { Pawn pawn = PawnGenerator.GeneratePawn(kind, fac); WorkTags combinedDisabledWorkTags = pawn.story.CombinedDisabledWorkTags; foreach (WorkTags workTags in Enum.GetValues(typeof(WorkTags))) { if (!dictionary.ContainsKey(workTags)) { dictionary.Add(workTags, 0); } if ((combinedDisabledWorkTags & workTags) != WorkTags.None) { Dictionary <WorkTags, int> dictionary2; WorkTags key; (dictionary2 = dictionary)[key = workTags] = dictionary2[key] + 1; } } pawn.Destroy(DestroyMode.Vanish); } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(string.Concat(new object[] { "Sampled ", 1000, "x ", kind.defName, ":" })); stringBuilder.AppendLine("Worktags disabled"); foreach (WorkTags key2 in Enum.GetValues(typeof(WorkTags))) { int num = dictionary[key2]; stringBuilder.AppendLine(string.Concat(new object[] { " ", key2.ToString(), " ", num, " (", ((float)num / 1000f).ToStringPercent(), ")" })); } Log.Message(stringBuilder.ToString().TrimEndNewlines(), false); }, MenuOptionPriority.Default, null, null, 0f, null, null); list.Add(item); } Find.WindowStack.Add(new FloatMenu(list)); }
private static IEnumerable InfectionSimulatorWorker() { int trials = 2; List <Pawn> doctors = GenerateDoctorArray(); List <int> testSkill = new List <int> { 4, 10, 16 }; List <ThingDef> testMedicine = new List <ThingDef> { null, ThingDefOf.MedicineHerbal, ThingDefOf.MedicineIndustrial, ThingDefOf.MedicineUltratech }; PawnGenerationRequest pawngen = new PawnGenerationRequest(PawnKindDefOf.Colonist, Faction.OfPlayer); int originalTicks = Find.TickManager.TicksGame; List <InfectionSimRow> results = new List <InfectionSimRow>(); int totalTests = InfectionList().Count() * testMedicine.Count() * testSkill.Count() * trials; int currentTest = 0; foreach (HediffDef hediff in InfectionList()) { foreach (ThingDef meds in testMedicine) { foreach (int item in testSkill) { InfectionSimRow result = default(InfectionSimRow); result.illness = hediff; result.skill = item; result.medicine = meds; Pawn doctor = doctors[item]; int i = 0; while (i < trials) { Pawn patient = PawnGenerator.GeneratePawn(pawngen); int startTicks = Find.TickManager.TicksGame; patient.health.AddHediff(result.illness); Hediff activeHediff = patient.health.hediffSet.GetFirstHediffOfDef(result.illness); while (!patient.Dead && patient.health.hediffSet.HasHediff(result.illness)) { if (activeHediff.TendableNow()) { activeHediff.Tended(TendUtility.CalculateBaseTendQuality(doctor, patient, meds)); result.medicineUsed += 1f; } foreach (Hediff item2 in patient.health.hediffSet.GetHediffsTendable()) { item2.Tended(TendUtility.CalculateBaseTendQuality(doctor, patient, meds)); } Find.TickManager.DebugSetTicksGame(Find.TickManager.TicksGame + 1); patient.health.HealthTick(); if (Find.TickManager.TicksGame % 900 == 0) { yield return(null); } } if (patient.Dead) { result.deathChance += 1f; } else { result.recoveryTimeDays += (Find.TickManager.TicksGame - startTicks).TicksToDays(); } int num = currentTest + 1; currentTest = num; LongEventHandler.SetCurrentEventText($"Simulating ({currentTest}/{totalTests})"); yield return(null); num = i + 1; i = num; } result.recoveryTimeDays /= (float)trials - result.deathChance; result.deathChance /= trials; result.medicineUsed /= trials; results.Add(result); result = default(InfectionSimRow); } } } DebugTables.MakeTablesDialog(results, new TableDataGetter <InfectionSimRow>("defName", (InfectionSimRow isr) => isr.illness.defName), new TableDataGetter <InfectionSimRow>("meds", (InfectionSimRow isr) => (isr.medicine == null) ? "(none)" : isr.medicine.defName), new TableDataGetter <InfectionSimRow>("skill", (InfectionSimRow isr) => isr.skill.ToString()), new TableDataGetter <InfectionSimRow>("death chance", (InfectionSimRow isr) => isr.deathChance.ToStringPercent()), new TableDataGetter <InfectionSimRow>("recovery time (days)", (InfectionSimRow isr) => isr.recoveryTimeDays.ToString("F1")), new TableDataGetter <InfectionSimRow>("medicine used", (InfectionSimRow isr) => isr.medicineUsed.ToString())); Find.TickManager.DebugSetTicksGame(originalTicks); }