public void LoadAsteroidScenario() { ConfigNode asteroidNode = GetAsteroidModuleNode(); ProtoScenarioModule asteroidModule = new ProtoScenarioModule(asteroidNode); HighLogic.CurrentGame.scenarios.Add(asteroidModule); asteroidModule.Load(ScenarioRunner.fetch); }
public static void CreateSettings(Game game) { if (!game.scenarios.Any(p => p.moduleName == typeof(LastKSC).Name)) { ProtoScenarioModule proto = game.AddProtoScenarioModule(typeof(LastKSC), GameScenes.TRACKSTATION); proto.Load(ScenarioRunner.fetch); } }
private void OnGameStateCreated(Game game) { LastKSC.CreateSettings(game); if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { ProtoScenarioModule m = HighLogic.CurrentGame.scenarios.FirstOrDefault(m => m.moduleName == "LastKSC"); if (m == null) { return; } LastKSC l = (LastKSC)m.Load(ScenarioRunner.Instance); bool noSite; if (!string.IsNullOrEmpty(l.lastSite)) { // found a site, load it ConfigNode site = Sites.GetSiteByName(l.lastSite); if (site == null) { l.lastSite = Sites.defaultSite; noSite = true; } else { KSCSwitcher.SetSiteAndResetCamera(site); Debug.Log("KSCSwitcher set the launch site to the last site, " + l.lastSite); return; } } else { l.lastSite = Sites.defaultSite; noSite = true; } if (noSite) { if (!string.IsNullOrEmpty(Sites.defaultSite)) { ConfigNode site = Sites.GetSiteByName(Sites.defaultSite); if (site == null) { Debug.LogError("KSCSwitcher found a default site name but could not retrieve the site config: " + Sites.defaultSite); return; } else { KSCSwitcher.SetSiteAndResetCamera(site); Debug.Log("KSCSwitcher set the initial launch site to the default" + Sites.defaultSite); } } } } }
public void LoadNewScenarioData(ConfigNode newScenarioData) { ProtoScenarioModule newModule = new ProtoScenarioModule(newScenarioData); try { HighLogic.CurrentGame.scenarios.Add(newModule); newModule.Load(ScenarioRunner.fetch); } catch { DarkLog.Debug("Error loading scenario data!"); blockScenarioDataSends = true; } }
public void LoadNewScenarioData(ConfigNode newScenarioData) { ProtoScenarioModule newModule = new ProtoScenarioModule(newScenarioData); try { HighLogic.CurrentGame.scenarios.Add(newModule); newModule.Load(ScenarioRunner.Instance); } catch { DarkLog.Debug("Error loading scenario data!"); blockScenarioDataSends = true; } }
private static void installScenario() { Game game = HighLogic.CurrentGame; if ((game != null) && !game.scenarios.Any(s => s.moduleName == typeof(EarnedAchievements).Name)) { // add scenario to game ProtoScenarioModule scenario = game.AddProtoScenarioModule(typeof(EarnedAchievements), GameScenes.EDITOR, GameScenes.FLIGHT, GameScenes.SPACECENTER, GameScenes.TRACKSTATION); // load scenario instantly if (scenario.targetScenes.Contains(HighLogic.LoadedScene)) { scenario.Load(ScenarioRunner.fetch); } } }
public void LoadScenarioDataIntoGame() { while (scenarioQueue.Count > 0) { LoadScenarioData(scenarioQueue.Dequeue()); } if (!loadedScience && Client.fetch.gameMode == GameMode.CAREER) { DarkLog.Debug("Creating new science data"); ConfigNode newNode = GetBlankResearchAndDevelopmentNode(); ProtoScenarioModule newModule = new ProtoScenarioModule(newNode); try { HighLogic.CurrentGame.scenarios.Add(newModule); newModule.Load(ScenarioRunner.fetch); } catch { DarkLog.Debug("Error loading new science data!"); blockScenarioDataSends = true; } } }
private void applyScenarioUpdate(KMPScenarioUpdate update) { bool loaded = false; foreach (ProtoScenarioModule proto in HighLogic.CurrentGame.scenarios) { if (proto != null && proto.moduleName == update.name && proto.moduleRef != null && update.getScenarioNode() != null) { Log.Debug("Loading scenario data for existing module: " + update.name); if (update.name == "ResearchAndDevelopment") { ResearchAndDevelopment rd = (ResearchAndDevelopment) proto.moduleRef; Log.Debug("pre-R&D: {0}", rd.Science); } try { proto.moduleRef.Load(update.getScenarioNode()); } catch (Exception e) { KMPClientMain.sendConnectionEndMessage("Error in handling scenario data. Please restart your client. "); Log.Debug(e.ToString()); } if (update.name == "ResearchAndDevelopment") { ResearchAndDevelopment rd = (ResearchAndDevelopment) proto.moduleRef; Log.Debug("post-R&D: {0}", rd.Science); } loaded = true; break; } } if (!loaded) { Log.Debug("Loading new scenario module data: " + update.name); ProtoScenarioModule newScenario = new ProtoScenarioModule(update.getScenarioNode()); //var proto = HighLogic.CurrentGame.AddProtoScenarioModule(newScenario.GetType(), GameScenes.SPACECENTER, GameScenes.FLIGHT, GameScenes.TRACKSTATION); HighLogic.CurrentGame.scenarios.Add(newScenario); newScenario.Load(ScenarioRunner.fetch); if (update.name == "ScenarioDiscoverableObjects") { ScenarioDiscoverableObjects sdo = (ScenarioDiscoverableObjects) newScenario.moduleRef; sdo.spawnInterval *= (playerStatus.Count()+1); //Throttle spawn rate based on number of players (at connection time) sdo.debugSpawnProbability(); sdoReceived = true; } } clearEditorPartList = true; }
private void handleScenarioUpdate(object obj) { if (obj is KMPScenarioUpdate) { KMPScenarioUpdate update = (KMPScenarioUpdate) obj; bool loaded = false; foreach (ProtoScenarioModule proto in HighLogic.CurrentGame.scenarios) { if (proto != null && proto.moduleName == update.name && proto.moduleRef != null && update.getScenarioNode() != null) { Log.Debug("Loading scenario data for existing module: " + update.name); if (update.name == "ResearchAndDevelopment") { ResearchAndDevelopment rd = (ResearchAndDevelopment) proto.moduleRef; Log.Debug("pre-R&D: {0}", rd.Science); } try { proto.moduleRef.Load(update.getScenarioNode()); } catch (Exception e) { KMPClientMain.sendConnectionEndMessage("Error in handling scenario data. Please restart your client. "); Log.Debug(e.ToString()); } if (update.name == "ResearchAndDevelopment") { ResearchAndDevelopment rd = (ResearchAndDevelopment) proto.moduleRef; Log.Debug("post-R&D: {0}", rd.Science); } loaded = true; break; } } if (!loaded) { Log.Debug("Loading new scenario module data: " + update.name); ProtoScenarioModule newScenario = new ProtoScenarioModule(update.getScenarioNode()); newScenario.Load(ScenarioRunner.fetch); } clearEditorPartList = true; } }
public void LoadScenarioData(ScenarioEntry entry) { if (entry.scenarioName == "ScenarioDiscoverableObjects") { DarkLog.Debug("Skipping loading asteroid data - It is created locally"); return; } if (entry.scenarioName == "ResearchAndDevelopment" && Client.fetch.gameMode != GameMode.CAREER) { DarkLog.Debug("Skipping loading career mode data in sandbox"); return; } if (entry.scenarioName == "ResearchAndDevelopment" && Client.fetch.gameMode == GameMode.CAREER) { loadedScience = true; } //Don't stare directly at the next 7 lines - It's bad for your eyes. string tempFile = Path.GetTempFileName(); using (StreamWriter sw = new StreamWriter(tempFile)) { sw.Write(entry.scenarioData); } ConfigNode scenarioNode = ConfigNode.Load(tempFile); File.Delete(tempFile); if (scenarioNode == null) { DarkLog.Debug(entry.scenarioName + " scenario data failed to create a ConfigNode!"); blockScenarioDataSends = true; return; } bool loaded = false; foreach (ProtoScenarioModule psm in HighLogic.CurrentGame.scenarios) { if (psm.moduleName == entry.scenarioName) { DarkLog.Debug("Loading existing " + entry.scenarioName + " scenario module"); try { if (psm.moduleRef == null) { DarkLog.Debug("Fixing null scenario module!"); psm.moduleRef = new ScenarioModule(); } psm.moduleRef.Load(scenarioNode); } catch (Exception e) { DarkLog.Debug("Error loading " + entry.scenarioName + " scenario module, Exception: " + e); blockScenarioDataSends = true; } loaded = true; } } if (!loaded) { DarkLog.Debug("Loading new " + entry.scenarioName + " scenario module"); ProtoScenarioModule scenarioModule = new ProtoScenarioModule(scenarioNode); try { HighLogic.CurrentGame.scenarios.Add(scenarioModule); scenarioModule.Load(ScenarioRunner.fetch); } catch (Exception e) { DarkLog.Debug("Error loading " + entry.scenarioName + " scenario module, Exception: " + e); blockScenarioDataSends = true; } } }