Free water units are always added to coastal cities

This commit is contained in:
Yair Morgenstern 2023-08-24 10:07:33 +03:00
parent 3d8af531c5
commit 2ce258b281

View File

@ -31,8 +31,13 @@ class UnitManager(val civInfo:Civilization) {
if (civInfo.cities.isEmpty()) return null
if (!civInfo.gameInfo.ruleset.units.containsKey(unitName)) return null
val cityToAddTo = city ?: civInfo.cities.random()
val unit = civInfo.getEquivalentUnit(unitName)
val cityToAddTo = when {
unit.isWaterUnit() && (city==null || !city.isCoastal()) ->
civInfo.cities.filter { it.isCoastal() }.randomOrNull()
city != null -> city
else -> 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
?: return null