Sort Maintenace Using Fixed Point (#5764)

* Add new UniqueType.NoMaintenance to support Guided Missile

* revert gradle
Add UnitMaintenanceDiscount
Rename UnitMaintenanceDiscount->UnitMaintenanceDiscountGlobal
Rework maintenance equation to account for overlapping reductions
Add maintenance variable to MapUnit

* Add square brackets in string (apparently didn't check in?)
More robust uniques check code so not assuming only one matching unique
Use toPercent()

* Proper toPercent() math

* Use fixed point Long to help in sorting to avoid float bug?

* Use fixed point Long to help in sorting to avoid float bug?

Co-authored-by: temurakami <spellman23@gmail.com>
This commit is contained in:
itanasi 2021-12-15 12:59:10 -08:00 committed by GitHub
parent b1390cd6db
commit 4fe7315478
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,7 +52,8 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
// Sort by descending maintenance, then drop most expensive X units to make them free
// If more free than units left, returns empty sequence
// There's something here that causes a bug and I'm not sure where, so let's try taking this apart piece by piece
unitsToPayFor = unitsToPayFor.sortedByDescending { it.maintenance }.toList().asSequence()
// Switching sort to use fixed point math. Perhaps error is due to floating comparisons
unitsToPayFor = unitsToPayFor.sortedByDescending { it.maintenance*100000.0.toInt() }.toList().asSequence()
unitsToPayFor = unitsToPayFor.drop(freeUnits)
val numberOfUnitsToPayFor = max(0.0, unitsToPayFor.sumOf { it.maintenance.toDouble() }).toFloat()