Example #1
0
        public void InitNewGame()
        {
            string str = (from mod in LoadedModManager.RunningMods
                          select mod.ToString()).ToCommaList(false);

            Log.Message("Initializing new game with mods " + str, false);
            if (this.maps.Any <Map>())
            {
                Log.Error("Called InitNewGame() but there already is a map. There should be 0 maps...", false);
            }
            else if (this.initData == null)
            {
                Log.Error("Called InitNewGame() but init data is null. Create it first.", false);
            }
            else
            {
                MemoryUtility.UnloadUnusedUnityAssets();
                DeepProfiler.Start("InitNewGame");
                try
                {
                    Current.ProgramState = ProgramState.MapInitializing;
                    IntVec3           intVec      = new IntVec3(this.initData.mapSize, 1, this.initData.mapSize);
                    Settlement        settlement  = null;
                    List <Settlement> settlements = Find.WorldObjects.Settlements;
                    for (int i = 0; i < settlements.Count; i++)
                    {
                        if (settlements[i].Faction == Faction.OfPlayer)
                        {
                            settlement = settlements[i];
                            break;
                        }
                    }
                    if (settlement == null)
                    {
                        Log.Error("Could not generate starting map because there is no any player faction base.", false);
                    }
                    this.tickManager.gameStartAbsTick = GenTicks.ConfiguredTicksAbsAtGameStart;
                    Map currentMap = MapGenerator.GenerateMap(intVec, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs, null);
                    this.worldInt.info.initialMapSize = intVec;
                    if (this.initData.permadeath)
                    {
                        this.info.permadeathMode           = true;
                        this.info.permadeathModeUniqueName = PermadeathModeUtility.GeneratePermadeathSaveName();
                    }
                    PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism);
                    this.FinalizeInit();
                    Current.Game.CurrentMap = currentMap;
                    Find.CameraDriver.JumpToCurrentMapLoc(MapGenerator.PlayerStartSpot);
                    Find.CameraDriver.ResetSize();
                    if (Prefs.PauseOnLoad && this.initData.startedFromEntry)
                    {
                        LongEventHandler.ExecuteWhenFinished(delegate
                        {
                            this.tickManager.DoSingleTick();
                            this.tickManager.CurTimeSpeed = TimeSpeed.Paused;
                        });
                    }
                    Find.Scenario.PostGameStart();
                    if (Faction.OfPlayer.def.startingResearchTags != null)
                    {
                        foreach (ResearchProjectTagDef tag in Faction.OfPlayer.def.startingResearchTags)
                        {
                            foreach (ResearchProjectDef researchProjectDef in DefDatabase <ResearchProjectDef> .AllDefs)
                            {
                                if (researchProjectDef.HasTag(tag))
                                {
                                    this.researchManager.InstantFinish(researchProjectDef, false);
                                }
                            }
                        }
                    }
                    GameComponentUtility.StartedNewGame();
                    this.initData = null;
                }
                finally
                {
                    DeepProfiler.End();
                }
            }
        }
Example #2
0
        public void InitNewGame()
        {
            string str = LoadedModManager.RunningMods.Select((ModContentPack mod) => mod.PackageIdPlayerFacing).ToLineList("  - ");

            Log.Message("Initializing new game with mods:\n" + str);
            if (maps.Any())
            {
                Log.Error("Called InitNewGame() but there already is a map. There should be 0 maps...");
                return;
            }
            if (initData == null)
            {
                Log.Error("Called InitNewGame() but init data is null. Create it first.");
                return;
            }
            MemoryUtility.UnloadUnusedUnityAssets();
            DeepProfiler.Start("InitNewGame");
            try
            {
                Current.ProgramState = ProgramState.MapInitializing;
                IntVec3           intVec      = new IntVec3(initData.mapSize, 1, initData.mapSize);
                Settlement        settlement  = null;
                List <Settlement> settlements = Find.WorldObjects.Settlements;
                for (int i = 0; i < settlements.Count; i++)
                {
                    if (settlements[i].Faction == Faction.OfPlayer)
                    {
                        settlement = settlements[i];
                        break;
                    }
                }
                if (settlement == null)
                {
                    Log.Error("Could not generate starting map because there is no any player faction base.");
                }
                tickManager.gameStartAbsTick = GenTicks.ConfiguredTicksAbsAtGameStart;
                Map currentMap = MapGenerator.GenerateMap(intVec, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs);
                worldInt.info.initialMapSize = intVec;
                if (initData.permadeath)
                {
                    info.permadeathMode           = true;
                    info.permadeathModeUniqueName = PermadeathModeUtility.GeneratePermadeathSaveName();
                }
                PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism);
                FinalizeInit();
                Current.Game.CurrentMap = currentMap;
                Find.CameraDriver.JumpToCurrentMapLoc(MapGenerator.PlayerStartSpot);
                Find.CameraDriver.ResetSize();
                if (Prefs.PauseOnLoad && initData.startedFromEntry)
                {
                    LongEventHandler.ExecuteWhenFinished(delegate
                    {
                        tickManager.DoSingleTick();
                        tickManager.CurTimeSpeed = TimeSpeed.Paused;
                    });
                }
                Find.Scenario.PostGameStart();
                history.FinalizeInit();
                if (Faction.OfPlayer.def.startingResearchTags != null)
                {
                    foreach (ResearchProjectTagDef startingResearchTag in Faction.OfPlayer.def.startingResearchTags)
                    {
                        foreach (ResearchProjectDef allDef in DefDatabase <ResearchProjectDef> .AllDefs)
                        {
                            if (allDef.HasTag(startingResearchTag))
                            {
                                researchManager.FinishProject(allDef);
                            }
                        }
                    }
                }
                if (Faction.OfPlayer.def.startingTechprintsResearchTags != null)
                {
                    foreach (ResearchProjectTagDef startingTechprintsResearchTag in Faction.OfPlayer.def.startingTechprintsResearchTags)
                    {
                        foreach (ResearchProjectDef allDef2 in DefDatabase <ResearchProjectDef> .AllDefs)
                        {
                            if (allDef2.HasTag(startingTechprintsResearchTag))
                            {
                                int techprints = researchManager.GetTechprints(allDef2);
                                if (techprints < allDef2.TechprintCount)
                                {
                                    researchManager.AddTechprints(allDef2, allDef2.TechprintCount - techprints);
                                }
                            }
                        }
                    }
                }
                GameComponentUtility.StartedNewGame();
                initData = null;
            }
            finally
            {
                DeepProfiler.End();
            }
        }