Resolved #11901 - Can no longer build infinite air units in cities

This commit is contained in:
yairm210 2024-07-08 00:24:25 +03:00
parent 13c1ef89a5
commit 661d7a1b79
3 changed files with 11 additions and 2 deletions

View File

@ -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

View File

@ -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()
}

View File

@ -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...