From 62f53641dcacadd8fc476d45f9979bc693eb2351 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 14 Aug 2023 13:19:34 -0700 Subject: [PATCH] Add option to override warp to plane Signed-off-by: Lamont Granquist --- MechJeb2/MechJebModuleAscentBaseAutopilot.cs | 25 +++++++++++--------- MechJeb2/MechJebModuleAscentMenu.cs | 2 ++ MechJeb2/MechJebModuleAscentSettings.cs | 6 ++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/MechJeb2/MechJebModuleAscentBaseAutopilot.cs b/MechJeb2/MechJebModuleAscentBaseAutopilot.cs index ca20016e9..1b527446e 100644 --- a/MechJeb2/MechJebModuleAscentBaseAutopilot.cs +++ b/MechJeb2/MechJebModuleAscentBaseAutopilot.cs @@ -86,9 +86,18 @@ protected override void OnModuleDisabled() public void StartCountdown(double time) { - TimedLaunch = true; - _launchTime = time; - _lastTMinus = 999; + if (AscentSettings.OverrideWarpToPlane) + { + TimedLaunch = false; + _launchTime = VesselState.time; + _lastTMinus = 0; + } + else + { + TimedLaunch = true; + _launchTime = time; + _lastTMinus = 999; + } } public override void OnFixedUpdate() @@ -320,15 +329,9 @@ protected float ThrottleToRaiseApoapsis(double currentApR, double finalApR) return desiredThrottle; } - protected double SrfvelPitch() - { - return 90.0 - Vector3d.Angle(VesselState.surfaceVelocity, VesselState.up); - } + protected double SrfvelPitch() => 90.0 - Vector3d.Angle(VesselState.surfaceVelocity, VesselState.up); - protected double SrfvelHeading() - { - return VesselState.HeadingFromDirection(VesselState.surfaceVelocity.ProjectOnPlane(VesselState.up)); - } + protected double SrfvelHeading() => VesselState.HeadingFromDirection(VesselState.surfaceVelocity.ProjectOnPlane(VesselState.up)); // this provides ground track heading based on desired inclination and is what most consumers should call protected void AttitudeTo(double desiredPitch) diff --git a/MechJeb2/MechJebModuleAscentMenu.cs b/MechJeb2/MechJebModuleAscentMenu.cs index ed7469c4e..a620bf8df 100644 --- a/MechJeb2/MechJebModuleAscentMenu.cs +++ b/MechJeb2/MechJebModuleAscentMenu.cs @@ -344,6 +344,8 @@ private void ShowAutoWarpGUIElements() _launchingToPlane = _launchingToRendezvous = _launchingToMatchLan = _launchingToLan = _autopilot.TimedLaunch = false; } + _ascentSettings.OverrideWarpToPlane = GUILayout.Toggle(_ascentSettings.OverrideWarpToPlane, "Override Warp to Plane"); + GUILayout.EndVertical(); Profiler.EndSample(); } diff --git a/MechJeb2/MechJebModuleAscentSettings.cs b/MechJeb2/MechJebModuleAscentSettings.cs index 89c21b6f3..bfdb47aad 100644 --- a/MechJeb2/MechJebModuleAscentSettings.cs +++ b/MechJeb2/MechJebModuleAscentSettings.cs @@ -275,6 +275,7 @@ public bool Autostage public bool LaunchingToRendezvous; public bool LaunchingToMatchLan; public bool LaunchingToLan; + public bool OverrideWarpToPlane; /* * Helpers for dealing with switching between modules @@ -304,10 +305,7 @@ private void DisableAscentModules() GetAscentModule(type).Enabled = false; } - public override void OnFixedUpdate() - { - DisableAscentModules(); - } + public override void OnFixedUpdate() => DisableAscentModules(); public void ApplyRODefaults() {