public void FixedUpdate() { //For each vessel in the watchlist, check to see if it reaches an atm density of 0.01 and if so, pre-recover it foreach (Guid id in new List <Guid>(StageWatchList)) { Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == id); if (vessel == null) { StageWatchList.Remove(id); continue; } if ((!vessel.loaded || vessel.packed) && vessel.altitude < cutoffAlt) { Debug.Log("[SR] Vessel " + vessel.vesselName + " (" + id + ") is about to be destroyed. Pre-recovering Kerbals."); RecoveryItem recItem = new RecoveryItem(vessel); //Pre-recover the Kerbals recItem.PreRecoverKerbals(); //Add the ship to the RecoveryQueue to be handled by the VesselDestroy event instance.RecoveryQueue.Add(recItem); // Debug.Log("[SR] Current RecoveryQueue size: " + instance.RecoveryQueue.Count); StageWatchList.Remove(id); } } }
public void FixedUpdate() { if (!sceneChangeComplete) { return; } //For each vessel in the watchlist, check to see if it reaches an atm density of 0.01 and if so, pre-recover it foreach (Guid id in new List <Guid>(StageWatchList)) { Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == id); if (vessel == null) { StageWatchList.Remove(id); continue; } if ((!vessel.loaded || vessel.packed) && vessel.mainBody == Planetarium.fetch.Home && vessel.altitude < cutoffAlt && vessel.altitude > 0) { if (!SRShouldRecover(vessel)) { StageWatchList.Remove(id); continue; } Debug.Log($"[SR] Vessel {vessel.vesselName} ({id}) is about to be destroyed at altitude {vessel.altitude}. Pre-recovering Kerbals."); RecoveryItem recItem = new RecoveryItem(vessel); //Pre-recover the Kerbals recItem.PreRecoverKerbals(); //Add the ship to the RecoveryQueue to be handled by the VesselDestroy event RecoveryQueue.Add(recItem); // Debug.Log("[SR] Current RecoveryQueue size: " + instance.RecoveryQueue.Count); StageWatchList.Remove(id); } } //foreach (RecoveryItem recItem in new List<RecoveryItem>(RecoveryQueue)) //Assignment validation is failing :( //{ // if (Planetarium.GetUniversalTime() - recItem.PreRecoveredTime > 10) //must be destroyed within 10 seconds? // { // recItem.ResetPreRecoveredKerbals(); // RecoveryQueue.Remove(recItem); // } //} }
public void VesselUnloadEvent(Vessel vessel) { //If we're disabled, just return if (!Settings.Instance.SREnabled) { return; } //If the vessel or the protovessel are null then we surely can't do anything with them if (vessel == null || vessel.protoVessel == null) { return; } ProtoVessel pv = vessel.protoVessel; //If we aren't supposed to recover clamps, then don't try. if (Settings.Instance.RecoverClamps) { //If we've already recovered the clamps, then no need to try again if (clampsRecovered.Find(a => a.id == vessel.id) != null) { return; } //Assign the pv variable to the protovessel, then look for if the root is a clamp if (pv.protoPartSnapshots.Count > 0 && pv.protoPartSnapshots[0].modules.Exists(m => m.moduleName == "LaunchClamp")) { //We look for the launchclamp module, which will hopefully cover FASA and stock. Debug.Log("[SR] Recovering a clamp!"); //Add it to the recovered clamps list so we don't try to recover it again clampsRecovered.Add(vessel); float totalRefund = 0; //Loop over all the parts and calculate their cost (we recover at 100% since we're at the launchpad/runway) foreach (ProtoPartSnapshot pps in pv.protoPartSnapshots) { float out1, out2; totalRefund += ShipConstruction.GetPartCosts(pps, pps.partInfo, out out1, out out2); } //Add dem funds to da total. Get dem funds! AddFunds(totalRefund); //Fire the successful recovery event. Even though this isn't a stage we still need to do this for things like KCT to recover the parts. //Can be averted with stock functions if I can get them working properly APIManager.instance.RecoverySuccessEvent.Fire(vessel, new float[] { 100, totalRefund, 0 }, "SUCCESS"); //And then we try a bunch of things to make sure the clamps are removed (remove it from the flight state, kill it, and destroy it) HighLogic.CurrentGame.flightState.protoVessels.Remove(pv); vessel.Die(); Destroy(vessel); //So, question for myself. Would it be better to try to manually fire the recovery events? Would that really be worth anything? } } //If it's a stage that will be destroyed, we need to manually recover the Kerbals if (Settings.Instance.RecoverKerbals && Settings.Instance.PreRecover && pv.GetVesselCrew().Count > 0) { //Check if the conditions for vessel destruction are met if (vessel != FlightGlobals.ActiveVessel && !vessel.isEVA && vessel.mainBody == Planetarium.fetch.Home && pv.situation != Vessel.Situations.LANDED && vessel.altitude < cutoffAlt && vessel.altitude > 0) //unloading in > 0.01 atm and not landed //pv.altitude < vessel.mainBody.atmosphereDepth { Debug.Log("[SR] Vessel " + pv.vesselName + " is going to be destroyed. Recovering Kerbals!"); //Kerbal death should be handled by SR instead RecoveryItem recItem = new RecoveryItem(vessel); //Pre-recover the Kerbals recItem.PreRecoverKerbals(); //Add the ship to the RecoveryQueue to be handled by the OnDestroy event instance.RecoveryQueue.Add(recItem); } else { WatchVessel(vessel); } } }