From 661d7a1b793ce0df84182c4160a89487f5533470 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Mon, 8 Jul 2024 00:24:25 +0300 Subject: [PATCH] Resolved #11901 - Can no longer build infinite air units in cities --- core/src/com/unciv/logic/city/City.kt | 2 ++ core/src/com/unciv/logic/map/mapunit/MapUnit.kt | 9 ++++++++- .../com/unciv/logic/map/mapunit/movement/UnitMovement.kt | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/city/City.kt b/core/src/com/unciv/logic/city/City.kt index 777a14c091..657d016f31 100644 --- a/core/src/com/unciv/logic/city/City.kt +++ b/core/src/com/unciv/logic/city/City.kt @@ -237,6 +237,8 @@ class City : IsPartOfGameInfoSerialization, INamed { 200 + cityConstructions.getBuiltBuildings().sumOf { it.cityHealth } fun getStrength() = cityConstructions.getBuiltBuildings().sumOf { it.cityStrength }.toFloat() + /** Gets max air units that can remain in the city untransported */ + fun getMaxAirUnits() = 6 override fun toString() = name // for debug diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt index 59aaf05a83..67c720ef85 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt @@ -892,7 +892,14 @@ class MapUnit : IsPartOfGameInfoSerialization { else -> tile.militaryUnit = this } // this check is here in order to not load the fresh built unit into carrier right after the build - isTransported = !tile.isCityCenter() && baseUnit.movesLikeAirUnits // not moving civilians + if (baseUnit.movesLikeAirUnits){ + if (!tile.isCityCenter()) isTransported = true + else { + val currentUntransportedUnits = tile.getUnits().count { it.type.isAirUnit() && !it.isTransported } + // Tile units includes us, we were just added + isTransported = currentUntransportedUnits > tile.getCity()!!.getMaxAirUnits() + } + } moveThroughTile(tile) cache.updateUniques() } diff --git a/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt b/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt index 5458295c5e..761ac64d5a 100644 --- a/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt +++ b/core/src/com/unciv/logic/map/mapunit/movement/UnitMovement.kt @@ -602,7 +602,7 @@ class UnitMovement(val unit: MapUnit) { private fun canAirUnitMoveTo(tile: Tile, unit: MapUnit): Boolean { // landing in the city if (tile.isCityCenter()) { - if (tile.airUnits.filter { !it.isTransported }.size < 6 && tile.getCity()?.civ == unit.civ) + if (tile.airUnits.filter { !it.isTransported }.size < tile.getCity()!!.getMaxAirUnits() && tile.getCity()?.civ == unit.civ) return true // if city is free - no problem, get in } // let's check whether it enters city on carrier now...