diff --git a/core/src/com/unciv/logic/map/mapunit/movement/MovementCost.kt b/core/src/com/unciv/logic/map/mapunit/movement/MovementCost.kt index 3c197cf67b..e37f9000a7 100644 --- a/core/src/com/unciv/logic/map/mapunit/movement/MovementCost.kt +++ b/core/src/com/unciv/logic/map/mapunit/movement/MovementCost.kt @@ -172,8 +172,7 @@ object MovementCost { // these two tiles can perhaps be optimized. Using a hex-math-based "commonAdjacentTiles" // function is surprisingly less efficient than the current neighbor-intersection approach. // See #4085 for more details. - val tilesExertingZoneOfControl = getTilesExertingZoneOfControl(unit, from) - if (tilesExertingZoneOfControl.none { to.aerialDistanceTo(it) == 1 }) + if (!anyTilesExertingZoneOfControl(unit, from, to)) return false // Even though this is a very fast check, we perform it last. This is because very few units @@ -185,16 +184,19 @@ object MovementCost { return true } - private fun getTilesExertingZoneOfControl(unit: MapUnit, tile: Tile) = sequence { - for (neighbor in tile.neighbors) { - if (neighbor.isCityCenter() && unit.civ.isAtWarWith(neighbor.getOwner()!!)) { - yield(neighbor) - } - else if (neighbor.militaryUnit != null && unit.civ.isAtWarWith(neighbor.militaryUnit!!.civ)) { - if (neighbor.militaryUnit!!.type.isWaterUnit() || (unit.type.isLandUnit() && !neighbor.militaryUnit!!.isEmbarked())) - yield(neighbor) + private fun anyTilesExertingZoneOfControl(unit: MapUnit, from: Tile, to:Tile): Boolean { + for (neighbor in from.neighbors) { + if (neighbor.isCityCenter()) { + if (neighbor.aerialDistanceTo(to) == 1 + && unit.civ.isAtWarWith(neighbor.getOwner()!!)) + return true + } else if (neighbor.militaryUnit != null) { + if (neighbor.aerialDistanceTo(to) == 1 + && (neighbor.militaryUnit!!.type.isWaterUnit() || (unit.type.isLandUnit() && !neighbor.militaryUnit!!.isEmbarked())) + && unit.civ.isAtWarWith(neighbor.militaryUnit!!.civ)) + return true } } + return false } - }