Example #1
0
 public void LoadGame()
 {
     if (maps.Any())
     {
         Log.Error("Called LoadGame() but there already is a map. There should be 0 maps...");
         return;
     }
     MemoryUtility.UnloadUnusedUnityAssets();
     BackCompatibility.PreLoadSavegame(ScribeMetaHeaderUtility.loadedGameVersion);
     Current.ProgramState = ProgramState.MapInitializing;
     ExposeSmallComponents();
     LongEventHandler.SetCurrentEventText("LoadingWorld".Translate());
     if (Scribe.EnterNode("world"))
     {
         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) ? maps[value] : null);
         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();
         BackCompatibility.PostLoadSavegame(ScribeMetaHeaderUtility.loadedGameVersion);
     }
     else
     {
         Log.Error("Could not find world XML node.");
     }
 }