private static bool IsDlcScenarioInstalled(string scenarioName) { if (scenarioName == "DeployedScience" && !ExpansionsLoader.IsExpansionInstalled("Serenity")) { return(false); } return(true); }
private static void ApplyLaunchSitePatches() { #if !KSP131 if (!ExpansionsLoader.IsExpansionInstalled("MakingHistory")) { return; } PQSCity2[] cities = FindObjectsOfType <PQSCity2>(); for (Int32 i = 0; i < Templates.RemoveLaunchSites.Count; i++) { String site = Templates.RemoveLaunchSites[i]; // Remove the launch site from the list if it exists if (PSystemSetup.Instance.LaunchSites.Any(s => s.name == site)) { PSystemSetup.Instance.RemoveLaunchSite(site); } PQSCity2 city = cities.FirstOrDefault(c => { GameObject o; return((o = c.gameObject).name == site || o.name == site + "(Clone)"); }); // Kill the PQSCity if it exists if (city != null) { Destroy(city.gameObject); } } // PSystemSetup.RemoveLaunchSite does not remove launch sites from PSystemSetup.StockLaunchSites // Currently an ArgumentOutOfRangeException can result when they are different lists because of a bug in stock code try { FieldInfo stockLaunchSitesField = typeof(PSystemSetup).GetField("stocklaunchsites", BindingFlags.NonPublic | BindingFlags.Instance); if (stockLaunchSitesField == null) { return; } LaunchSite[] stockLaunchSites = (LaunchSite[])stockLaunchSitesField.GetValue(PSystemSetup.Instance); LaunchSite[] updateStockLaunchSites = stockLaunchSites.Where(site => !Templates.RemoveLaunchSites.Contains(site.name)).ToArray(); if (stockLaunchSites.Length != updateStockLaunchSites.Length) { stockLaunchSitesField.SetValue(PSystemSetup.Instance, updateStockLaunchSites); } } catch (Exception ex) { Logger.Default.Log("Failed to remove launch sites from 'stockLaunchSites' field. Exception information follows."); Logger.Default.LogException(ex); } #endif }
public override bool RequirementMet(ConfiguredContract contract) { foreach (string expansion in expansions) { if (!ExpansionsLoader.IsExpansionInstalled(expansion)) { return(false); } } return(true); }
private static bool IsScenarioModuleAllowed(string scenarioName) { if (string.IsNullOrEmpty(scenarioName)) { return(false); } if (scenarioName == "DeployedScience" && !ExpansionsLoader.IsExpansionInstalled("Serenity")) { return(false); } if (!IsDlcScenarioInstalled(scenarioName)) { return(false); } if (!AllScenarioTypesInAssemblies.ContainsKey(scenarioName)) { return(false); //Module missing } var scenarioType = AllScenarioTypesInAssemblies[scenarioName]; var scenarioAttributes = (KSPScenario[])scenarioType.GetCustomAttributes(typeof(KSPScenario), true); if (scenarioAttributes.Length > 0) { var attribute = scenarioAttributes[0]; var protoAllowed = false; if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { protoAllowed = attribute.HasCreateOption(ScenarioCreationOptions.AddToExistingCareerGames); protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToNewCareerGames); } if (HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX) { protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToExistingScienceSandboxGames); protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToNewScienceSandboxGames); } if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX) { protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToExistingSandboxGames); protoAllowed |= attribute.HasCreateOption(ScenarioCreationOptions.AddToNewSandboxGames); } return(protoAllowed); } //Scenario is not marked with KSPScenario - let's load it anyway. return(true); }
public override void OnAwake() { base.OnAwake(); // Right now we only look at deployed science, which is a Breaking Ground feature if (!ExpansionsLoader.IsExpansionInstalled("Serenity")) { Destroy(this); } else { deployedScienceTag = Localizer.GetStringByTag("#autoLOC_8002254"); deployedScienceMessageTitle = Localizer.GetStringByTag("#cc.science.deployedScienceReport"); } }
private static void OnPQSLoaderPostApply(PQSLoader pqs, ConfigNode node) { // You need to pay for rocks if (!ExpansionsLoader.IsExpansionInstalled("Serenity")) { return; } PQSROCControl rockController = pqs.Value.GetComponentInChildren <PQSROCControl>(); if (!rockController) { GameObject rockControllerObject = new GameObject("My rocks are bigger than yours."); rockController = rockControllerObject.AddComponent <PQSROCControl>(); rockController.sphere = pqs.Value; rockController.modEnabled = true; rockController.order = 987654321; rockController.transform.parent = rockController.sphere.transform; rockController.rocs = new List <LandClassROC>(); } // We support modding rockController.currentCBName = pqs.Value.name; }
// Execute MainMenu functions void Start() { previous = PlanetariumCamera.fetch.initialTarget; PlanetariumCamera.fetch.targets .Where(m => m.celestialBody != null && (m.celestialBody.Has("barycenter") || !m.celestialBody.Get("selectable", true))) .ToList() .ForEach(map => PlanetariumCamera.fetch.targets.Remove(map)); // Stars GameObject gob = Sun.Instance.gameObject; KopernicusStar star = gob.AddComponent <KopernicusStar>(); Utility.CopyObjectFields(Sun.Instance, star, false); DestroyImmediate(Sun.Instance); Sun.Instance = star; // LensFlares gob = SunFlare.Instance.gameObject; KopernicusSunFlare flare = gob.AddComponent <KopernicusSunFlare>(); gob.name = star.sun.name; Utility.CopyObjectFields(SunFlare.Instance, flare, false); DestroyImmediate(SunFlare.Instance); SunFlare.Instance = star.lensFlare = flare; // Bodies Dictionary <String, KeyValuePair <CelestialBody, CelestialBody> > fixes = new Dictionary <String, KeyValuePair <CelestialBody, CelestialBody> >(); foreach (CelestialBody body in PSystemManager.Instance.localBodies) { // More stars if (body.flightGlobalsIndex != 0 && body.scaledBody.GetComponentsInChildren <SunShaderController>(true).Length > 0) { GameObject starObj = Instantiate(Sun.Instance.gameObject); star = starObj.GetComponent <KopernicusStar>(); star.sun = body; starObj.transform.parent = Sun.Instance.transform.parent; starObj.name = body.name; starObj.transform.localPosition = Vector3.zero; starObj.transform.localRotation = Quaternion.identity; starObj.transform.localScale = Vector3.one; starObj.transform.position = body.position; starObj.transform.rotation = body.rotation; GameObject flareObj = Instantiate(SunFlare.Instance.gameObject); flare = flareObj.GetComponent <KopernicusSunFlare>(); star.lensFlare = flare; flareObj.transform.parent = SunFlare.Instance.transform.parent; flareObj.name = body.name; flareObj.transform.localPosition = Vector3.zero; flareObj.transform.localRotation = Quaternion.identity; flareObj.transform.localScale = Vector3.one; flareObj.transform.position = body.position; flareObj.transform.rotation = body.rotation; } // Post spawn patcher if (body.Has("orbitPatches")) { ConfigNode orbitNode = body.Get <ConfigNode>("orbitPatches"); OrbitLoader loader = new OrbitLoader(body); Parser.LoadObjectFromConfigurationNode(loader, orbitNode, "Kopernicus"); CelestialBody oldRef = body.referenceBody; body.referenceBody.orbitingBodies.Remove(body); CelestialBody newRef = UBI.GetBody(loader.referenceBody); if (newRef != null) { body.orbit.referenceBody = body.orbitDriver.referenceBody = newRef; } else { // Log the exception Debug.Log("Exception: PostSpawnOrbit reference body for \"" + body.name + "\" could not be found. Missing body name is \"" + loader.referenceBody + "\"."); // Open the Warning popup Injector.DisplayWarning(); } fixes.Add(body.transform.name, new KeyValuePair <CelestialBody, CelestialBody>(oldRef, body.referenceBody)); body.referenceBody.orbitingBodies.Add(body); body.referenceBody.orbitingBodies = body.referenceBody.orbitingBodies.OrderBy(cb => cb.orbit.semiMajorAxis).ToList(); body.orbit.Init(); body.orbitDriver.UpdateOrbit(); // Calculations if (!body.Has("sphereOfInfluence")) { body.sphereOfInfluence = body.orbit.semiMajorAxis * Math.Pow(body.Mass / body.orbit.referenceBody.Mass, 0.4); } if (!body.Has("hillSphere")) { body.hillSphere = body.orbit.semiMajorAxis * (1 - body.orbit.eccentricity) * Math.Pow(body.Mass / body.orbit.referenceBody.Mass, 0.333333333333333); } if (body.solarRotationPeriod) { Double rotPeriod = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, body.transform.name).celestialBody.rotationPeriod; Double num1 = Math.PI * 2 * Math.Sqrt(Math.Pow(Math.Abs(body.orbit.semiMajorAxis), 3) / body.orbit.referenceBody.gravParameter); body.rotationPeriod = rotPeriod * num1 / (num1 + rotPeriod);; } } } // Update the order in the tracking station List <MapObject> trackingstation = new List <MapObject>(); Utility.DoRecursive(PSystemManager.Instance.localBodies[0], cb => cb.orbitingBodies, cb => { trackingstation.Add(PlanetariumCamera.fetch.targets.Find(t => t.celestialBody == cb)); }); PlanetariumCamera.fetch.targets.Clear(); PlanetariumCamera.fetch.targets.AddRange(trackingstation); // Update the initialTarget of the tracking station Resources.FindObjectsOfTypeAll <PlanetariumCamera>().FirstOrDefault().initialTarget = Resources.FindObjectsOfTypeAll <ScaledMovement>().FirstOrDefault(o => o.celestialBody.isHomeWorld); // Undo stuff foreach (CelestialBody b in PSystemManager.Instance.localBodies.Where(b_ => b_.Has("orbitPatches"))) { fixes[b.transform.name].Value.orbitingBodies.Remove(b); fixes[b.transform.name].Key.orbitingBodies.Add(b); fixes[b.transform.name].Key.orbitingBodies = fixes[b.transform.name].Key.orbitingBodies.OrderBy(cb => cb.orbit.semiMajorAxis).ToList(); } #if !KSP131 if (ExpansionsLoader.IsExpansionInstalled("MakingHistory")) { PQSCity2[] cities = FindObjectsOfType <PQSCity2>(); foreach (String site in Templates.RemoveLaunchSites) { // Remove the launch site from the list if it exists if (PSystemSetup.Instance.LaunchSites.Any(s => s.name == site)) { PSystemSetup.Instance.RemoveLaunchSite(site); } PQSCity2 city = cities.FirstOrDefault(c => c.gameObject.name == site || c.gameObject.name == site + "(Clone)"); // Kill the PQSCity if it exists if (city != null) { Destroy(city.gameObject); } } // PSystemSetup.RemoveLaunchSite does not remove launch sites from PSystemSetup.StockLaunchSites // Currently an ArgumentOutOfRangeException can result when they are different lists because of a bug in stock code try { FieldInfo stockLaunchSitesField = typeof(PSystemSetup).GetField("stocklaunchsites", BindingFlags.NonPublic | BindingFlags.Instance); LaunchSite[] stockLaunchSites = (LaunchSite[])stockLaunchSitesField.GetValue(PSystemSetup.Instance); LaunchSite[] updateStockLaunchSites = stockLaunchSites.Where(site => !Templates.RemoveLaunchSites.Contains(site.name)).ToArray(); if (stockLaunchSites.Length != updateStockLaunchSites.Length) { stockLaunchSitesField.SetValue(PSystemSetup.Instance, updateStockLaunchSites); } } catch (Exception ex) { Logger.Default.Log("Failed to remove launch sites from 'stockLaunchSites' field. Exception information follows."); Logger.Default.LogException(ex); } } #endif #if FALSE // AFG-Ception foreach (CelestialBody body in PSystemManager.Instance.localBodies) { if (body.afg == null) { continue; } foreach (KopernicusStar s in KopernicusStar.Stars) { AtmosphereFromGround afg; if (s != Sun.Instance) { afg = Instantiate(body.afg.gameObject) .GetComponent <AtmosphereFromGround>(); Utility.CopyObjectFields(body.afg, afg, false); afg.transform.parent = body.afg.transform.parent; afg.transform.localPosition = body.afg.transform.localPosition; afg.transform.localScale = body.afg.transform.localScale; afg.transform.localRotation = body.afg.transform.localRotation; afg.gameObject.layer = body.afg.gameObject.layer; } else { afg = body.afg; } afg.gameObject.AddComponent <KopernicusStarAFG>().Star = s; } } #endif }
public override bool RequirementMet(ConfiguredContract contract) { return(ExpansionsLoader.IsExpansionInstalled(expansion.ToString())); }