Skip to content

Commit

Permalink
maybe fix principia node execution
Browse files Browse the repository at this point in the history
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Oct 28, 2023
1 parent c441e6b commit 0162ec3
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions MechJeb2/MechJebModuleNodeExecutor.cs
Expand Up @@ -62,15 +62,15 @@ public void ExecuteOneNode(object controller)
_mode = Mode.ONE_NODE;
Users.Add(controller);
BurnTriggered = false;
_dvLeft = 0;
_dvLeft = Vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(Orbit).magnitude;
}

public void ExecuteAllNodes(object controller)
{
_mode = Mode.ALL_NODES;
Users.Add(controller);
BurnTriggered = false;
_dvLeft = 0;
_dvLeft = Vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(Orbit).magnitude;
}

public void Abort()
Expand Down Expand Up @@ -99,9 +99,12 @@ private enum Mode { ONE_NODE, ALL_NODES }

private Mode _mode = Mode.ONE_NODE;

public bool BurnTriggered;
private double _dvLeft; // for Principia
private Vector3d _direction; // de-rotated world vector
public bool BurnTriggered;
public bool IsAligned;
private double _dvLeft; // for Principia
private Vector3d _direction; // de-rotated world vector
private static bool _isLoadedPrincipia => VesselState.isLoadedPrincipia;
private bool _hasNodes => Vessel.patchedConicSolver.maneuverNodes.Count > 0;

public override void Drive(FlightCtrlState s) => HandleUllage(s);

Expand All @@ -119,9 +122,6 @@ private void HandleUllage(FlightCtrlState s)
s.Z = -1.0F;
}

private static bool _isLoadedPrincipia => VesselState.isLoadedPrincipia;
private bool _hasNodes => Vessel.patchedConicSolver.maneuverNodes.Count > 0;

public override void OnFixedUpdate()
{
if (!Vessel.patchedConicsUnlocked() || (!_isLoadedPrincipia && !_hasNodes))
Expand All @@ -134,6 +134,8 @@ public override void OnFixedUpdate()

if (!_isLoadedPrincipia)
_dvLeft = node!.GetBurnVector(Orbit).magnitude;
else
DecrementDvLeft();

_direction = NextDirection();

Expand All @@ -157,8 +159,6 @@ public override void OnFixedUpdate()
HandleAutowarp(ignitionUT);

HandleAligningAndThrust();

DecrementDvLeft();
}

private bool ShouldTerminate(ref ManeuverNode node)
Expand Down Expand Up @@ -223,16 +223,14 @@ private double CalculateIgnitionUT(ManeuverNode node)

private void DecrementDvLeft()
{
if (!_isLoadedPrincipia) return;

if (!BurnTriggered || !MuUtils.PhysicsRunning()) return;

// decrement remaining dV based on engine and RCS thrust
// Since this is Principia, we can't rely on the node's delta V itself updating, we have to do it ourselves.
// We also can't just use vesselState.currentThrustAccel because only engines are counted.
// NOTE: This *will* include acceleration from decouplers, which is pretty cool.
Vector3d dV = (Vessel.acceleration_immediate - Vessel.graviticAcceleration) * TimeWarp.fixedDeltaTime;
_dvLeft -= Vector3d.Dot(dV, Core.Attitude.targetAttitude());
_dvLeft -= Vector3d.Dot(dV, _direction);
}

private void HandleAutowarp(double ignitionUT)
Expand Down

0 comments on commit 0162ec3

Please sign in to comment.