Skip to content

Commit

Permalink
Add one-time reminder about ignition dyn pressure penalties
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Nov 5, 2023
1 parent b906404 commit 9e7bdd8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
31 changes: 28 additions & 3 deletions TestFlightFailure_IgnitionFail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class TestFlightFailure_IgnitionFail : TestFlightFailure_Engine

private readonly Dictionary<uint, EngineRunData> engineRunData = new Dictionary<uint, EngineRunData>(8);

private static bool dynPressureReminderShown;
private bool preLaunchFailures;
private bool dynPressurePenalties;
private bool verboseDebugging;
Expand Down Expand Up @@ -126,8 +127,16 @@ public override void OnStart(StartState state)
{
base.OnStart(state);
verboseDebugging = core.DebugEnabled;
preLaunchFailures = HighLogic.CurrentGame.Parameters.CustomParams<TestFlightGameSettings>().preLaunchFailures;
dynPressurePenalties = HighLogic.CurrentGame.Parameters.CustomParams<TestFlightGameSettings>().dynPressurePenalties;
TestFlightGameSettings tfSettings = HighLogic.CurrentGame.Parameters.CustomParams<TestFlightGameSettings>();
preLaunchFailures = tfSettings.preLaunchFailures;
dynPressurePenalties = tfSettings.dynPressurePenalties;

// Nothing gets saved in simulations. Use static fields to pass the information over to the editor scene where it gets correctly persisted.
if (dynPressureReminderShown)
{
tfSettings.dynPressurePenaltyReminderShown = true;
}
dynPressureReminderShown |= tfSettings.dynPressurePenaltyReminderShown;
}

public override void OnLoad(ConfigNode node)
Expand Down Expand Up @@ -297,7 +306,23 @@ public override void DoFailure()

if (multiplier < 0.99)
{
FlightLogger.eventLog.Add($"[{met}] {core.Title} failed: Ignition Failure. {(float)(part.dynamicPressurekPa * 1000d)}Pa dynamic pressure caused a {(1f-multiplier) * 100f:0.#}% reduction in normal ignition reliability.");
string sPenaltyPercent = $"{(1f - multiplier) * 100f:0.#}%";
FlightLogger.eventLog.Add($"[{met}] {core.Title} failed: Ignition Failure. {(float)(part.dynamicPressurekPa * 1000d)}Pa dynamic pressure caused a {sPenaltyPercent} reduction in normal ignition reliability.");

if (!dynPressureReminderShown && multiplier < 0.95)
{
string msg = $"High dynamic pressure caused a {sPenaltyPercent} reduction in normal ignition reliability. Consider lighting the engine on the ground or higher up in the atmosphere.\nThese penalties are listed in both the flight log (F3) and in the Part Action Window.";
PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
"IgnitionDynPressurePenaltyTip",
"Ignition Failure",
msg,
"OK",
false,
HighLogic.UISkin);
TestFlightGameSettings tfSettings = HighLogic.CurrentGame.Parameters.CustomParams<TestFlightGameSettings>();
tfSettings.dynPressurePenaltyReminderShown = dynPressureReminderShown = true;
}
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions TestFlightSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class TestFlightGameSettings : GameParameters.CustomParameterNode
[GameParameters.CustomParameterUI("Ignition Chance Penalty For High Dynamic Pressure", toolTip = "Whether engine ignition chance will suffer a penalty based on dynamic pressure.")]
public bool dynPressurePenalties = true;

// The following values are persisted to the savegame but are not shown in the difficulty settings UI
public bool dynPressurePenaltyReminderShown = false;

public override void SetDifficultyPreset(GameParameters.Preset preset)
{
switch (preset)
Expand Down

0 comments on commit 9e7bdd8

Please sign in to comment.