Skip to content
Closed
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
68 changes: 51 additions & 17 deletions MechJeb2/MechJebStageStatsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using KSP.Localization;
using UnityEngine;
Expand Down Expand Up @@ -60,7 +60,7 @@ public MechJebStageStatsHelper(MechJebModuleInfoItems items)
private enum StageData
{
KSPStage, InitialMass, FinalMass, StagedMass, BurnedMass, Thrust, VacInitialTWR, VacMaxTWR, AtmoInitialTWR, AtmoMaxTWR,
Isp, AtmoDeltaV, VacDeltaV, Time
Isp, AtmoDeltaV, VacDeltaV, Time, AtmoCumulativeDeltaV, VacCumulativeDeltaV
}

private static readonly List<StageData> AllStages = new List<StageData>
Expand All @@ -78,6 +78,8 @@ private enum StageData
StageData.Isp,
StageData.AtmoDeltaV,
StageData.VacDeltaV,
StageData.AtmoCumulativeDeltaV,
StageData.VacCumulativeDeltaV,
StageData.Time
};

Expand Down Expand Up @@ -126,8 +128,10 @@ private void InitalizeStageHeaderData()
stageHeaderData.Add(StageData.AtmoInitialTWR, CachedLocalizer.Instance.MechJebInfoItemsStatsColumn7 + SPACING);
stageHeaderData.Add(StageData.AtmoMaxTWR, CachedLocalizer.Instance.MechJebInfoItemsStatsColumn8 + SPACING);
stageHeaderData.Add(StageData.Isp, CachedLocalizer.Instance.MechJebInfoItemsStatsColumn9 + SPACING);
stageHeaderData.Add(StageData.AtmoDeltaV, (showRcs ? "RCS ∆Vmin" : CachedLocalizer.Instance.MechJebInfoItemsStatsColumn10) + SPACING);
stageHeaderData.Add(StageData.VacDeltaV, (showRcs ? "RCS ∆Vmax" : CachedLocalizer.Instance.MechJebInfoItemsStatsColumn11) + SPACING);
stageHeaderData.Add(StageData.AtmoDeltaV, CachedLocalizer.Instance.MechJebInfoItemsStatsColumn10 + SPACING);
stageHeaderData.Add(StageData.VacDeltaV, CachedLocalizer.Instance.MechJebInfoItemsStatsColumn11 + SPACING);
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.

This changes it though so that if you showRcs now you're not getting the correct column heading?

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.

I think you still probably need to fix this back?

stageHeaderData.Add(StageData.AtmoCumulativeDeltaV, "Σ ∆V Atmo" + SPACING);
stageHeaderData.Add(StageData.VacCumulativeDeltaV, "Σ ∆V Vac" + SPACING);
stageHeaderData.Add(StageData.Time, CachedLocalizer.Instance.MechJebInfoItemsStatsColumn12 + SPACING);
}

Expand Down Expand Up @@ -162,12 +166,34 @@ private double _atmoStartTWR(int index, double geeASL) =>
private double _atmoEndTWR(int index, double geeASL) =>
showRcs ? stats.AtmoStats[index].RcsMaxTWR(geeASL) : stats.AtmoStats[index].MaxTWR(geeASL);

private double CalculateCumulativeVacDeltaV(List<int> stages, int currentStageIndex)
{
var cumulative = 0.0;

for (int i = currentStageIndex; i < stages.Count; i++)
cumulative += _vacDv(stages[i]);

return cumulative;
}

private double CalculateCumulativeAtmoDeltaV(List<int> stages, int currentStageIndex)
{
var cumulative = 0.0;

for (int i = currentStageIndex; i < stages.Count; i++)
cumulative += _atmoDv(stages[i]);

return cumulative;
}

private void UpdateStageDisplayInfo(List<int> stages, double geeASL)
{
foreach (KeyValuePair<StageData, List<string>> kvp in stageDisplayInfo)
kvp.Value.Clear();
foreach (int index in stages)
{
var currentStageIndex = stages.IndexOf(index);

stageDisplayInfo[StageData.KSPStage].Add($"{stats.AtmoStats[index].KSPStage} ");
if (stageVisibility[StageData.InitialMass])
stageDisplayInfo[StageData.InitialMass].Add($"{stats.AtmoStats[index].StartMass:F3} t ");
Expand All @@ -186,6 +212,10 @@ private void UpdateStageDisplayInfo(List<int> stages, double geeASL)
if (stageVisibility[StageData.Isp]) stageDisplayInfo[StageData.Isp].Add($"{_isp(index):F2} ");
if (stageVisibility[StageData.AtmoDeltaV]) stageDisplayInfo[StageData.AtmoDeltaV].Add($"{_atmoDv(index):F0} m/s ");
if (stageVisibility[StageData.VacDeltaV]) stageDisplayInfo[StageData.VacDeltaV].Add($"{_vacDv(index):F0} m/s ");
if (stageVisibility[StageData.AtmoCumulativeDeltaV])
stageDisplayInfo[StageData.AtmoCumulativeDeltaV].Add($"{CalculateCumulativeAtmoDeltaV(stages, currentStageIndex):F0} m/s ");
if (stageVisibility[StageData.VacCumulativeDeltaV])
stageDisplayInfo[StageData.VacCumulativeDeltaV].Add($"{CalculateCumulativeVacDeltaV(stages, currentStageIndex):F0} m/s ");
if (stageVisibility[StageData.Time])
stageDisplayInfo[StageData.Time].Add(timeSeconds
? $"{_deltaTime(index):F2}s "
Expand Down Expand Up @@ -244,6 +274,8 @@ public void AllStageStats()
showRcs = !showRcs;
infoItems.showRcs = showRcs;
InitalizeStageHeaderData();

SetVisibility(StageDisplayState);
}

if (!HighLogic.LoadedSceneIsEditor)
Expand Down Expand Up @@ -339,19 +371,21 @@ private bool DrawStageStatsColumn(string header, in List<string> data)

private void LoadStageVisibility()
{
stageVisibility[StageData.StagedMass] = showStagedMass;
stageVisibility[StageData.BurnedMass] = showBurnedMass;
stageVisibility[StageData.InitialMass] = showInitialMass;
stageVisibility[StageData.FinalMass] = showFinalMass;
stageVisibility[StageData.Thrust] = showThrust;
stageVisibility[StageData.VacInitialTWR] = showVacInitialTWR;
stageVisibility[StageData.AtmoInitialTWR] = showAtmoInitialTWR;
stageVisibility[StageData.AtmoMaxTWR] = showAtmoMaxTWR;
stageVisibility[StageData.VacMaxTWR] = showVacMaxTWR;
stageVisibility[StageData.AtmoDeltaV] = showAtmoDeltaV;
stageVisibility[StageData.VacDeltaV] = showVacDeltaV;
stageVisibility[StageData.Time] = showTime;
stageVisibility[StageData.Isp] = showISP;
stageVisibility[StageData.StagedMass] = showStagedMass;
stageVisibility[StageData.BurnedMass] = showBurnedMass;
stageVisibility[StageData.InitialMass] = showInitialMass;
stageVisibility[StageData.FinalMass] = showFinalMass;
stageVisibility[StageData.Thrust] = showThrust;
stageVisibility[StageData.VacInitialTWR] = showVacInitialTWR;
stageVisibility[StageData.AtmoInitialTWR] = showAtmoInitialTWR;
stageVisibility[StageData.AtmoMaxTWR] = showAtmoMaxTWR;
stageVisibility[StageData.VacMaxTWR] = showVacMaxTWR;
stageVisibility[StageData.AtmoDeltaV] = showAtmoDeltaV;
stageVisibility[StageData.VacDeltaV] = showVacDeltaV;
stageVisibility[StageData.Time] = showTime;
stageVisibility[StageData.Isp] = showISP;
stageVisibility[StageData.AtmoCumulativeDeltaV] = showAtmoDeltaV;
stageVisibility[StageData.VacCumulativeDeltaV] = showVacDeltaV;
}

private void SaveStageVisibility()
Expand Down