mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
* Try to fix #5729 as concurrency issue. * Oh, remove comment about crash, I guess.
This commit is contained in:
parent
005c465ee4
commit
f6d186445c
@ -35,27 +35,29 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
// Handle unit maintenance discounts
|
||||
// Have to capture global and per-unit
|
||||
// Free Garrison already removed above from sequence
|
||||
// Initialize maintenance cost per unit, default 1 aka 100%
|
||||
// Initialize base maintenance cost empire-wide, default 1 aka 100%
|
||||
// Then calculate per-unit discounrts
|
||||
// Note all discounts are in the form of -X%, such as -25 for 25% reduction
|
||||
for (unit in unitsToPayFor){
|
||||
unit.maintenance = 1f
|
||||
for (unique in unit.getMatchingUniques(UniqueType.UnitMaintenanceDiscount)){
|
||||
unit.maintenance *= unique.params[0].toPercent()
|
||||
}
|
||||
}
|
||||
// Apply global discounts
|
||||
|
||||
var civWideMaintenance = 1f
|
||||
// Calculate global discounts
|
||||
for (unique in civInfo.getMatchingUniques(UniqueType.UnitMaintenanceDiscountGlobal, StateForConditionals(civInfo))) {
|
||||
for (unit in unitsToPayFor.filter { it.matchesFilter(unique.params[1]) }) {
|
||||
unit.maintenance *= unique.params[0].toPercent()
|
||||
}
|
||||
civWideMaintenance *= unique.params[0].toPercent()
|
||||
}
|
||||
|
||||
val costsToPay = ArrayList<Float>()
|
||||
for (unit in unitsToPayFor) {
|
||||
var unitMaintenance = civWideMaintenance
|
||||
for (unique in unit.getMatchingUniques(UniqueType.UnitMaintenanceDiscount)){
|
||||
unitMaintenance *= unique.params[0].toPercent()
|
||||
}
|
||||
costsToPay.add(unitMaintenance)
|
||||
}
|
||||
|
||||
// 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
|
||||
// We tried toInt()ing, didn't help. Let's try converting to a final list before sorting.
|
||||
unitsToPayFor = unitsToPayFor.toList().sortedByDescending { it.maintenance }.asSequence()
|
||||
unitsToPayFor = unitsToPayFor.drop(freeUnits)
|
||||
val numberOfUnitsToPayFor = max(0.0, unitsToPayFor.sumOf { it.maintenance.toDouble() }).toFloat()
|
||||
// If more free than units left, runs sum on empty sequence
|
||||
costsToPay.sortDescending()
|
||||
val numberOfUnitsToPayFor = max(0.0, costsToPay.asSequence().drop(freeUnits).sumOf { it.toDouble() } ).toFloat()
|
||||
|
||||
val turnLimit =
|
||||
BASE_GAME_DURATION_TURNS * civInfo.gameInfo.gameParameters.gameSpeed.modifier
|
||||
@ -344,4 +346,4 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
||||
return statMap
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,6 @@ class MapUnit {
|
||||
@Transient
|
||||
val movement = UnitMovementAlgorithms(this)
|
||||
|
||||
@Transient
|
||||
var maintenance = 1f
|
||||
|
||||
@Transient
|
||||
var isDestroyed = false
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user