public static void StunChances()
        {
            Func <ThingDef, float, bool, string> bluntBodyStunChance = delegate(ThingDef d, float dam, bool onHead)
            {
                SimpleCurve           simpleCurve = (!onHead) ? DamageDefOf.Blunt.bluntStunChancePerDamagePctOfCorePartToBodyCurve : DamageDefOf.Blunt.bluntStunChancePerDamagePctOfCorePartToHeadCurve;
                PawnGenerationRequest request     = new PawnGenerationRequest(d.race.AnyPawnKind, Find.FactionManager.FirstFactionOfDef(d.race.AnyPawnKind.defaultFactionType), PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
                Pawn  pawn = PawnGenerator.GeneratePawn(request);
                float x    = dam / d.race.body.corePart.def.GetMaxHealth(pawn);
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                return(Mathf.Clamp01(simpleCurve.Evaluate(x)).ToStringPercent());
            };
            List <TableDataGetter <ThingDef> > list = new List <TableDataGetter <ThingDef> >();

            list.Add(new TableDataGetter <ThingDef>("defName", (ThingDef d) => d.defName));
            list.Add(new TableDataGetter <ThingDef>("body size", (ThingDef d) => d.race.baseBodySize.ToString("F2")));
            list.Add(new TableDataGetter <ThingDef>("health scale", (ThingDef d) => d.race.baseHealthScale.ToString("F2")));
            list.Add(new TableDataGetter <ThingDef>("body size\n* health scale", (ThingDef d) => (d.race.baseHealthScale * d.race.baseBodySize).ToString("F2")));
            list.Add(new TableDataGetter <ThingDef>("core part\nhealth", delegate(ThingDef d)
            {
                PawnGenerationRequest request = new PawnGenerationRequest(d.race.AnyPawnKind, Find.FactionManager.FirstFactionOfDef(d.race.AnyPawnKind.defaultFactionType), PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
                Pawn pawn       = PawnGenerator.GeneratePawn(request);
                float maxHealth = d.race.body.corePart.def.GetMaxHealth(pawn);
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                return(maxHealth);
            }));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nbody\n5", (ThingDef d) => bluntBodyStunChance(d, 5f, false)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nbody\n10", (ThingDef d) => bluntBodyStunChance(d, 10f, false)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nbody\n15", (ThingDef d) => bluntBodyStunChance(d, 15f, false)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nbody\n20", (ThingDef d) => bluntBodyStunChance(d, 20f, false)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nhead\n5", (ThingDef d) => bluntBodyStunChance(d, 5f, true)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nhead\n10", (ThingDef d) => bluntBodyStunChance(d, 10f, true)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nhead\n15", (ThingDef d) => bluntBodyStunChance(d, 15f, true)));
            list.Add(new TableDataGetter <ThingDef>("stun\nchance\nhead\n20", (ThingDef d) => bluntBodyStunChance(d, 20f, true)));
            DebugTables.MakeTablesDialog <ThingDef>(from d in DefDatabase <ThingDef> .AllDefs
                                                    where d.category == ThingCategory.Pawn
                                                    select d, list.ToArray());
        }
Esempio n. 2
0
        public static void AnimalCombatBalance()
        {
            Func <PawnKindDef, float> meleeDps = delegate(PawnKindDef k)
            {
                Pawn pawn2 = PawnGenerator.GeneratePawn(new PawnGenerationRequest(k, null, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: true));
                while (pawn2.health.hediffSet.hediffs.Count > 0)
                {
                    pawn2.health.RemoveHediff(pawn2.health.hediffSet.hediffs[0]);
                }
                float statValue = pawn2.GetStatValue(StatDefOf.MeleeDPS);
                Find.WorldPawns.PassToWorld(pawn2, PawnDiscardDecideMode.Discard);
                return(statValue);
            };
            Func <PawnKindDef, float> averageArmor = delegate(PawnKindDef k)
            {
                Pawn pawn = PawnGenerator.GeneratePawn(k);
                while (pawn.health.hediffSet.hediffs.Count > 0)
                {
                    pawn.health.RemoveHediff(pawn.health.hediffSet.hediffs[0]);
                }
                float result = (pawn.GetStatValue(StatDefOf.ArmorRating_Blunt) + pawn.GetStatValue(StatDefOf.ArmorRating_Sharp)) / 2f;
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                return(result);
            };
            Func <PawnKindDef, float> combatPowerCalculated = delegate(PawnKindDef k)
            {
                float num  = 1f + meleeDps(k) * 2f;
                float num2 = 1f + (k.RaceProps.baseHealthScale + averageArmor(k) * 1.8f) * 2f;
                float num3 = num * num2 * 2.5f + 10f;
                return(num3 + k.race.GetStatValueAbstract(StatDefOf.MoveSpeed) * 2f);
            };

            DebugTables.MakeTablesDialog(from d in DefDatabase <PawnKindDef> .AllDefs
                                         where d.race != null && d.RaceProps.Animal
                                         orderby d.combatPower
                                         select d, new TableDataGetter <PawnKindDef>("animal", (PawnKindDef k) => k.defName), new TableDataGetter <PawnKindDef>("meleeDps", (PawnKindDef k) => meleeDps(k).ToString("F1")), new TableDataGetter <PawnKindDef>("baseHealthScale", (PawnKindDef k) => k.RaceProps.baseHealthScale.ToString()), new TableDataGetter <PawnKindDef>("moveSpeed", (PawnKindDef k) => k.race.GetStatValueAbstract(StatDefOf.MoveSpeed).ToString()), new TableDataGetter <PawnKindDef>("averageArmor", (PawnKindDef k) => averageArmor(k).ToStringPercent()), new TableDataGetter <PawnKindDef>("combatPowerCalculated", (PawnKindDef k) => combatPowerCalculated(k).ToString("F0")), new TableDataGetter <PawnKindDef>("combatPower", (PawnKindDef k) => k.combatPower.ToString()));
        }
        public static void ColonistRelativeChance()
        {
            HashSet <Pawn> hashSet = new HashSet <Pawn>(Find.WorldPawns.AllPawnsAliveOrDead);
            List <Pawn>    list    = new List <Pawn>();

            for (int i = 0; i < 500; i++)
            {
                PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDefOf.SpaceRefugee, Faction.OfAncients, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
                Pawn pawn = PawnGenerator.GeneratePawn(request);
                list.Add(pawn);
                if (!pawn.IsWorldPawn())
                {
                    Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.KeepForever);
                }
            }
            int num = list.Count((Pawn x) => PawnRelationUtility.GetMostImportantColonyRelative(x) != null);

            Log.Message(string.Concat(new object[]
            {
                "Colony relatives: ",
                ((float)num / 500f).ToStringPercent(),
                " (",
                num,
                " of ",
                500,
                ")"
            }), false);
            foreach (Pawn pawn2 in Find.WorldPawns.AllPawnsAliveOrDead.ToList <Pawn>())
            {
                if (!hashSet.Contains(pawn2))
                {
                    Find.WorldPawns.RemovePawn(pawn2);
                    Find.WorldPawns.PassToWorld(pawn2, PawnDiscardDecideMode.Discard);
                }
            }
        }
Esempio n. 4
0
        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 item2 in orderedEnumerable)
            {
                PawnKindDef     kind = item2;
                Faction         fac  = FactionUtility.DefaultFactionFrom(kind.defaultFactionType);
                FloatMenuOption item = new FloatMenuOption(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;
                        IEnumerator enumerator2           = Enum.GetValues(typeof(WorkTags)).GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                WorkTags workTags = (WorkTags)enumerator2.Current;
                                if (!dictionary.ContainsKey(workTags))
                                {
                                    dictionary.Add(workTags, 0);
                                }
                                if ((combinedDisabledWorkTags & workTags) != 0)
                                {
                                    Dictionary <WorkTags, int> dictionary2;
                                    WorkTags key;
                                    (dictionary2 = dictionary)[key = workTags] = dictionary2[key] + 1;
                                }
                            }
                        }
                        finally
                        {
                            IDisposable disposable;
                            if ((disposable = (enumerator2 as IDisposable)) != null)
                            {
                                disposable.Dispose();
                            }
                        }
                        pawn.Destroy();
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Sampled " + 1000 + "x " + kind.defName + ":");
                    stringBuilder.AppendLine("Worktags disabled");
                    IEnumerator enumerator3 = Enum.GetValues(typeof(WorkTags)).GetEnumerator();
                    try
                    {
                        while (enumerator3.MoveNext())
                        {
                            WorkTags key2 = (WorkTags)enumerator3.Current;
                            int num       = dictionary[key2];
                            stringBuilder.AppendLine("  " + key2.ToString() + "    " + num + " (" + ((float)num / 1000f).ToStringPercent() + ")");
                        }
                    }
                    finally
                    {
                        IDisposable disposable2;
                        if ((disposable2 = (enumerator3 as IDisposable)) != null)
                        {
                            disposable2.Dispose();
                        }
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines());
                });
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Esempio n. 5
0
        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 item2 in orderedEnumerable)
            {
                Faction         fac  = FactionUtility.DefaultFactionFrom(item2.defaultFactionType);
                PawnKindDef     kind = item2;
                FloatMenuOption item = new FloatMenuOption(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 hediff in pawn.health.hediffSet.hediffs)
                        {
                            DefMap <HediffDef, int> defMap2;
                            HediffDef def2;
                            (defMap2 = hediffs)[def2 = hediff.def] = defMap2[def2] + 1;
                        }
                        foreach (Apparel item3 in pawn.apparel.WornApparel)
                        {
                            DefMap <ThingDef, int> defMap;
                            ThingDef def3;
                            (defMap = apparel)[def3 = item3.def] = defMap[def3] + 1;
                        }
                        pawn.Destroy();
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("Sampled " + 400 + "x " + kind.defName + ":");
                    stringBuilder.AppendLine("Weapons");
                    foreach (ThingDef item4 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby weapons[t] descending
                             select t)
                    {
                        int num = weapons[item4];
                        if (num > 0)
                        {
                            stringBuilder.AppendLine("  " + item4.defName + "    " + ((float)num / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Apparel");
                    foreach (ThingDef item5 in from t in DefDatabase <ThingDef> .AllDefs
                             orderby apparel[t] descending
                             select t)
                    {
                        int num2 = apparel[item5];
                        if (num2 > 0)
                        {
                            stringBuilder.AppendLine("  " + item5.defName + "    " + ((float)num2 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Tech hediffs");
                    foreach (HediffDef item6 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved != null
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num3 = hediffs[item6];
                        if (num3 > 0)
                        {
                            stringBuilder.AppendLine("  " + item6.defName + "    " + ((float)num3 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Addiction hediffs");
                    foreach (HediffDef item7 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num4 = hediffs[item7];
                        if (num4 > 0)
                        {
                            stringBuilder.AppendLine("  " + item7.defName + "    " + ((float)num4 / 400f).ToStringPercent());
                        }
                    }
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("Other hediffs");
                    foreach (HediffDef item8 in from h in DefDatabase <HediffDef> .AllDefs
                             where h.spawnThingOnRemoved == null && !h.IsAddiction
                             orderby hediffs[h] descending
                             select h)
                    {
                        int num5 = hediffs[item8];
                        if (num5 > 0)
                        {
                            stringBuilder.AppendLine("  " + item8.defName + "    " + ((float)num5 / 400f).ToStringPercent());
                        }
                    }
                    Log.Message(stringBuilder.ToString().TrimEndNewlines());
                });
                list.Add(item);
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Esempio n. 6
0
        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 item in InfectionList())
            {
                foreach (ThingDef item2 in testMedicine)
                {
                    foreach (int item3 in testSkill)
                    {
                        InfectionSimRow result = new InfectionSimRow
                        {
                            illness  = item,
                            skill    = item3,
                            medicine = item2
                        };
                        Pawn doctor = doctors[item3];
                        int  i      = 0;
                        if (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, item2));
                                    result.medicineUsed += 1f;
                                }
                                foreach (Hediff item4 in patient.health.hediffSet.GetHediffsTendable())
                                {
                                    item4.Tended(TendUtility.CalculateBaseTendQuality(doctor, patient, item2));
                                }
                                Find.TickManager.DebugSetTicksGame(Find.TickManager.TicksGame + 1);
                                patient.health.HealthTick();
                                if (Find.TickManager.TicksGame % 900 == 0)
                                {
                                    yield return((object)null);

                                    /*Error: Unable to find new state assignment for yield return*/;
                                }
                            }
                            if (patient.Dead)
                            {
                                result.deathChance += 1f;
                            }
                            else
                            {
                                result.recoveryTimeDays += (Find.TickManager.TicksGame - startTicks).TicksToDays();
                            }
                            currentTest++;
                            LongEventHandler.SetCurrentEventText($"Simulating ({currentTest}/{totalTests})");
                            yield return((object)null);

                            /*Error: Unable to find new state assignment for yield return*/;
                        }
                        result.recoveryTimeDays /= (float)trials - result.deathChance;
                        result.deathChance      /= (float)trials;
                        result.medicineUsed     /= (float)trials;
                        results.Add(result);
                    }
                }
            }
            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);
            yield break;
IL_06f6:
            /*Error near IL_06f7: Unexpected return in MoveNext()*/;
        }
Esempio n. 7
0
 private static void DoPlayLoad()
 {
     GraphicDatabase.Clear();
     DeepProfiler.Start("Load all active mods.");
     try
     {
         LoadedModManager.LoadAllActiveMods();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Load language metadata.");
     try
     {
         LanguageDatabase.LoadAllMetadata();
     }
     finally
     {
         DeepProfiler.End();
     }
     LongEventHandler.SetCurrentEventText("LoadingDefs".Translate());
     DeepProfiler.Start("Copy all Defs from mods to global databases.");
     try
     {
         foreach (Type item in typeof(Def).AllSubclasses())
         {
             GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods");
         }
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Resolve cross-references between non-implied Defs.");
     try
     {
         DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Rebind defs (early).");
     try
     {
         DefOfHelper.RebindAllDefOfs(earlyTryMode: true);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Inject selected language data into game data (early pass).");
     try
     {
         LanguageDatabase.activeLanguage.InjectIntoData_BeforeImpliedDefs();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Generate implied Defs (pre-resolve).");
     try
     {
         DefGenerator.GenerateImpliedDefs_PreResolve();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs.");
     try
     {
         DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Rebind DefOfs (final).");
     try
     {
         DefOfHelper.RebindAllDefOfs(earlyTryMode: false);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Other def binding, resetting and global operations (pre-resolve).");
     try
     {
         PlayerKnowledgeDatabase.ReloadAndRebind();
         LessonAutoActivator.Reset();
         CostListCalculator.Reset();
         Pawn.ResetStaticData();
         PawnApparelGenerator.Reset();
         RestUtility.Reset();
         ThoughtUtility.Reset();
         PawnWeaponGenerator.Reset();
         ThinkTreeKeyAssigner.Reset();
         ThingCategoryNodeDatabase.FinalizeInit();
         TrainableUtility.Reset();
         HaulAIUtility.Reset();
         GenConstruct.Reset();
         MedicalCareUtility.Reset();
         InspectPaneUtility.Reset();
         GraphicDatabaseHeadRecords.Reset();
         DateReadout.Reset();
         ResearchProjectDef.GenerateNonOverlappingCoordinates();
         BaseGen.Reset();
         ResourceCounter.ResetDefs();
         ApparelProperties.ResetStaticData();
         WildPlantSpawner.ResetStaticData();
         PawnGenerator.Reset();
         TunnelHiveSpawner.ResetStaticData();
         Hive.ResetStaticData();
         ExpectationsUtility.Reset();
         WealthWatcher.ResetStaticData();
         SkillUI.Reset();
         WorkGiver_FillFermentingBarrel.ResetStaticData();
         WorkGiver_DoBill.ResetStaticData();
         WorkGiver_InteractAnimal.ResetStaticData();
         WorkGiver_Warden_DoExecution.ResetStaticData();
         WorkGiver_GrowerSow.ResetStaticData();
         WorkGiver_Miner.ResetStaticData();
         WorkGiver_FixBrokenDownBuilding.ResetStaticData();
         WorkGiver_ConstructDeliverResources.ResetStaticData();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Resolve references.");
     try
     {
         foreach (Type item2 in typeof(Def).AllSubclasses())
         {
             if (item2 != typeof(ThingDef))
             {
                 GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true);
             }
         }
         DefDatabase <ThingDef> .ResolveAllReferences();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Generate implied Defs (post-resolve).");
     try
     {
         DefGenerator.GenerateImpliedDefs_PostResolve();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Other def binding, resetting and global operations (post-resolve).");
     try
     {
         BuildingProperties.FinalizeInit();
         ThingSetMakerUtility.Reset();
     }
     finally
     {
         DeepProfiler.End();
     }
     if (Prefs.DevMode)
     {
         DeepProfiler.Start("Error check all defs.");
         try
         {
             foreach (Type item3 in typeof(Def).AllSubclasses())
             {
                 GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs");
             }
         }
         finally
         {
             DeepProfiler.End();
         }
     }
     LongEventHandler.SetCurrentEventText("Initializing".Translate());
     DeepProfiler.Start("Load keyboard preferences.");
     try
     {
         KeyPrefs.Init();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Short hash giving.");
     try
     {
         ShortHashGiver.GiveAllShortHashes();
     }
     finally
     {
         DeepProfiler.End();
     }
     LongEventHandler.ExecuteWhenFinished(delegate
     {
         DeepProfiler.Start("Load backstories.");
         try
         {
             BackstoryDatabase.ReloadAllBackstories();
         }
         finally
         {
             DeepProfiler.End();
         }
     });
     LongEventHandler.ExecuteWhenFinished(delegate
     {
         DeepProfiler.Start("Inject selected language data into game data.");
         try
         {
             LanguageDatabase.activeLanguage.InjectIntoData_AfterImpliedDefs();
             GenLabel.ClearCache();
         }
         finally
         {
             DeepProfiler.End();
         }
     });
     LongEventHandler.ExecuteWhenFinished(delegate
     {
         StaticConstructorOnStartupUtility.CallAll();
         if (Prefs.DevMode)
         {
             StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes();
         }
     });
 }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
        private static void PawnKindApparelCheck()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (PawnKindDef item in from kd in DefDatabase <PawnKindDef> .AllDefs
                     where kd.race == ThingDefOf.Human
                     orderby kd.defName
                     select kd)
            {
                PawnKindDef localKindDef = item;
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Action, delegate
                {
                    Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                    bool flag       = false;
                    for (int k = 0; k < 100; k++)
                    {
                        Pawn pawn2 = PawnGenerator.GeneratePawn(localKindDef, faction);
                        if (pawn2.royalty != null)
                        {
                            RoyalTitle mostSeniorTitle2 = pawn2.royalty.MostSeniorTitle;
                            if (mostSeniorTitle2 != null && !mostSeniorTitle2.def.requiredApparel.NullOrEmpty())
                            {
                                for (int l = 0; l < mostSeniorTitle2.def.requiredApparel.Count; l++)
                                {
                                    if (!mostSeniorTitle2.def.requiredApparel[l].IsMet(pawn2))
                                    {
                                        Log.Error(localKindDef + " (" + mostSeniorTitle2.def.label + ")  does not have its title requirements met. index=" + l + logApparel(pawn2));
                                        flag = true;
                                    }
                                }
                            }
                        }
                        List <Apparel> wornApparel2 = pawn2.apparel.WornApparel;
                        for (int m = 0; m < wornApparel2.Count; m++)
                        {
                            string text = apparelOkayToWear(pawn2, wornApparel2[m]);
                            if (text != "OK")
                            {
                                Log.Error(text + " - " + wornApparel2[m].Label + logApparel(pawn2));
                                flag = true;
                            }
                        }
                        Find.WorldPawns.PassToWorld(pawn2, PawnDiscardDecideMode.Discard);
                    }
                    if (!flag)
                    {
                        Log.Message("No errors for " + localKindDef.defName);
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
            string apparelOkayToWear(Pawn pawn, Apparel apparel)
            {
                ApparelProperties app = apparel.def.apparel;

                if (!pawn.kindDef.apparelRequired.NullOrEmpty() && pawn.kindDef.apparelRequired.Contains(apparel.def))
                {
                    return("OK");
                }
                if (!app.CorrectGenderForWearing(pawn.gender))
                {
                    return("Wrong gender.");
                }
                List <SpecificApparelRequirement> specificApparelRequirements = pawn.kindDef.specificApparelRequirements;

                if (specificApparelRequirements != null)
                {
                    for (int i = 0; i < specificApparelRequirements.Count; i++)
                    {
                        if (PawnApparelGenerator.ApparelRequirementHandlesThing(specificApparelRequirements[i], apparel.def) && PawnApparelGenerator.ApparelRequirementTagsMatch(specificApparelRequirements[i], apparel.def))
                        {
                            return("OK");
                        }
                    }
                }
                if (!pawn.kindDef.apparelTags.NullOrEmpty())
                {
                    if (!app.tags.Any((string tag) => pawn.kindDef.apparelTags.Contains(tag)))
                    {
                        return("Required tag missing.");
                    }
                    if ((pawn.royalty == null || pawn.royalty.MostSeniorTitle == null) && app.tags.Contains("Royal") && !pawn.kindDef.apparelTags.Any((string tag) => app.tags.Contains(tag)))
                    {
                        return("Royal apparel on non-royal pawn.");
                    }
                }
                if (!pawn.kindDef.apparelDisallowTags.NullOrEmpty() && pawn.kindDef.apparelDisallowTags.Any((string t) => app.tags.Contains(t)))
                {
                    return("Has a disallowed tag.");
                }
                if (pawn.royalty != null && pawn.royalty.AllTitlesInEffectForReading.Any())
                {
                    RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle;
                    if (apparel.TryGetQuality(out QualityCategory qc) && (int)qc < (int)mostSeniorTitle.def.requiredMinimumApparelQuality)
                    {
                        return("Quality too low.");
                    }
                }
                return("OK");
            }

            string logApparel(Pawn p)
            {
                StringBuilder stringBuilder = new StringBuilder();

                stringBuilder.AppendLine();
                stringBuilder.AppendLine($"Apparel of {p.LabelShort}:");
                List <Apparel> wornApparel = p.apparel.WornApparel;

                for (int j = 0; j < wornApparel.Count; j++)
                {
                    stringBuilder.AppendLine("  - " + wornApparel[j].Label);
                }
                return(stringBuilder.ToString());
            }
        }
Esempio n. 10
0
        private static void GenerateTraits(Pawn pawn, PawnGenerationRequest request)
        {
            if (pawn.story == null)
            {
                return;
            }
            if (pawn.story.childhood.forcedTraits != null)
            {
                List <TraitEntry> forcedTraits = pawn.story.childhood.forcedTraits;
                for (int i = 0; i < forcedTraits.Count; i++)
                {
                    TraitEntry traitEntry = forcedTraits[i];
                    if (traitEntry.def == null)
                    {
                        Log.Error("Null forced trait def on " + pawn.story.childhood);
                    }
                    else if (!pawn.story.traits.HasTrait(traitEntry.def))
                    {
                        pawn.story.traits.GainTrait(new Trait(traitEntry.def, traitEntry.degree, false));
                    }
                }
            }
            if (pawn.story.adulthood != null && pawn.story.adulthood.forcedTraits != null)
            {
                List <TraitEntry> forcedTraits2 = pawn.story.adulthood.forcedTraits;
                for (int j = 0; j < forcedTraits2.Count; j++)
                {
                    TraitEntry traitEntry2 = forcedTraits2[j];
                    if (traitEntry2.def == null)
                    {
                        Log.Error("Null forced trait def on " + pawn.story.adulthood);
                    }
                    else if (!pawn.story.traits.HasTrait(traitEntry2.def))
                    {
                        pawn.story.traits.GainTrait(new Trait(traitEntry2.def, traitEntry2.degree, false));
                    }
                }
            }
            int num = Rand.RangeInclusive(2, 3);

            if (request.AllowGay && (LovePartnerRelationUtility.HasAnyLovePartnerOfTheSameGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheSameGender(pawn)))
            {
                Trait trait = new Trait(TraitDefOf.Gay, PawnGenerator.RandomTraitDegree(TraitDefOf.Gay), false);
                pawn.story.traits.GainTrait(trait);
            }
            while (pawn.story.traits.allTraits.Count < num)
            {
                TraitDef newTraitDef = DefDatabase <TraitDef> .AllDefsListForReading.RandomElementByWeight((TraitDef tr) => tr.GetGenderSpecificCommonality(pawn));

                if (!pawn.story.traits.HasTrait(newTraitDef))
                {
                    if (newTraitDef == TraitDefOf.Gay)
                    {
                        if (!request.AllowGay)
                        {
                            continue;
                        }
                        if (LovePartnerRelationUtility.HasAnyLovePartnerOfTheOppositeGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheOppositeGender(pawn))
                        {
                            continue;
                        }
                    }
                    if (request.Faction == null || Faction.OfPlayerSilentFail == null || !request.Faction.HostileTo(Faction.OfPlayer) || newTraitDef.allowOnHostileSpawn)
                    {
                        if (!pawn.story.traits.allTraits.Any((Trait tr) => newTraitDef.ConflictsWith(tr)) && (newTraitDef.conflictingTraits == null || !newTraitDef.conflictingTraits.Any((TraitDef tr) => pawn.story.traits.HasTrait(tr))))
                        {
                            if (newTraitDef.requiredWorkTypes == null || !pawn.story.OneOfWorkTypesIsDisabled(newTraitDef.requiredWorkTypes))
                            {
                                if (!pawn.story.WorkTagIsDisabled(newTraitDef.requiredWorkTags))
                                {
                                    int degree = PawnGenerator.RandomTraitDegree(newTraitDef);
                                    if (!pawn.story.childhood.DisallowsTrait(newTraitDef, degree) && (pawn.story.adulthood == null || !pawn.story.adulthood.DisallowsTrait(newTraitDef, degree)))
                                    {
                                        Trait trait2 = new Trait(newTraitDef, degree, false);
                                        if (pawn.mindState != null && pawn.mindState.mentalBreaker != null)
                                        {
                                            float num2 = pawn.mindState.mentalBreaker.BreakThresholdExtreme;
                                            num2 += trait2.OffsetOfStat(StatDefOf.MentalBreakThreshold);
                                            num2 *= trait2.MultiplierOfStat(StatDefOf.MentalBreakThreshold);
                                            if (num2 > 0.4f)
                                            {
                                                continue;
                                            }
                                        }
                                        pawn.story.traits.GainTrait(trait2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        private static Pawn TryGenerateNewNakedPawn(ref PawnGenerationRequest request, out string error, bool ignoreScenarioRequirements)
        {
            error = null;
            Pawn pawn = (Pawn)ThingMaker.MakeThing(request.KindDef.race, null);

            PawnGenerator.pawnsBeingGenerated.Add(new PawnGenerator.PawnGenerationStatus(pawn, null));
            Pawn result;

            try
            {
                pawn.kindDef = request.KindDef;
                pawn.SetFactionDirect(request.Faction);
                PawnComponentsUtility.CreateInitialComponents(pawn);
                if (request.FixedGender.HasValue)
                {
                    pawn.gender = request.FixedGender.Value;
                }
                else if (pawn.RaceProps.hasGenders)
                {
                    if (Rand.Value < 0.5f)
                    {
                        pawn.gender = Gender.Male;
                    }
                    else
                    {
                        pawn.gender = Gender.Female;
                    }
                }
                else
                {
                    pawn.gender = Gender.None;
                }
                PawnGenerator.GenerateRandomAge(pawn, request);
                pawn.needs.SetInitialLevels();
                if (!request.Newborn && request.CanGeneratePawnRelations)
                {
                    PawnGenerator.GeneratePawnRelations(pawn, ref request);
                }
                if (pawn.RaceProps.Humanlike)
                {
                    pawn.story.melanin   = ((!request.FixedMelanin.HasValue) ? PawnSkinColors.RandomMelanin(request.Faction) : request.FixedMelanin.Value);
                    pawn.story.crownType = ((Rand.Value >= 0.5f) ? CrownType.Narrow : CrownType.Average);
                    pawn.story.hairColor = PawnHairColors.RandomHairColor(pawn.story.SkinColor, pawn.ageTracker.AgeBiologicalYears);
                    PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName);
                    pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, request.Faction.def);
                    PawnGenerator.GenerateTraits(pawn, request);
                    PawnGenerator.GenerateBodyType(pawn);
                    PawnGenerator.GenerateSkills(pawn);
                }
                PawnGenerator.GenerateInitialHediffs(pawn, request);
                if (pawn.workSettings != null && request.Faction.IsPlayer)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                if (request.Faction != null && pawn.RaceProps.Animal)
                {
                    pawn.GenerateNecessaryName();
                }
                if (!request.AllowDead && (pawn.Dead || pawn.Destroyed))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated dead pawn.";
                    result = null;
                }
                else if (!request.AllowDowned && pawn.Downed)
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated downed pawn.";
                    result = null;
                }
                else if (request.MustBeCapableOfViolence && ((pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent)) || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn incapable of violence.";
                    result = null;
                }
                else if (!ignoreScenarioRequirements && request.Context == PawnGenerationContext.PlayerStarter && !Find.Scenario.AllowPlayerStartingPawn(pawn))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn doesn't meet scenario requirements.";
                    result = null;
                }
                else if (request.Validator != null && !request.Validator(pawn))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn didn't pass validator check.";
                    result = null;
                }
                else
                {
                    for (int i = 0; i < PawnGenerator.pawnsBeingGenerated.Count - 1; i++)
                    {
                        if (PawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime == null)
                        {
                            PawnGenerator.pawnsBeingGenerated[i] = new PawnGenerator.PawnGenerationStatus(PawnGenerator.pawnsBeingGenerated[i].Pawn, new List <Pawn>());
                        }
                        PawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime.Add(pawn);
                    }
                    result = pawn;
                }
            }
            finally
            {
                PawnGenerator.pawnsBeingGenerated.RemoveLast <PawnGenerator.PawnGenerationStatus>();
            }
            return(result);
        }
Esempio n. 12
0
        private static Pawn GeneratePawnInternal(PawnGenerationRequest request)
        {
            request.EnsureNonNullFaction();
            Pawn pawn = null;

            if (!request.Newborn && !request.ForceGenerateNewPawn)
            {
                if (request.ForceRedressWorldPawnIfFormerColonist)
                {
                    IEnumerable <Pawn> validCandidatesToRedress = PawnGenerator.GetValidCandidatesToRedress(request);
                    if (validCandidatesToRedress.Where(new Func <Pawn, bool>(PawnUtility.EverBeenColonistOrTameAnimal)).TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn))
                    {
                        PawnGenerator.RedressPawn(pawn, request);
                        Find.WorldPawns.RemovePawn(pawn);
                    }
                }
                if (pawn == null && request.Inhabitant && request.Tile != -1)
                {
                    Settlement settlement = Find.WorldObjects.WorldObjectAt <Settlement>(request.Tile);
                    if (settlement != null && settlement.previouslyGeneratedInhabitants.Any <Pawn>())
                    {
                        IEnumerable <Pawn> validCandidatesToRedress2 = PawnGenerator.GetValidCandidatesToRedress(request);
                        if ((from x in validCandidatesToRedress2
                             where settlement.previouslyGeneratedInhabitants.Contains(x)
                             select x).TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn))
                        {
                            PawnGenerator.RedressPawn(pawn, request);
                            Find.WorldPawns.RemovePawn(pawn);
                        }
                    }
                }
                if (pawn == null && Rand.Chance(PawnGenerator.ChanceToRedressAnyWorldPawn(request)))
                {
                    IEnumerable <Pawn> validCandidatesToRedress3 = PawnGenerator.GetValidCandidatesToRedress(request);
                    if (validCandidatesToRedress3.TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn))
                    {
                        PawnGenerator.RedressPawn(pawn, request);
                        Find.WorldPawns.RemovePawn(pawn);
                    }
                }
            }
            if (pawn == null)
            {
                pawn = PawnGenerator.GenerateNewNakedPawn(ref request);
                if (pawn == null)
                {
                    return(null);
                }
                if (!request.Newborn)
                {
                    PawnGenerator.GenerateGearFor(pawn, request);
                }
                if (request.Inhabitant && request.Tile != -1)
                {
                    Settlement settlement2 = Find.WorldObjects.WorldObjectAt <Settlement>(request.Tile);
                    if (settlement2 != null)
                    {
                        settlement2.previouslyGeneratedInhabitants.Add(pawn);
                    }
                }
            }
            if (Find.Scenario != null)
            {
                Find.Scenario.Notify_PawnGenerated(pawn, request.Context);
            }
            return(pawn);
        }
Esempio n. 13
0
 public static Pawn GeneratePawn(PawnKindDef kindDef, Faction faction = null)
 {
     return(PawnGenerator.GeneratePawn(new PawnGenerationRequest(kindDef, faction, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null)));
 }
Esempio n. 14
0
        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));
        }
Esempio n. 15
0
        private static IEnumerable InfectionSimulatorWorker()
        {
            int         trials    = 2;
            List <Pawn> doctors   = DebugOutputsInfection.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, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
            int originalTicks             = Find.TickManager.TicksGame;
            List <DebugOutputsInfection.InfectionSimRow> results = new List <DebugOutputsInfection.InfectionSimRow>();
            int totalTests  = DebugOutputsInfection.InfectionList().Count <HediffDef>() * testMedicine.Count <ThingDef>() * testSkill.Count <int>() * trials;
            int currentTest = 0;

            foreach (HediffDef hediff in DebugOutputsInfection.InfectionList())
            {
                foreach (ThingDef meds in testMedicine)
                {
                    foreach (int skill in testSkill)
                    {
                        DebugOutputsInfection.InfectionSimRow result = default(DebugOutputsInfection.InfectionSimRow);
                        result.illness  = hediff;
                        result.skill    = skill;
                        result.medicine = meds;
                        Pawn doctor = doctors[skill];
                        for (int i = 0; i < trials; i++)
                        {
                            Pawn patient    = PawnGenerator.GeneratePawn(pawngen);
                            int  startTicks = Find.TickManager.TicksGame;
                            patient.health.AddHediff(result.illness, null, null, null);
                            Hediff activeHediff = patient.health.hediffSet.GetFirstHediffOfDef(result.illness, false);
                            while (!patient.Dead && patient.health.hediffSet.HasHediff(result.illness, false))
                            {
                                if (activeHediff.TendableNow(false))
                                {
                                    activeHediff.Tended(TendUtility.CalculateBaseTendQuality(doctor, patient, meds), 0);
                                    result.medicineUsed += 1f;
                                }
                                foreach (Hediff hediff2 in patient.health.hediffSet.GetHediffsTendable())
                                {
                                    hediff2.Tended(TendUtility.CalculateBaseTendQuality(doctor, patient, meds), 0);
                                }
                                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();
                            }
                            currentTest++;
                            LongEventHandler.SetCurrentEventText(string.Format("Simulating ({0}/{1})", currentTest, totalTests));
                            yield return(null);
                        }
                        result.recoveryTimeDays /= (float)trials - result.deathChance;
                        result.deathChance      /= (float)trials;
                        result.medicineUsed     /= (float)trials;
                        results.Add(result);
                    }
                }
            }
            IEnumerable <DebugOutputsInfection.InfectionSimRow> dataSources = results;

            TableDataGetter <DebugOutputsInfection.InfectionSimRow>[] array = new TableDataGetter <DebugOutputsInfection.InfectionSimRow> [6];
            array[0] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("defName", (DebugOutputsInfection.InfectionSimRow isr) => isr.illness.defName);
            array[1] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("meds", (DebugOutputsInfection.InfectionSimRow isr) => (isr.medicine == null) ? "(none)" : isr.medicine.defName);
            array[2] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("skill", (DebugOutputsInfection.InfectionSimRow isr) => isr.skill.ToString());
            array[3] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("death chance", (DebugOutputsInfection.InfectionSimRow isr) => isr.deathChance.ToStringPercent());
            array[4] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("recovery time (days)", (DebugOutputsInfection.InfectionSimRow isr) => isr.recoveryTimeDays.ToString("F1"));
            array[5] = new TableDataGetter <DebugOutputsInfection.InfectionSimRow>("medicine used", (DebugOutputsInfection.InfectionSimRow isr) => isr.medicineUsed.ToString());
            DebugTables.MakeTablesDialog <DebugOutputsInfection.InfectionSimRow>(dataSources, array);
            Find.TickManager.DebugSetTicksGame(originalTicks);
            yield break;
        }
Esempio n. 16
0
        private static void PawnKindAbilityCheck()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();
            StringBuilder          sb   = new StringBuilder();

            foreach (PawnKindDef item in from kd in DefDatabase <PawnKindDef> .AllDefs
                     where kd.titleRequired != null || !kd.titleSelectOne.NullOrEmpty()
                     orderby kd.defName
                     select kd)
            {
                PawnKindDef localKindDef = item;
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Action, delegate
                {
                    Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                    for (int i = 0; i < 100; i++)
                    {
                        RoyalTitleDef fixedTitle = null;
                        if (localKindDef.titleRequired != null)
                        {
                            fixedTitle = localKindDef.titleRequired;
                        }
                        else if (!localKindDef.titleSelectOne.NullOrEmpty() && Rand.Chance(localKindDef.royalTitleChance))
                        {
                            fixedTitle = localKindDef.titleSelectOne.RandomElementByWeight((RoyalTitleDef t) => t.commonality);
                        }
                        Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(localKindDef, faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, 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));
                        RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle;
                        if (mostSeniorTitle != null)
                        {
                            Hediff_Psylink mainPsylinkSource = pawn.GetMainPsylinkSource();
                            if (mainPsylinkSource == null)
                            {
                                if (mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def) > 0)
                                {
                                    string text = mostSeniorTitle.def.LabelCap + " - No psylink.";
                                    if (pawn.abilities.abilities.Any((Ability x) => x.def.level > 0))
                                    {
                                        text += " Has psycasts without psylink.";
                                    }
                                    sb.AppendLine(text);
                                }
                            }
                            else if (mainPsylinkSource.level < mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def))
                            {
                                sb.AppendLine("Psylink at level " + mainPsylinkSource.level + ", but requires " + mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def));
                            }
                            else if (mainPsylinkSource.level > mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def))
                            {
                                sb.AppendLine("Psylink at level " + mainPsylinkSource.level + ". Max is " + mostSeniorTitle.def.MaxAllowedPsylinkLevel(faction.def));
                            }
                        }
                        Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                    }
                    if (sb.Length == 0)
                    {
                        Log.Message("No errors for " + localKindDef.defName);
                    }
                    else
                    {
                        Log.Error("Errors:\n" + sb.ToString());
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
Esempio n. 17
0
        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));
        }