Skip to content

Commit

Permalink
Fix per-flight data cap not working when vessel has more than 1 of th…
Browse files Browse the repository at this point in the history
…e same engine
  • Loading branch information
siimav committed Aug 27, 2023
1 parent ecd47fd commit 06554cc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions TestFlightCore/TestFlightCore/TestFlightCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,23 @@ public float ModifyFlightData(float modifier, bool additive)
newFlightData = Math.Min(newFlightData, initialFlightData + perFlightMax);
}

// Adjust new flight data if neccesary to stay under the cap
// Adjust new flight data if necessary to stay under the cap
if (dataCap != 1f && newFlightData > (maxData * dataCap))
newFlightData = maxData * dataCap;
if (newFlightData > maxData)
newFlightData = maxData;

float dataToAdd = newFlightData - existingData;
if (perFlightMax > 0f)
{
// Prevent data from multiple engines from overflowing the per-flight cap
float currentFlightCap = initialFlightData + perFlightMax;
float distanceToPerFlightCap = currentFlightCap - existingStoredFlightData;
dataToAdd = Math.Min(distanceToPerFlightCap, dataToAdd);
}

// update the scenario store to add (or subtract) the difference between the flight data before calculation and the flight data after (IE the relative change)
TestFlightManagerScenario.Instance.SetFlightDataForPartName(Alias, existingStoredFlightData + (newFlightData - existingData));
TestFlightManagerScenario.Instance.SetFlightDataForPartName(Alias, existingStoredFlightData + dataToAdd);
// and update our part's saved data on the vessel
currentFlightData = newFlightData;

Expand Down

0 comments on commit 06554cc

Please sign in to comment.