From 4fe7315478d0ba2aa57b78b2c134ff5f10589803 Mon Sep 17 00:00:00 2001 From: itanasi <44038014+itanasi@users.noreply.github.com> Date: Wed, 15 Dec 2021 12:59:10 -0800 Subject: [PATCH] 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 --- core/src/com/unciv/logic/civilization/CivInfoStats.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/civilization/CivInfoStats.kt b/core/src/com/unciv/logic/civilization/CivInfoStats.kt index 4b6ea49ce0..fe97b62d30 100644 --- a/core/src/com/unciv/logic/civilization/CivInfoStats.kt +++ b/core/src/com/unciv/logic/civilization/CivInfoStats.kt @@ -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()