From 4fff3a395eee81d39dfac07555df0566ecf4ac03 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 24 Nov 2022 09:53:31 +0200 Subject: [PATCH] Resolved #8044 - corner case where entire path to destination is full and destination is unenterable --- core/src/com/unciv/logic/city/PopulationManager.kt | 5 +++-- core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/city/PopulationManager.kt b/core/src/com/unciv/logic/city/PopulationManager.kt index 2b3311c232..a211b98981 100644 --- a/core/src/com/unciv/logic/city/PopulationManager.kt +++ b/core/src/com/unciv/logic/city/PopulationManager.kt @@ -124,10 +124,11 @@ class PopulationManager : IsPartOfGameInfoSerialization { val currentCiv = cityInfo.civInfo + val tilesToEvaluate = cityInfo.getCenterTile().getTilesInDistance(3) + .filter { it.getOwner() == currentCiv }.toList().asSequence() for (i in 1..getFreePopulation()) { //evaluate tiles - val (bestTile, valueBestTile) = cityInfo.getCenterTile().getTilesInDistance(3) - .filter { it.getOwner() == currentCiv } + val (bestTile, valueBestTile) = tilesToEvaluate .filterNot { it.providesYield() } .associateWith { Automation.rankTileForCityWork(it, cityInfo, cityStats) } .maxByOrNull { it.value } diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index b62f45b93b..5c7db26384 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -552,7 +552,12 @@ class UnitMovementAlgorithms(val unit: MapUnit) { && (origin.isCityCenter() || finalTileReached.isCityCenter()) && unit.civInfo.hasUnique(UniqueType.UnitsInCitiesNoMaintenance) ) unit.civInfo.updateStatsForNextTurn() - if (needToFindNewRoute) moveToTile(destination, considerZoneOfControl) + + // Under rare cases (see #8044), we can be headed to a tile and *the entire path* is blocked by other units, so we can't "enter" that tile. + // If, in such conditions, the *destination tile* is unenterable, needToFindNewRoute will trigger, so we need to catch this situation to avoid infinite loop + if (needToFindNewRoute && unit.currentTile != origin) { + moveToTile(destination, considerZoneOfControl) + } } /**