示例#1
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()*/;
        }
示例#2
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;
        }
 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(true);
     }
     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(false);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Other def binding, resetting and global operations.");
     try
     {
         PlayerKnowledgeDatabase.ReloadAndRebind();
         LessonAutoActivator.Reset();
         CostListCalculator.Reset();
         PawnApparelGenerator.Reset();
         RestUtility.Reset();
         ThoughtUtility.Reset();
         PawnWeaponGenerator.Reset();
         ThinkTreeKeyAssigner.Reset();
         ThingCategoryNodeDatabase.FinalizeInit();
         TrainableUtility.Reset();
         HaulAIUtility.Reset();
         GenConstruct.Reset();
         WorkGiver_FillFermentingBarrel.Reset();
         WorkGiver_DoBill.Reset();
         Pawn.Reset();
         WorkGiver_InteractAnimal.Reset();
         WorkGiver_Warden_DoExecution.Reset();
         WorkGiver_GrowerSow.Reset();
         WorkGiver_Miner.Reset();
         MedicalCareUtility.Reset();
         InspectPaneUtility.Reset();
         GraphicDatabaseHeadRecords.Reset();
         DateReadout.Reset();
         ResearchProjectDef.GenerateNonOverlappingCoordinates();
         WorkGiver_FixBrokenDownBuilding.CacheTranslations();
         ItemCollectionGeneratorUtility.Reset();
         BaseGen.Reset();
         HealthUtility.Reset();
         ResourceCounter.ResetDefs();
         WildSpawner.Reset();
         ApparelProperties.Reset();
     }
     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(true);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Generate implied Defs (post-resolve).");
     try
     {
         DefGenerator.GenerateImpliedDefs_PostResolve();
     }
     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();
             GenLabel.ClearCache();
         }
         finally
         {
             DeepProfiler.End();
         }
     });
     LongEventHandler.ExecuteWhenFinished(delegate
     {
         StaticConstructorOnStartupUtility.CallAll();
         if (Prefs.DevMode)
         {
             StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes();
         }
     });
 }
示例#4
0
        private static void DoPlayLoad()
        {
            DeepProfiler.Start("GraphicDatabase.Clear()");
            try
            {
                GraphicDatabase.Clear();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Load all active mods.");
            try
            {
                LoadedModManager.LoadAllActiveMods();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Load language metadata.");
            try
            {
                LanguageDatabase.InitAllMetadata();
            }
            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("TKeySystem.BuildMappings()");
            try
            {
                TKeySystem.BuildMappings();
            }
            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
            {
                DirectXmlCrossRefLoader.Clear();
                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();
                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();
                QuestNode_GetThingPlayerCanProduce.ResetStaticData();
                Pawn_PsychicEntropyTracker.ResetStaticData();
                ColoredText.ResetStaticData();
                QuestNode_GetRandomNegativeGameCondition.ResetStaticData();
                RoyalTitleUtility.ResetStaticData();
                RewardsGenerator.ResetStaticData();
                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
            {
                DeepProfiler.Start("ThingCategoryDef resolver");
                try
                {
                    DefDatabase <ThingCategoryDef> .ResolveAllReferences();
                }
                finally
                {
                    DeepProfiler.End();
                }
                DeepProfiler.Start("RecipeDef resolver");
                try
                {
                    DeepProfiler.enabled = false;
                    DefDatabase <RecipeDef> .ResolveAllReferences(onlyExactlyMyType : true, parallel : true);

                    DeepProfiler.enabled = true;
                }
                finally
                {
                    DeepProfiler.End();
                }
                DeepProfiler.Start("Static resolver calls");
                try
                {
                    foreach (Type item2 in typeof(Def).AllSubclasses())
                    {
                        if (!(item2 == typeof(ThingDef)) && !(item2 == typeof(ThingCategoryDef)) && !(item2 == typeof(RecipeDef)))
                        {
                            GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true, false);
                        }
                    }
                }
                finally
                {
                    DeepProfiler.End();
                }
                DeepProfiler.Start("ThingDef resolver");
                try
                {
                    DefDatabase <ThingDef> .ResolveAllReferences();
                }
                finally
                {
                    DeepProfiler.End();
                }
            }
            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
            {
                PawnWeaponGenerator.Reset();
                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
            {
                DeepProfiler.Start("Static constructor calls");
                try
                {
                    StaticConstructorOnStartupUtility.CallAll();
                    if (Prefs.DevMode)
                    {
                        StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes();
                    }
                }
                finally
                {
                    DeepProfiler.End();
                }
                DeepProfiler.Start("Garbage Collection");
                try
                {
                    AbstractFilesystem.ClearAllCache();
                    GC.Collect(int.MaxValue, GCCollectionMode.Forced);
                }
                finally
                {
                    DeepProfiler.End();
                }
            });
        }
示例#5
0
 public void LoadGame()
 {
     if (this.maps.Any <Map>())
     {
         Log.Error("Called LoadGame() but there already is a map. There should be 0 maps...", false);
         return;
     }
     MemoryUtility.UnloadUnusedUnityAssets();
     Current.ProgramState = ProgramState.MapInitializing;
     this.ExposeSmallComponents();
     LongEventHandler.SetCurrentEventText("LoadingWorld".Translate());
     if (Scribe.EnterNode("world"))
     {
         try
         {
             this.World = new World();
             this.World.ExposeData();
         }
         finally
         {
             Scribe.ExitNode();
         }
         this.World.FinalizeInit();
         LongEventHandler.SetCurrentEventText("LoadingMap".Translate());
         Scribe_Collections.Look <Map>(ref this.maps, "maps", LookMode.Deep, new object[0]);
         if (this.maps.RemoveAll((Map x) => x == null) != 0)
         {
             Log.Warning("Some maps were null after loading.", false);
         }
         int num = -1;
         Scribe_Values.Look <int>(ref num, "currentMapIndex", -1, false);
         if (num < 0 && this.maps.Any <Map>())
         {
             Log.Error("Current map is null after loading but there are maps available. Setting current map to [0].", false);
             num = 0;
         }
         if (num >= this.maps.Count)
         {
             Log.Error("Current map index out of bounds after loading.", false);
             if (this.maps.Any <Map>())
             {
                 num = 0;
             }
             else
             {
                 num = -1;
             }
         }
         this.currentMapIndex = -128;
         this.CurrentMap      = ((num < 0) ? null : this.maps[num]);
         LongEventHandler.SetCurrentEventText("InitializingGame".Translate());
         Find.CameraDriver.Expose();
         DeepProfiler.Start("FinalizeLoading");
         Scribe.loader.FinalizeLoading();
         DeepProfiler.End();
         LongEventHandler.SetCurrentEventText("SpawningAllThings".Translate());
         for (int i = 0; i < this.maps.Count; i++)
         {
             try
             {
                 this.maps[i].FinalizeLoading();
             }
             catch (Exception arg)
             {
                 Log.Error("Error in Map.FinalizeLoading(): " + arg, false);
             }
             try
             {
                 this.maps[i].Parent.FinalizeLoading();
             }
             catch (Exception arg2)
             {
                 Log.Error("Error in MapParent.FinalizeLoading(): " + arg2, false);
             }
         }
         this.FinalizeInit();
         if (Prefs.PauseOnLoad)
         {
             LongEventHandler.ExecuteWhenFinished(delegate
             {
                 Find.TickManager.DoSingleTick();
                 Find.TickManager.CurTimeSpeed = TimeSpeed.Paused;
             });
         }
         GameComponentUtility.LoadedGame();
         return;
     }
     Log.Error("Could not find world XML node.", false);
 }
示例#6
0
 public void LoadGame()
 {
     if (maps.Any())
     {
         Log.Error("Called LoadGame() but there already is a map. There should be 0 maps...");
     }
     else
     {
         MemoryUtility.UnloadUnusedUnityAssets();
         Current.ProgramState = ProgramState.MapInitializing;
         ExposeSmallComponents();
         LongEventHandler.SetCurrentEventText("LoadingWorld".Translate());
         if (!Scribe.EnterNode("world"))
         {
             Log.Error("Could not find world XML node.");
         }
         else
         {
             try
             {
                 World = new World();
                 World.ExposeData();
             }
             finally
             {
                 Scribe.ExitNode();
             }
             World.FinalizeInit();
             LongEventHandler.SetCurrentEventText("LoadingMap".Translate());
             Scribe_Collections.Look(ref maps, "maps", LookMode.Deep);
             if (maps.RemoveAll((Map x) => x == null) != 0)
             {
                 Log.Warning("Some maps were null after loading.");
             }
             int value = -1;
             Scribe_Values.Look(ref value, "currentMapIndex", -1);
             if (value < 0 && maps.Any())
             {
                 Log.Error("Current map is null after loading but there are maps available. Setting current map to [0].");
                 value = 0;
             }
             if (value >= maps.Count)
             {
                 Log.Error("Current map index out of bounds after loading.");
                 value = ((!maps.Any()) ? (-1) : 0);
             }
             currentMapIndex = sbyte.MinValue;
             CurrentMap      = ((value < 0) ? null : maps[value]);
             LongEventHandler.SetCurrentEventText("InitializingGame".Translate());
             Find.CameraDriver.Expose();
             DeepProfiler.Start("FinalizeLoading");
             Scribe.loader.FinalizeLoading();
             DeepProfiler.End();
             LongEventHandler.SetCurrentEventText("SpawningAllThings".Translate());
             for (int i = 0; i < maps.Count; i++)
             {
                 try
                 {
                     maps[i].FinalizeLoading();
                 }
                 catch (Exception arg)
                 {
                     Log.Error("Error in Map.FinalizeLoading(): " + arg);
                 }
                 try
                 {
                     maps[i].Parent.FinalizeLoading();
                 }
                 catch (Exception arg2)
                 {
                     Log.Error("Error in MapParent.FinalizeLoading(): " + arg2);
                 }
             }
             FinalizeInit();
             if (Prefs.PauseOnLoad)
             {
                 LongEventHandler.ExecuteWhenFinished(delegate
                 {
                     Find.TickManager.DoSingleTick();
                     Find.TickManager.CurTimeSpeed = TimeSpeed.Paused;
                 });
             }
             GameComponentUtility.LoadedGame();
         }
     }
 }
示例#7
0
 public void LoadGame()
 {
     if (this.maps.Any())
     {
         Log.Error("Called LoadGame() but there already is a map. There should be 0 maps...");
     }
     else
     {
         MemoryUtility.UnloadUnusedUnityAssets();
         Current.ProgramState = ProgramState.MapInitializing;
         this.ExposeSmallComponents();
         BackCompatibility.AfterLoadingSmallGameClassComponents(this);
         LongEventHandler.SetCurrentEventText("LoadingWorld".Translate());
         if (Scribe.EnterNode("world"))
         {
             try
             {
                 this.World = new World();
                 this.World.ExposeData();
             }
             finally
             {
                 Scribe.ExitNode();
             }
             this.World.FinalizeInit();
             LongEventHandler.SetCurrentEventText("LoadingMap".Translate());
             Scribe_Collections.Look <Map>(ref this.maps, "maps", LookMode.Deep, new object[0]);
             int num = -1;
             Scribe_Values.Look(ref num, "visibleMapIndex", -1, false);
             if (num < 0 && this.maps.Any())
             {
                 Log.Error("Visible map is null after loading but there are maps available. Setting visible map to [0].");
                 num = 0;
             }
             if (num >= this.maps.Count)
             {
                 Log.Error("Visible map index out of bounds after loading.");
                 num = ((!this.maps.Any()) ? (-1) : 0);
             }
             this.visibleMapIndex = -128;
             this.VisibleMap      = ((num < 0) ? null : this.maps[num]);
             LongEventHandler.SetCurrentEventText("InitializingGame".Translate());
             Find.CameraDriver.Expose();
             DeepProfiler.Start("FinalizeLoading");
             Scribe.loader.FinalizeLoading();
             DeepProfiler.End();
             LongEventHandler.SetCurrentEventText("SpawningAllThings".Translate());
             for (int i = 0; i < this.maps.Count; i++)
             {
                 this.maps[i].FinalizeLoading();
             }
             this.FinalizeInit();
             if (Prefs.PauseOnLoad)
             {
                 LongEventHandler.ExecuteWhenFinished(delegate
                 {
                     Find.TickManager.DoSingleTick();
                     Find.TickManager.CurTimeSpeed = TimeSpeed.Paused;
                 });
             }
             GameComponentUtility.LoadedGame();
         }
         else
         {
             Log.Error("Could not find world XML node.");
         }
     }
 }