/// <summary> /// After a decouple or part explosion, it's possible for this vessel to /// still have an assigned flight control parameter that is coming from /// a kOS core that is no longer on this vessel but is instead on the newly /// branched vessel we left behind. If so, that parameter needs to be /// removed from this vessel. The new kOSVesselModule will take care of /// making a new parameter on the new vessel, but this kOSVesselModule needs /// to detach it from this one. /// </summary> private void ResetPhysicallyDetachedParameters() { List <string> removeKeys = new List <string>(); foreach (string key in flightControlParameters.Keys) { IFlightControlParameter p = flightControlParameters[key]; if (p.GetShared() != null && p.GetShared().Vessel != null && Vessel != null && p.GetShared().Vessel.id != Vessel.id) { removeKeys.Add(key); } } foreach (string key in removeKeys) { SafeHouse.Logger.SuperVerbose(string.Format( "kOSVesselModule: re-defaulting parameter \"{0}\" because it's on a detached part of the vessel.", key)); RemoveFlightControlParameter(key); IFlightControlParameter p = null; if (key.Equals("steering")) { p = new SteeringManager(Vessel); } else if (key.Equals("throttle")) { p = new ThrottleManager(Vessel); } else if (key.Equals("wheelsteering")) { p = new WheelSteeringManager(Vessel); } else if (key.Equals("wheelthrottle")) { p = new WheelThrottleManager(Vessel); } else if (key.Equals("flightcontrol")) { p = new FlightControl(Vessel); } if (p != null) { AddFlightControlParameter(key, p); } } foundWrongVesselAutopilot = false; }
/// <summary> /// Generates a list of all processorModules included on the parentVessel. /// </summary> private void HarvestParts() { var proccessorModules = parentVessel.FindPartModulesImplementing <kOSProcessor>(); foreach (var proc in proccessorModules) { childParts.Add(proc.part.flightID); uint id = proc.part.flightID; if (partLookup.ContainsKey(id) && partLookup[id].ID != ID) { // If the part is already known and not associated with this module, then // it is appearing as a result of a staging or undocking event (or something // similar). As such, we need to copy the information from the flight parameters // on the originating module. foreach (string key in flightControlParameters.Keys) { if (partLookup[id].HasFlightControlParameter(key)) { // Only copy the data if the previous vessel module still has the parameter. IFlightControlParameter paramDestination = flightControlParameters[key]; IFlightControlParameter paramOrigin = partLookup[id].GetFlightControlParameter(key); // We only want to copy the parameters themselves once (because they are vessel dependent // not part dependent) but we still need to iterate through each part since "control" // itself is part dependent. if (partLookup[id].ID != BaseId) { paramDestination.CopyFrom(paramOrigin); } if (paramOrigin.Enabled && paramOrigin.ControlPartId == id) { // If this parameter was previously controlled by this part, re-enable // control, copy it's Value setpoint, and disable control on the old parameter. SharedObjects shared = paramOrigin.GetShared(); paramDestination.EnableControl(shared); paramDestination.UpdateValue(paramOrigin.GetValue(), shared); paramOrigin.DisableControl(); } } } baseId = partLookup[id].ID; // Keep track of which vessel the parameters are based on. } partLookup[id] = this; } partCount = parentVessel.Parts.Count; }