mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04:00
Fix any tech researched clearing all units from queues (#10777)
This commit is contained in:
parent
75af329b16
commit
77de68cfc5
@ -23,7 +23,6 @@ import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
|||||||
import com.unciv.models.ruleset.unique.UniqueType
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
import com.unciv.models.ruleset.unit.BaseUnit
|
import com.unciv.models.ruleset.unit.BaseUnit
|
||||||
import com.unciv.ui.components.MayaCalendar
|
import com.unciv.ui.components.MayaCalendar
|
||||||
import com.unciv.ui.components.extensions.toPercent
|
|
||||||
import com.unciv.ui.components.extensions.withItem
|
import com.unciv.ui.components.extensions.withItem
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
@ -335,18 +334,25 @@ class TechManager : IsPartOfGameInfoSerialization {
|
|||||||
updateResearchProgress()
|
updateResearchProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A variant of kotlin's [associateBy] that omits null values */
|
||||||
|
private inline fun <T, K, V> Iterable<T>.associateByNotNull(keySelector: (T) -> K, valueTransform: (T) -> V?): Map<K, V> {
|
||||||
|
val destination = LinkedHashMap<K, V>()
|
||||||
|
for (element in this) {
|
||||||
|
val value = valueTransform(element) ?: continue
|
||||||
|
destination[keySelector(element)] = value
|
||||||
|
}
|
||||||
|
return destination
|
||||||
|
}
|
||||||
|
|
||||||
private fun obsoleteOldUnits(techName: String) {
|
private fun obsoleteOldUnits(techName: String) {
|
||||||
// First build a map with obsoleted units to their (nation-specific) upgrade
|
// First build a map with obsoleted units to their (nation-specific) upgrade
|
||||||
val ruleset = getRuleset()
|
|
||||||
fun BaseUnit.getEquivalentUpgradeOrNull(techName: String): BaseUnit? {
|
fun BaseUnit.getEquivalentUpgradeOrNull(techName: String): BaseUnit? {
|
||||||
val unitUpgradesTo: String? = automaticallyUpgradedInProductionToUnitByTech(techName)
|
val unitUpgradesTo = automaticallyUpgradedInProductionToUnitByTech(techName)
|
||||||
if (unitUpgradesTo == null)
|
?: return null
|
||||||
return null
|
return civInfo.getEquivalentUnit(unitUpgradesTo)
|
||||||
return civInfo.getEquivalentUnit(unitUpgradesTo!!)
|
|
||||||
}
|
}
|
||||||
val obsoleteUnits = getRuleset().units.asSequence()
|
val obsoleteUnits = getRuleset().units.entries
|
||||||
.map { it.key to it.value.getEquivalentUpgradeOrNull(techName) }
|
.associateByNotNull({ it.key }, { it.value.getEquivalentUpgradeOrNull(techName) })
|
||||||
.toMap()
|
|
||||||
if (obsoleteUnits.isEmpty()) return
|
if (obsoleteUnits.isEmpty()) return
|
||||||
|
|
||||||
// Apply each to all cities - and remember which cities had which obsoleted unit
|
// Apply each to all cities - and remember which cities had which obsoleted unit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user