From d0cb10abbe4be355051dc6bea85f9f6598978f16 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 28 May 2019 23:13:08 +0300 Subject: [PATCH] Hopefully fixed a recurring bug in tryHeadTowardsEnemyCity --- core/src/com/unciv/logic/automation/UnitAutomation.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index b368bf3490..b5c1cca470 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -233,15 +233,14 @@ class UnitAutomation{ .filter { unit.civInfo.isAtWarWith(it) } .flatMap { it.cities }.asSequence() .filter { it.location in unit.civInfo.exploredTiles } - .map { it.getCenterTile() }.toList() if(unit.type.isRanged()) // ranged units don't harm capturable cities, waste of a turn - enemyCities = enemyCities.filterNot { it.getCity()!!.health==1 } + enemyCities = enemyCities.filterNot { it.health==1 } val closestReachableEnemyCity = enemyCities - .asSequence() - .sortedBy { city -> // sort enemy cities by closeness to our cities, and only then choose the first reachable - checking canReach is comparatively very time-intensive! - unit.civInfo.cities.asSequence().map { city.arialDistanceTo(it.getCenterTile()) }.min()!! + .asSequence().map { it.getCenterTile() } + .sortedBy { cityCenterTile -> // sort enemy cities by closeness to our cities, and only then choose the first reachable - checking canReach is comparatively very time-intensive! + unit.civInfo.cities.asSequence().map { cityCenterTile.arialDistanceTo(it.getCenterTile()) }.min()!! } .firstOrNull { unit.movementAlgs().canReach(it) }