Skip to content

Commit

Permalink
Fuse principia + stock maneuver node execution behavior
Browse files Browse the repository at this point in the history
Yep I'm actually doing DRY

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Oct 28, 2023
1 parent 6cc7fd1 commit 04245a9
Showing 1 changed file with 36 additions and 59 deletions.
95 changes: 36 additions & 59 deletions MechJeb2/MechJebModuleNodeExecutor.cs
Expand Up @@ -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()
Expand Down

0 comments on commit 04245a9

Please sign in to comment.