Skip to content

Commit

Permalink
Splitup burnout altitude setting
Browse files Browse the repository at this point in the history
Have one setting for optimized stages and one for fixed burntime
so flipping between them isn't so weird.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Jun 17, 2023
1 parent e6eabea commit 333e5d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions MechJeb2/MechJebModuleAscentMenu.cs
Expand Up @@ -131,17 +131,17 @@ private void ShowTargetingGUIElements()
GuiUtils.SimpleTextBox(CachedLocalizer.Instance.MechJeb_Ascent_label1, _ascentSettings.DesiredOrbitAltitude,
"km"); //Target Periapsis
GuiUtils.SimpleTextBox(CachedLocalizer.Instance.MechJeb_Ascent_label2, _ascentSettings.DesiredApoapsis, "km"); //Target Apoapsis:
GuiUtils.ToggledTextBox(ref _ascentSettings.AttachAltFlag, CachedLocalizer.Instance.MechJeb_Ascent_attachAlt,
_ascentSettings.DesiredAttachAlt, "km");
}
else
{
if (!_launchingWithAnyPlaneControl)
GuiUtils.SimpleTextBox("Flight Path Angle", _ascentSettings.DesiredFPA, "°");
_ascentSettings.AttachAltFlag = true;
GuiUtils.SimpleTextBox(CachedLocalizer.Instance.MechJeb_Ascent_attachAlt,
_ascentSettings.DesiredAttachAltFixed, "km");
}

GuiUtils.ToggledTextBox(ref _ascentSettings.AttachAltFlag, CachedLocalizer.Instance.MechJeb_Ascent_attachAlt,
_ascentSettings.DesiredAttachAlt, "km");

if (_ascentSettings.DesiredApoapsis >= 0 && _ascentSettings.DesiredApoapsis < _ascentSettings.DesiredOrbitAltitude)
GUILayout.Label(CachedLocalizer.Instance.MechJeb_Ascent_label3, GuiUtils.yellowLabel); //Ap < Pe: circularizing orbit
else if (_ascentSettings.AttachAltFlag && _ascentSettings.DesiredAttachAlt > _ascentSettings.DesiredApoapsis)
Expand Down
6 changes: 4 additions & 2 deletions MechJeb2/MechJebModuleAscentPVGAutopilot.cs
Expand Up @@ -81,22 +81,24 @@ private void SetTarget()
double apR = mainBody.Radius + AscentSettings.DesiredApoapsis;
if (_ascentSettings.DesiredApoapsis < 0)
apR = _ascentSettings.DesiredApoapsis;
double attR = mainBody.Radius + AscentSettings.DesiredAttachAlt;
double attR = mainBody.Radius +
(AscentSettings.OptimizeStage < 0 ? AscentSettings.DesiredAttachAltFixed : AscentSettings.DesiredAttachAlt);

bool lanflag = _ascentSettings.LaunchingToPlane || _ascentSettings.LaunchingToMatchLan || _ascentSettings.LaunchingToLan;
double lan = _ascentSettings.LaunchingToPlane || _ascentSettings.LaunchingToMatchLan
? core.target.TargetOrbit.LAN
: (double)AscentSettings.DesiredLan;

double inclination = AscentSettings.DesiredInclination;
bool attachAltFlag = AscentSettings.OptimizeStage < 0 || AscentSettings.AttachAltFlag;

// if we are launchingToPlane other code in MJ fixes the sign of the inclination to be correct
// FIXME: can we just use autopilot.desiredInclination here and rely on the other code to update that value?
if (_ascentSettings.LaunchingToPlane)
inclination = Math.Sign(inclination) * core.target.TargetOrbit.inclination;

// FIXME: kinda need to break this up it is getting very magical with all the non-obvious ignored combinations of options
core.glueball.SetTarget(peR, apR, attR, inclination, lan, AscentSettings.DesiredFPA, AscentSettings.AttachAltFlag, lanflag);
core.glueball.SetTarget(peR, apR, attR, inclination, lan, AscentSettings.DesiredFPA, attachAltFlag, lanflag);
}

private double _pitchStartTime;
Expand Down
4 changes: 4 additions & 0 deletions MechJeb2/MechJebModuleAscentSettings.cs
Expand Up @@ -26,6 +26,9 @@ public MechJebModuleAscentSettings(MechJebCore core) : base(core)
[Persistent(pass = (int)(Pass.Type | Pass.Global))]
public readonly EditableDoubleMult DesiredAttachAlt = new EditableDoubleMult(DESIRED_ATTACH_ALT_DEFAULT, 1000);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
public readonly EditableDoubleMult DesiredAttachAltFixed = new EditableDoubleMult(DESIRED_ATTACH_ALT_DEFAULT, 1000);

[Persistent(pass = (int)(Pass.Type | Pass.Global))]
public readonly EditableDoubleMult DesiredFPA = new EditableDoubleMult(DESIRED_FPA_DEFAULT, PI / 180);

Expand Down Expand Up @@ -311,6 +314,7 @@ public void ApplyRODefaults()
PitchStartVelocity.val = PITCH_START_VELOCITY_DEFAULT;
PitchRate.val = PITCH_RATE_DEFAULT;
DesiredAttachAlt.val = DESIRED_ATTACH_ALT_DEFAULT;
DesiredAttachAltFixed.val = DESIRED_ATTACH_ALT_DEFAULT;
DesiredFPA.val = DESIRED_FPA_DEFAULT;
DynamicPressureTrigger.val = DYNAMIC_PRESSURE_TRIGGER_DEFAULT;
AttachAltFlag = ATTACH_ALT_FLAG_DEFAULT;
Expand Down

0 comments on commit 333e5d5

Please sign in to comment.