/// <summary> /// Here we copy the flight state we received and apply to the specific vessel. /// This method is called by ksp as it's a delegate. It's called on every FixedUpdate /// </summary> private void LunaOnVesselFlyByWire(Guid id, FlightCtrlState st) { if (!Enabled || !FlightStateSystemReady) { return; } if (CurrentFlightState.TryGetValue(id, out var value)) { if (VesselCommon.IsSpectating) { st.CopyFrom(value.GetInterpolatedValue()); } else { //If we are close to a vessel and we both are in space don't copy the //input controls as then the vessel jitters, specially if the other player has SAS on if (FlightGlobals.ActiveVessel && FlightGlobals.ActiveVessel.situation > Vessel.Situations.FLYING) { var interpolatedState = value.GetInterpolatedValue(); st.mainThrottle = interpolatedState.mainThrottle; st.gearDown = interpolatedState.gearDown; st.gearUp = interpolatedState.gearUp; st.headlight = interpolatedState.headlight; st.killRot = interpolatedState.killRot; } else { st.CopyFrom(value.GetInterpolatedValue()); } } } }
/// <summary> /// Removes the vessel from the dictionaries /// </summary> public void RemoveVessel(Guid vesselId) { FlyByWireDictionary.TryRemove(vesselId, out _); CurrentFlightState.TryRemove(vesselId, out _); TargetFlightStateQueue.TryRemove(vesselId, out _); var vessel = FlightGlobals.FindVessel(vesselId); if (vessel != null) { TryRemoveCallback(vessel); } }
/// <summary> /// Removes the vessel from the dictionaries /// </summary> public void RemoveVessel(Vessel vesselToRemove) { if (vesselToRemove == null) { return; } TryRemoveCallback(vesselToRemove); FlyByWireDictionary.TryRemove(vesselToRemove.id, out _); CurrentFlightState.TryRemove(vesselToRemove.id, out _); TargetFlightStateQueue.TryRemove(vesselToRemove.id, out _); }
/// <summary> /// Clear the delegates and the dictionaries /// </summary> public void ClearSystem() { foreach (var keyVal in FlyByWireDictionary) { var vessel = FlightGlobals.FindVessel(keyVal.Key); if (vessel != null) { try { vessel.OnFlyByWire -= FlyByWireDictionary[keyVal.Key]; } catch (Exception) { // ignored } } } FlyByWireDictionary.Clear(); CurrentFlightState.Clear(); TargetFlightStateQueue.Clear(); }