mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -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
|
// Handle unit maintenance discounts
|
||||||
// Have to capture global and per-unit
|
// Have to capture global and per-unit
|
||||||
// Free Garrison already removed above from sequence
|
// 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
|
// Note all discounts are in the form of -X%, such as -25 for 25% reduction
|
||||||
for (unit in unitsToPayFor){
|
|
||||||
unit.maintenance = 1f
|
var civWideMaintenance = 1f
|
||||||
for (unique in unit.getMatchingUniques(UniqueType.UnitMaintenanceDiscount)){
|
// Calculate global discounts
|
||||||
unit.maintenance *= unique.params[0].toPercent()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Apply global discounts
|
|
||||||
for (unique in civInfo.getMatchingUniques(UniqueType.UnitMaintenanceDiscountGlobal, StateForConditionals(civInfo))) {
|
for (unique in civInfo.getMatchingUniques(UniqueType.UnitMaintenanceDiscountGlobal, StateForConditionals(civInfo))) {
|
||||||
for (unit in unitsToPayFor.filter { it.matchesFilter(unique.params[1]) }) {
|
civWideMaintenance *= unique.params[0].toPercent()
|
||||||
unit.maintenance *= 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
|
// Sort by descending maintenance, then drop most expensive X units to make them free
|
||||||
// If more free than units left, returns empty sequence
|
// If more free than units left, runs sum on 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
|
costsToPay.sortDescending()
|
||||||
// We tried toInt()ing, didn't help. Let's try converting to a final list before sorting.
|
val numberOfUnitsToPayFor = max(0.0, costsToPay.asSequence().drop(freeUnits).sumOf { it.toDouble() } ).toFloat()
|
||||||
unitsToPayFor = unitsToPayFor.toList().sortedByDescending { it.maintenance }.asSequence()
|
|
||||||
unitsToPayFor = unitsToPayFor.drop(freeUnits)
|
|
||||||
val numberOfUnitsToPayFor = max(0.0, unitsToPayFor.sumOf { it.maintenance.toDouble() }).toFloat()
|
|
||||||
|
|
||||||
val turnLimit =
|
val turnLimit =
|
||||||
BASE_GAME_DURATION_TURNS * civInfo.gameInfo.gameParameters.gameSpeed.modifier
|
BASE_GAME_DURATION_TURNS * civInfo.gameInfo.gameParameters.gameSpeed.modifier
|
||||||
|
@ -43,9 +43,6 @@ class MapUnit {
|
|||||||
@Transient
|
@Transient
|
||||||
val movement = UnitMovementAlgorithms(this)
|
val movement = UnitMovementAlgorithms(this)
|
||||||
|
|
||||||
@Transient
|
|
||||||
var maintenance = 1f
|
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
var isDestroyed = false
|
var isDestroyed = false
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user