static bool Prefix(Game __instance) { if (!PersistentWorldManager.GetInstance().PersistentWorldNotNull()) { return(true); } var persistentWorld = PersistentWorldManager.GetInstance().PersistentWorld; var game = __instance; MemoryUtility.UnloadUnusedUnityAssets(); Current.ProgramState = ProgramState.MapInitializing; var mapSize = new IntVec3(__instance.InitData.mapSize, 1, __instance.InitData.mapSize); var settlement = (Settlement)null; var settlements = Find.WorldObjects.Settlements; foreach (var t in settlements) { if (t.Faction != Faction.OfPlayer) { continue; } settlement = t; break; } if (settlement == null) { Log.Error("Could not generate starting map because there is no player faction base."); GenScene.GoToMainMenu(); return(false); } var map = MapGenerator.GenerateMap(mapSize, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs, null); game.CurrentMap = map; // TODO: Implement permanent death mode for colonies. if (__instance.InitData.permadeath) { __instance.Info.permadeathMode = true; } PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism); __instance.FinalizeInit(); Find.CameraDriver.JumpToCurrentMapLoc(MapGenerator.PlayerStartSpot); Find.CameraDriver.ResetSize(); persistentWorld.SchedulePause(); Find.Scenario.PostGameStart(); /* * Complete research needed depending if PlayerFaction is PlayerColony or PlayerTribe. */ if (Faction.OfPlayer.def.startingResearchTags != null) { foreach (var startingResearchTag in Faction.OfPlayer.def.startingResearchTags) { foreach (var allDef in DefDatabase <ResearchProjectDef> .AllDefs) { if (allDef.HasTag(startingResearchTag)) { game.researchManager.FinishProject(allDef, false, null); } } } } GameComponentUtility.StartedNewGame(); persistentWorld.LoadSaver.Status = PersistentWorldLoadSaver.PersistentWorldLoadStatus.Ingame; var colony = PersistentColony.Convert(persistentWorld, Current.Game); colony.ColonyData.UniqueId = ++PersistentWorldManager.GetInstance().PersistentWorld.WorldData.NextColonyId; colony.ColonyData.ActiveWorldTiles.Add(map.Tile); colony.GameData.MapSize = __instance.InitData.mapSize; game.InitData = null; persistentWorld.Colony = colony; persistentWorld.CheckAndSetColonyData(); persistentWorld.Colonies.Add(colony); persistentWorld.LoadedMaps.Add(map.Tile, new HashSet <PersistentColony>() { colony }); return(false); }
public static void GenerateEmptyMap() { LongEventHandler.QueueLongEvent(delegate() { var game = new Game { InitData = new GameInitData() { mapSize = 75, permadeath = false }, Scenario = ScenarioDefOf.Crashlanded.scenario, storyteller = new Storyteller(StorytellerDefOf.Cassandra, DifficultyDefOf.Rough) }; Find.Scenario.PreConfigure(); Current.Game = game; Find.GameInitData.PrepForMapGen(); Find.GameInitData.startedFromEntry = true; Find.Scenario.PreMapGenerate(); Find.GameInitData.ResetWorldRelatedMapInitData(); Current.Game.World = WorldGenerator.GenerateWorld(0.05f, GenText.RandomSeedString(), OverallRainfall.Normal, OverallTemperature.Normal, OverallPopulation.Normal); MemoryUtility.UnloadUnusedUnityAssets(); Find.World.renderer.RegenerateAllLayersNow(); MemoryUtility.UnloadUnusedUnityAssets(); Current.ProgramState = ProgramState.MapInitializing; var mapSize = new IntVec3(game.InitData.mapSize, 1, game.InitData.mapSize); game.World.info.initialMapSize = mapSize; if (game.InitData.permadeath) { game.Info.permadeathMode = true; game.Info.permadeathModeUniqueName = PermadeathModeUtility.GeneratePermadeathSaveName(); } game.tickManager.gameStartAbsTick = GenTicks.ConfiguredTicksAbsAtGameStart; _ = Find.Scenario.parts.RemoveAll(part => part is ScenPart_GameStartDialog); var arrivalMethod = Find.Scenario.AllParts.OfType <ScenPart_PlayerPawnsArriveMethod>().First(); arrivalMethod.method = PlayerPawnsArriveMethod.Standing; var tile = TileFinder.RandomStartingTile(); Find.GameInitData.startingAndOptionalPawns.Clear(); for (var i = 1; i <= 3; i++) { var pawn = StartingPawnUtility.NewGeneratedStartingPawn(); pawn.playerSettings.hostilityResponse = HostilityResponseMode.Ignore; DefDatabase <SkillDef> .AllDefsListForReading.Do(skillDef => pawn.skills.GetSkill(skillDef).EnsureMinLevelWithMargin(1)); Find.GameInitData.startingAndOptionalPawns.Add(pawn); } var settlement = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement); settlement.SetFaction(Find.GameInitData.playerFaction); settlement.Tile = tile; settlement.Name = NameGenerator.GenerateName(Faction.OfPlayer.def.factionNameMaker); Find.WorldObjects.Add(settlement); Current.Game.CurrentMap = MapGenerator.GenerateMap(mapSize, settlement, settlement.MapGeneratorDef, settlement.ExtraGenStepDefs, null); PawnUtility.GiveAllStartingPlayerPawnsThought(ThoughtDefOf.NewColonyOptimism); game.FinalizeInit(); game.playSettings.useWorkPriorities = true; Find.CameraDriver.JumpToCurrentMapLoc(MapGenerator.PlayerStartSpot); Find.CameraDriver.ResetSize(); Find.Scenario.PostGameStart(); foreach (var researchProjectDef in DefDatabase <ResearchProjectDef> .AllDefs) { game.researchManager.FinishProject(researchProjectDef, false, null); } GameComponentUtility.StartedNewGame(); game.InitData = null; }, "GeneratingMap", true, new Action <Exception>(GameAndMapInitExceptionHandlers.ErrorWhileGeneratingMap), true); LongEventHandler.QueueLongEvent(delegate() { ScreenFader.SetColor(Color.black); ScreenFader.StartFade(Color.clear, 0.5f); }, null, false, null, true); }
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(); } }
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(); } }
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(); } } }