diff --git a/MechJeb2/MechJebModuleNodeExecutor.cs b/MechJeb2/MechJebModuleNodeExecutor.cs index 5adce55e..bbc78a50 100644 --- a/MechJeb2/MechJebModuleNodeExecutor.cs +++ b/MechJeb2/MechJebModuleNodeExecutor.cs @@ -139,82 +139,59 @@ public override void OnFixedUpdate() return; } - if (_isLoadedPrincipia && _mode == Mode.ONE_PNODE) - { - ManeuverNode node = _hasNodes ? Vessel.patchedConicSolver.maneuverNodes[0] : null; - _direction = NextDirection(); - - if (_dvLeft < 0) - { - BurnTriggered = false; - - Abort(); - return; - } + ManeuverNode node = _hasNodes ? Vessel.patchedConicSolver.maneuverNodes[0] : null; - Core.Attitude.attitudeTo(Planetarium.fetch.rotation * _direction, AttitudeReference.INERTIAL_COT, this); + if (!_isLoadedPrincipia) + _dvLeft = node!.GetBurnVector(Orbit).magnitude; - double ignitionUT = CalculateIgnitionUT(node); + _direction = NextDirection(); - if (VesselState.time >= ignitionUT) - { - BurnTriggered = true; - if (!MuUtils.PhysicsRunning()) Core.Warp.MinimumWarp(); - } + if (ShouldTerminate(ref node)) + { + BurnTriggered = false; + Abort(); + return; + } - HandleAutowarp(ignitionUT); + Core.Attitude.attitudeTo(Planetarium.fetch.rotation * _direction, AttitudeReference.INERTIAL_COT, this); - HandleAligningAndThrust(); + double ignitionUT = CalculateIgnitionUT(node); - DecrementDvLeft(); - } - else if (_hasNodes) + if (VesselState.time >= ignitionUT) { - //check if we've finished a node: - ManeuverNode node = Vessel.patchedConicSolver.maneuverNodes[0]; - _dvLeft = node.GetBurnVector(Orbit).magnitude; - _direction = NextDirection(); - - if (BurnTriggered && AngleFromNode() >= 0.5 * PI) - { - BurnTriggered = false; + BurnTriggered = true; + if (!MuUtils.PhysicsRunning()) Core.Warp.MinimumWarp(); + } - node.RemoveSelf(); + HandleAutowarp(ignitionUT); - if (_mode == Mode.ONE_NODE) - { - Abort(); - return; - } + HandleAligningAndThrust(); - if (_mode == Mode.ALL_NODES) - { - if (Vessel.patchedConicSolver.maneuverNodes.Count == 0) - { - Abort(); - return; - } + DecrementDvLeft(); + } - node = Vessel.patchedConicSolver.maneuverNodes[0]; - } - } + private bool ShouldTerminate(ref ManeuverNode node) + { + if (_isLoadedPrincipia) + return _dvLeft < 0; - Core.Attitude.attitudeTo(Planetarium.fetch.rotation * _direction, AttitudeReference.INERTIAL_COT, this); + if (BurnTriggered && AngleFromNode() >= 0.5 * PI) + { + node.RemoveSelf(); - double ignitionUT = CalculateIgnitionUT(node); + if (_mode == Mode.ONE_NODE) + return true; - if (VesselState.time >= ignitionUT) + if (_mode == Mode.ALL_NODES) { - BurnTriggered = true; - if (!MuUtils.PhysicsRunning()) Core.Warp.MinimumWarp(); - } - - HandleAutowarp(ignitionUT); + if (Vessel.patchedConicSolver.maneuverNodes.Count == 0) + return true; - HandleAligningAndThrust(); - - DecrementDvLeft(); + node = Vessel.patchedConicSolver.maneuverNodes[0]; + } } + + return false; } private double AngleFromNode()