From 2ce258b28137de413120b93f35b5705c600c0729 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 24 Aug 2023 10:07:33 +0300 Subject: [PATCH] Free water units are always added to coastal cities --- .../com/unciv/logic/civilization/managers/UnitManager.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/managers/UnitManager.kt b/core/src/com/unciv/logic/civilization/managers/UnitManager.kt index acdbe7df52..0c3a318c8b 100644 --- a/core/src/com/unciv/logic/civilization/managers/UnitManager.kt +++ b/core/src/com/unciv/logic/civilization/managers/UnitManager.kt @@ -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 @@ -76,7 +81,7 @@ class UnitManager(val civInfo:Civilization) { if (!unique.hasTriggerConditional()) UniqueTriggerActivation.triggerUnitwideUnique(unique, unit, triggerNotificationText = triggerNotificationText) for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponGainingUnit)) - if (unique.conditionals.any { it.isOfType(UniqueType.TriggerUponGainingUnit) && + if (unique.conditionals.any { it.isOfType(UniqueType.TriggerUponGainingUnit) && unit.matchesFilter(unique.params[0]) }) UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo, triggerNotificationText = triggerNotificationText) if (unit.baseUnit.getResourceRequirementsPerTurn().isNotEmpty())