Skip to content

Commit

Permalink
Modify battery assert to avoid floating point errors (#28007)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr authored May 19, 2024
1 parent e5f30b1 commit b4a5399
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Content.Server/Power/Pow3r/BatteryRampPegSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ private void UpdateNetwork(Network network, PowerState state, float frameTime)
}
}

if (unmet <= 0 || totalBatterySupply <= 0)
// Return if normal supplies met all demand or there are no supplying batteries
if (unmet <= 0 || totalMaxBatterySupply <= 0)
return;

// Target output capacity for batteries
Expand Down Expand Up @@ -275,8 +276,8 @@ private void UpdateNetwork(Network network, PowerState state, float frameTime)

battery.SupplyRampTarget = battery.MaxEffectiveSupply * relativeTargetBatteryOutput - battery.CurrentReceiving * battery.Efficiency;

DebugTools.Assert(battery.SupplyRampTarget + battery.CurrentReceiving * battery.Efficiency <= battery.LoadingNetworkDemand
|| MathHelper.CloseToPercent(battery.SupplyRampTarget + battery.CurrentReceiving * battery.Efficiency, battery.LoadingNetworkDemand, 0.001));
DebugTools.Assert(battery.MaxEffectiveSupply * relativeTargetBatteryOutput <= battery.LoadingNetworkDemand
|| MathHelper.CloseToPercent(battery.MaxEffectiveSupply * relativeTargetBatteryOutput, battery.LoadingNetworkDemand, 0.001));
}
}

Expand Down

0 comments on commit b4a5399

Please sign in to comment.