/// <summary> /// Checks whether StageRecovery should recover the vessel /// </summary> /// <param name="vessel">The vessel to check</param> /// <returns>True if SR should handle it, false otherwise</returns> private static bool SRShouldRecover(Vessel vessel) { //Check if the stage was claimed by another mod string controllingMod = RecoveryControllerWrapper.ControllingMod(vessel); Log.Info("[SR] Controlling mod is " + (controllingMod ?? "null")); if (HighLogic.LoadedSceneIsFlight) //outside of the flight scene we're gonna handle everything { if (string.IsNullOrEmpty(controllingMod) || string.Equals(controllingMod, "auto", StringComparison.OrdinalIgnoreCase)) { if (FMRS_Enabled(false)) { //FMRS is installed and is active, but we aren't sure if they're handling chutes yet Log.Info("[SR] FMRS is active..."); if (!FMRS_Enabled(true)) { //FMRS is active, but isn't handling parachutes or deferred it to us. So if there isn't crew or a form of control, then we handle it Log.Info("[SR] But FMRS isn't handling chutes..."); if ((vessel.protoVessel.wasControllable) || vessel.protoVessel.GetVesselCrew().Count > 0) { //crewed or was controlled, so FMRS will get it Log.Info("[SR] But this stage has control/kerbals, so have fun FMRS!"); return(false); } Log.Info("[SR] So we've got this stage! Maybe next time FMRS."); // if we've gotten here, FMRS probably isn't handling the craft and we should instead. } else { //FRMS is active, is handling chutes, and hasn't deferred it to us. We aren't gonna handle this case at all Log.Info("[SR] And FMRS is handling everything, have fun!"); return(false); } } else { Log.Info("[SR] FMRS is not active."); } } else if (string.Equals(controllingMod, "StageRecovery", StringComparison.OrdinalIgnoreCase)) { Log.Info("[SR] Vessel specified StageRecovery as its processor."); return(true); } else //another mod has requested full control over recovery of the vessel { Log.Info($"[SR] Vessel specified '{controllingMod}' as its processor."); return(false); } } return(true); }
//Fired when the mod loads each scene public void Start() { Log.Info("[SR] Start start"); if (Settings.Instance != null) { Settings.Instance.gui.hideAll(); } //If we're in the MainMenu, don't do anything if (forbiddenScenes.Contains(HighLogic.LoadedScene)) { return; } Settings.Instance.gui.InitializeToolbar(this.gameObject); //If the event hasn't been added yet, run this code (adds the event and the stock button) //if (!eventAdded) { GameEvents.onGameSceneLoadRequested.Add(GameSceneLoadEvent); //Add the VesselDestroyEvent to the listeners //GameEvents.onVesselDestroy.Add(VesselDestroyEvent); GameEvents.onVesselWillDestroy.Add(VesselDestroyEvent); //Add the event that listens for unloads (for removing launch clamps) GameEvents.onVesselGoOnRails.Add(VesselUnloadEvent); //GameEvents..Add(DecoupleEvent); GameEvents.OnGameSettingsApplied.Add(GameSettingsAppliedEvent); GameEvents.onVesselRecovered.Add(onVesselRecovered); GameEvents.onVesselTerminated.Add(onVesselTerminated); cutoffAlt = ComputeCutoffAlt(Planetarium.fetch.Home) + 1000; Log.Info("[SR] Determined cutoff altitude to be " + cutoffAlt); //Register with the RecoveryController (do we only do this once?) var s = RecoveryControllerWrapper.RegisterModWithRecoveryController("StageRecovery"); Log.Info("[SR] RecoveryController registration success: " + s); //Set the eventAdded flag to true so this code doesn't run again //eventAdded = true; //Confine the RecoveryModifier to be between 0 and 1 Settings2.Instance.RecoveryModifier = (Settings2.Instance.RecoveryModifier < 0) ? 0 : (Settings2.Instance.RecoveryModifier > 1) ? 1 : Settings2.Instance.RecoveryModifier; //Load and resave the BlackList. The save ensures that the file will be created if it doesn't exist. Settings.Instance.BlackList.Load(); Settings.Instance.BlackList.Save(); } if (!HighLogic.LoadedSceneIsFlight) { Settings.Instance.ClearStageLists(); } if (HighLogic.LoadedSceneIsFlight) { foreach (Vessel v in FlightGlobals.Vessels) { TryWatchVessel(v); } } if (HighLogic.LoadedSceneIsEditor) { GameEvents.onEditorShipModified.Add(ShipModifiedEvent); } //Remove anything that happens in the future List <Guid> removeList = new List <Guid>(); double currentUT = Planetarium.GetUniversalTime(); foreach (KeyValuePair <Guid, double> logItem in RecoverAttemptLog) { if (logItem.Value >= currentUT) { removeList.Add(logItem.Key); } } foreach (Guid removeItem in removeList) { RecoverAttemptLog.Remove(removeItem); } //end future removal sceneChangeComplete = true; }
//Fired when the mod loads each scene public void Start() { Debug.Log("[SR] Start start"); if (Settings.Instance != null) { Settings.Instance.gui.hideAll(); } //If we're in the MainMenu, don't do anything if (forbiddenScenes.Contains(HighLogic.LoadedScene)) { return; } //If the event hasn't been added yet, run this code (adds the event and the stock button) if (!eventAdded) { GameEvents.onGameSceneLoadRequested.Add(GameSceneLoadEvent); //Add the VesselDestroyEvent to the listeners //GameEvents.onVesselDestroy.Add(VesselDestroyEvent); GameEvents.onVesselWillDestroy.Add(VesselDestroyEvent); //Add the event that listens for unloads (for removing launch clamps) GameEvents.onVesselGoOnRails.Add(VesselUnloadEvent); //GameEvents..Add(DecoupleEvent); //If Blizzy's toolbar isn't available, use the stock one //if (!ToolbarManager.ToolbarAvailable) GameEvents.onGUIApplicationLauncherReady.Add(Settings.Instance.gui.OnGUIAppLauncherReady); cutoffAlt = ComputeCutoffAlt(Planetarium.fetch.Home) + 1000; Debug.Log("[SR] Determined cutoff altitude to be " + cutoffAlt); //Register with the RecoveryController (do we only do this once?) Debug.Log("[SR] RecoveryController registration success: " + RecoveryControllerWrapper.RegisterMod("StageRecovery")); //Set the eventAdded flag to true so this code doesn't run again eventAdded = true; } //Load the settings from file Settings.Instance.Load(); //Confine the RecoveryModifier to be between 0 and 1 if (Settings.Instance.RecoveryModifier > 1) { Settings.Instance.RecoveryModifier = 1; } if (Settings.Instance.RecoveryModifier < 0) { Settings.Instance.RecoveryModifier = 0; } //Save the settings file (in case it doesn't exist yet). I suppose this is somewhat unnecessary if the file exists Settings.Instance.Save(); //Load and resave the BlackList. The save ensures that the file will be created if it doesn't exist. Settings.Instance.BlackList.Load(); Settings.Instance.BlackList.Save(); if (!HighLogic.LoadedSceneIsFlight) { Settings.Instance.ClearStageLists(); } if (HighLogic.LoadedSceneIsFlight) { foreach (Vessel v in FlightGlobals.Vessels) { TryWatchVessel(v); } } //Remove anything that happens in the future List <Guid> removeList = new List <Guid>(); double currentUT = Planetarium.GetUniversalTime(); foreach (KeyValuePair <Guid, double> logItem in RecoverAttemptLog) { if (logItem.Value >= currentUT) { removeList.Add(logItem.Key); } } foreach (Guid removeItem in removeList) { RecoverAttemptLog.Remove(removeItem); } //end future removal sceneChangeComplete = true; }