Resolved #12187 - units are not added to cities in resistance if non-resistant cities are available

This commit is contained in:
yairm210 2024-09-07 22:37:29 +03:00
parent 2a0ff58cc9
commit 9c0e9131f0

View File

@ -53,11 +53,14 @@ class UnitManager(val civInfo: Civilization) {
if (civInfo.cities.isEmpty()) return null
val unit = civInfo.getEquivalentUnit(baseUnit)
val citiesNotInResistance = civInfo.cities.filterNot { it.isInResistance() }
val cityToAddTo = when {
unit.isWaterUnit && (city == null || !city.isCoastal()) ->
citiesNotInResistance.filter { it.isCoastal() }.randomOrNull() ?:
civInfo.cities.filter { it.isCoastal() }.randomOrNull()
city != null -> city
else -> civInfo.cities.random()
else -> citiesNotInResistance.randomOrNull() ?: civInfo.cities.random()
} ?: return null // If we got a free water unit with no coastal city to place it in
val placedUnit = placeUnitNearTile(cityToAddTo.location, unit.name)
// silently bail if no tile to place the unit is found