Modify battery assert to avoid floating point errors (#28007)

This commit is contained in:
Leon Friedrich 2024-05-19 13:54:52 +12:00 committed by null
parent 939133e8ba
commit caa2f7e5ba
No known key found for this signature in database
GPG Key ID: 212F05528FD678BE
1 changed files with 4 additions and 3 deletions

View File

@ -240,7 +240,8 @@ namespace Content.Server.Power.Pow3r
}
}
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
@ -275,8 +276,8 @@ namespace Content.Server.Power.Pow3r
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));
}
}