Skip to content

Commit 5dc01ad

Browse files
authored
Award DU upon engine ignition (#285)
* Successfully igniting an engine will now award 1/40th of the configured maximum DU. * Add duSucceed config value, defaults to zero. Choose between duSucceed or 1/40th of max DU, whichever is higher. Move DU award to separate OnIgnition() function.
1 parent 21b6be4 commit 5dc01ad

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

TestFlightAPI/TestFlightAPI/TestFlightFailure.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class TestFlightFailureBase : PartModule, ITestFlightFailure
2222
[KSPField]
2323
public float duFail = 0f;
2424
[KSPField]
25+
public float duSucceed = 0f;
26+
[KSPField]
2527
public float duRepair = 0f;
2628
[KSPField]
2729
public bool oneShot = false;
@@ -163,6 +165,7 @@ public virtual void SetActiveConfig(string alias)
163165
currentConfig.TryGetValue("weight", ref weight);
164166
currentConfig.TryGetValue("failureTitle", ref failureTitle);
165167
currentConfig.TryGetValue("duFail", ref duFail);
168+
currentConfig.TryGetValue("duSucceed", ref duSucceed);
166169
currentConfig.TryGetValue("duRepair", ref duRepair);
167170
currentConfig.TryGetValue("oneShot", ref oneShot);
168171
currentConfig.TryGetValue("awardDuInPreLaunch", ref awardDuInPreLaunch);

TestFlightFailure_IgnitionFail.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ public override void OnUpdate()
275275
}
276276
else
277277
{
278+
OnIgnition();
278279
engineData.hasBeenRun = true;
279280
}
280281
}
@@ -648,6 +649,19 @@ private void ShowRestartWindowPenaltyInfo(string sPenaltyPercent)
648649
TestFlightGameSettings tfSettings = HighLogic.CurrentGame.Parameters.CustomParams<TestFlightGameSettings>();
649650
tfSettings.restartWindowPenaltyReminderShown = restartWindowPenaltyReminderShown = true;
650651
}
652+
653+
private void OnIgnition()
654+
{
655+
if (core.GetFlightData() == core.GetInitialFlightData() && (vessel.situation != Vessel.Situations.PRELAUNCH || awardDuInPreLaunch)) //Only award DU on the first ignition of each flight, and only when not attached to launch clamps.
656+
{
657+
float ignitionDU = Mathf.Max(duSucceed, core.GetMaximumData() / 40);
658+
if (verboseDebugging)
659+
{
660+
Log($"IgnitionFail: Awarding successful ignition DU: {ignitionDU:F4}");
661+
}
662+
core.ModifyFlightData(ignitionDU, true); //Award DU for first successful ignition
663+
}
664+
}
651665
}
652666
}
653667

0 commit comments

Comments
 (0)