Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion MechJeb2/MechJebModuleSmartASS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public enum Target
private AttitudeReference targetReference = AttitudeReference.ORBIT;

private static readonly double LARGE_INCREMENT = 10.0;

private int lastNodeCount = 0;
// Current attitude/direction (for smooth interpolation)
private Vector3d curDirection = Vector3d.zero;
private Quaternion curAttitude = Quaternion.identity;
Expand Down Expand Up @@ -224,6 +224,24 @@ public override void OnLoad(ConfigNode local, ConfigNode type, ConfigNode global
Engage(false);
}

public override void Drive(FlightCtrlState s)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be in Drive() as opposed to OnFixedUpdate() later in the code?

If it does, it is probably worth a short comment on why. It is mostly just touching internal state and not the flight controls (which is what is in my mental model of why you need to use Drive(), but the details on that kinda paged out of my brain a few years ago).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this in Drive() so the check only runs when SmartASS is active. Switching to OnFixedUpdate() would require more checks to make sure the module is active (and also to prevent edge cases where it switched to KILLROT even when the module isn't active)
I can change the code to use OnFixedUpdate if you prefer.

{
base.Drive(s);

int currentNodeCount = Part.vessel.patchedConicSolver.maneuverNodes.Count;

if (target == Target.NODE)
{
if (lastNodeCount > 0 && currentNodeCount == 0)
{
target = Target.KILLROT;
Engage();
}
}

lastNodeCount = currentNodeCount;
}

protected override void WindowGUI(int windowID)
{
bool hasSmoothControl = false; // Local variable for current frame
Expand Down