示例#1
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
            {
                //InitMap
                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=Map

                //Map currentMap = MapGenerator.GenerateMap(intVec, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs);

                //Map currentMap=MapGenerator.GenerateMap(intVec,settlement,settlement.MapGeneratorDef,settlement.ExtraGenStepDefs)

                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;
                    });
                }

                //--------------end
                Find.Scenario.PostGameStart();
                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();
            }
        }
示例#2
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);
                return;
            }
            if (this.initData == null)
            {
                Log.Error("Called InitNewGame() but init data is null. Create it first.", false);
                return;
            }
            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 current in Faction.OfPlayer.def.startingResearchTags)
                    {
                        foreach (ResearchProjectDef current2 in DefDatabase <ResearchProjectDef> .AllDefs)
                        {
                            if (current2.HasTag(current))
                            {
                                this.researchManager.FinishProject(current2, false, null);
                            }
                        }
                    }
                }
                GameComponentUtility.StartedNewGame();
                this.initData = null;
            }
            finally
            {
                DeepProfiler.End();
            }
        }
示例#3
0
        public void InitNewGame()
        {
            string str = GenText.ToCommaList(from mod in LoadedModManager.RunningMods
                                             select mod.ToString(), true);

            Log.Message("Initializing new game with mods " + str);
            if (this.maps.Any())
            {
                Log.Error("Called InitNewGame() but there already is a map. There should be 0 maps...");
            }
            else if (this.initData == null)
            {
                Log.Error("Called InitNewGame() but init data is null. Create it first.");
            }
            else
            {
                MemoryUtility.UnloadUnusedUnityAssets();
                DeepProfiler.Start("InitNewGame");
                try
                {
                    Current.ProgramState = ProgramState.MapInitializing;
                    IntVec3            intVec       = new IntVec3(this.initData.mapSize, 1, this.initData.mapSize);
                    FactionBase        factionBase  = null;
                    List <FactionBase> factionBases = Find.WorldObjects.FactionBases;
                    int num = 0;
                    while (num < factionBases.Count)
                    {
                        if (factionBases[num].Faction != Faction.OfPlayer)
                        {
                            num++;
                            continue;
                        }
                        factionBase = factionBases[num];
                        break;
                    }
                    if (factionBase == null)
                    {
                        Log.Error("Could not generate starting map because there is no any player faction base.");
                    }
                    this.tickManager.gameStartAbsTick = GenTicks.ConfiguredTicksAbsAtGameStart;
                    Map visibleMap = MapGenerator.GenerateMap(intVec, factionBase, factionBase.MapGeneratorDef, factionBase.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.VisibleMap = visibleMap;
                    Find.CameraDriver.JumpToVisibleMapLoc(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 (string startingResearchTag in Faction.OfPlayer.def.startingResearchTags)
                        {
                            foreach (ResearchProjectDef allDef in DefDatabase <ResearchProjectDef> .AllDefs)
                            {
                                if (allDef.HasTag(startingResearchTag))
                                {
                                    this.researchManager.InstantFinish(allDef, false);
                                }
                            }
                        }
                    }
                    GameComponentUtility.StartedNewGame();
                    this.initData = null;
                }
                finally
                {
                    DeepProfiler.End();
                }
            }
        }