Skip to content

Commit

Permalink
Fix PVG without delta-V window open
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 May 10, 2023
1 parent d89220e commit 8775cca
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
11 changes: 7 additions & 4 deletions MechJeb2/MechJebModuleAscentBaseAutopilot.cs
Expand Up @@ -12,7 +12,7 @@ public abstract class MechJebModuleAscentBaseAutopilot : ComputerModule
public string Status = "";

protected MechJebModuleAscentSettings AscentSettings => core.ascentSettings;

public bool TimedLaunch;
private double _launchTime;

Expand Down Expand Up @@ -93,6 +93,9 @@ public void StartCountdown(double time)

public override void OnFixedUpdate()
{
if (AscentSettings.AscentType == AscentType.PVG)
core.stageStats.RequestUpdate(this);

FixupLaunchStart();
if (TimedLaunch)
{
Expand Down Expand Up @@ -277,8 +280,8 @@ protected virtual void TimedLaunchHook()
{
// triggered when timed launches start the actual launch
}


//data used by ThrottleToRaiseApoapsis
private float _raiseApoapsisLastThrottle;
private double _raiseApoapsisLastApR;
Expand Down Expand Up @@ -362,7 +365,7 @@ protected void AttitudeTo(double desiredPitch, double desiredHeading)
+ Math.Sin(desiredPitch * UtilMath.Deg2Rad) * vesselState.up;

desiredThrustVector = desiredThrustVector.normalized;

/* old style AoA limiter */
if (AscentSettings.LimitAoA && !AscentSettings.LimitQaEnabled)
{
Expand Down
1 change: 1 addition & 0 deletions MechJeb2/MechJebModuleAscentMenu.cs
Expand Up @@ -412,6 +412,7 @@ protected override void WindowGUI(int windowID)

if (_ascentSettings.AscentType == AscentType.PVG)
{
core.stageStats.RequestUpdate(this);
GUILayout.BeginVertical(GUI.skin.box);
_pvgSettingsMenu.enabled = GUILayout.Toggle(_pvgSettingsMenu.enabled, "Edit Rocket Staging");
GUILayout.EndVertical();
Expand Down
53 changes: 29 additions & 24 deletions MechJeb2/MechJebModuleAscentPVGSettingsMenu.cs
Expand Up @@ -44,44 +44,49 @@ private void SetupButtonStyles()
protected override void WindowGUI(int windowID)
{
SetupButtonStyles();
GUILayout.BeginVertical(GUI.skin.box);

int topstage = -1;

_ascentSettings.LastStage.val = Clamp(_ascentSettings.LastStage.val, 0, core.stageStats.vacStats.Length - 1);

for (int i = _ascentSettings.LastStage; i < core.stageStats.vacStats.Length; i++)
if ( _ascentSettings.LastStage < core.stageStats.vacStats.Length && core.stageStats.vacStats.Length > 0)
{
FuelFlowSimulation.FuelStats stats = core.stageStats.vacStats[i];
if (stats.DeltaV < _ascentSettings.MinDeltaV.val)
continue;

if (topstage < 0)
topstage = i;

GUILayout.BeginHorizontal();
GUILayout.Label($"{i,3} {stats.DeltaV:##,###0} m/s");
if (_ascentSettings.UnguidedStages.Contains(i))
GUILayout.Label(" (unguided)");
if (_ascentSettings.OptimizeStage == i)
GUILayout.Label(" (optimize)");
GUILayout.EndHorizontal();
}
GUILayout.BeginVertical(GUI.skin.box);

GUILayout.EndVertical();

_ascentSettings.LastStage.val = Clamp(_ascentSettings.LastStage.val, 0, core.stageStats.vacStats.Length - 1);

for (int i = _ascentSettings.LastStage; i < core.stageStats.vacStats.Length; i++)
{
FuelFlowSimulation.FuelStats stats = core.stageStats.vacStats[i];
if (stats.DeltaV < _ascentSettings.MinDeltaV.val)
continue;

if (topstage < 0)
topstage = i;

GUILayout.BeginHorizontal();
GUILayout.Label($"{i,3} {stats.DeltaV:##,###0} m/s");
if (_ascentSettings.UnguidedStages.Contains(i))
GUILayout.Label(" (unguided)");
if (_ascentSettings.OptimizeStage == i)
GUILayout.Label(" (optimize)");
GUILayout.EndHorizontal();
}

GUILayout.EndVertical();
}

// this should only run once -- maybe it should run in some hook like scene loading or something?
// we need DV info though.
if (_ascentSettings.OptimizeStageInternal < 0)
_ascentSettings.OptimizeStageInternal.val = topstage;

GUILayout.BeginVertical(GUI.skin.box);
GuiUtils.SimpleTextBox("Min ∆v: ", _ascentSettings.MinDeltaV, "m/s", 30);
GuiUtils.SimpleTextBox("Last Stage: ", _ascentSettings.LastStage);
GuiUtils.ToggledTextBox(ref _ascentSettings.OptimizeStageFlag, "Optimize Stage: ", _ascentSettings.OptimizeStageInternal);
GuiUtils.ToggledTextBox(ref _ascentSettings.UnguidedStagesFlag, "Unguided Stages: ", _ascentSettings.UnguidedStagesInternal);
GUILayout.EndVertical();

GUILayout.BeginVertical(GUI.skin.box);
//_ascentSettings.ExtendIfRequired = GUILayout.Toggle(_ascentSettings.ExtendIfRequired, "Extend if Required");
GuiUtils.ToggledTextBox(ref _ascentSettings.CoastStageFlag, "Coast Stage: ", _ascentSettings.CoastStageInternal);
Expand All @@ -93,15 +98,15 @@ protected override void WindowGUI(int windowID)
GuiUtils.ToggledTextBox(ref _ascentSettings.FixedCoast, "Fixed Coast Length:", _ascentSettings.FixedCoastLength, "s", width: 40);
GuiUtils.SimpleTextBox("Ullage lead time: ", core.guidance.UllageLeadTime, "s", 60);
GUILayout.EndVertical();

GUILayout.BeginVertical(GUI.skin.box);
GUILayout.BeginHorizontal();
GuiUtils.ToggledTextBox(ref _ascentSettings.SpinupStageFlag, "Spinup stage: ", _ascentSettings.SpinupStageInternal, width: 30);
GuiUtils.SimpleTextBox("ω: ", _ascentSettings.SpinupAngularVelocity, "rpm", 30);
GUILayout.EndHorizontal();
GuiUtils.SimpleTextBox("Spinup lead time: ", _ascentSettings.SpinupLeadTime, "s", 60);
GUILayout.EndVertical();

GUILayout.BeginVertical(GUI.skin.box);
GuiUtils.SimpleTextBox(CachedLocalizer.Instance.MechJeb_Ascent_label13, _ascentSettings.PitchStartVelocity, "m/s",
40); //Booster Pitch start:
Expand Down
5 changes: 5 additions & 0 deletions MechJeb2/MechJebModulePVGGlueBall.cs
Expand Up @@ -52,6 +52,11 @@ public override void OnModuleDisabled()
{
}

public override void OnFixedUpdate()
{
core.stageStats.RequestUpdate(this);
}

public override void OnStart(PartModule.StartState state)
{
GameEvents.onStageActivate.Add(HandleStageEvent);
Expand Down

0 comments on commit 8775cca

Please sign in to comment.