From d3f639e29c4806aa5af068af794093090c198c2a Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 29 Jun 2021 22:35:22 +0300 Subject: [PATCH] Solved crashing 'head towards sieged city' bug --- core/src/com/unciv/logic/automation/UnitAutomation.kt | 2 +- core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index 9744ffa31b..e24fbc3a7c 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -298,7 +298,7 @@ object UnitAutomation { val reachableTileNearSiegedCity = siegedCities .flatMap { it.getCenterTile().getTilesAtDistance(2) } .sortedBy { it.aerialDistanceTo(unit.currentTile) } - .firstOrNull { unit.movement.canReach(it) } + .firstOrNull { unit.movement.canMoveTo(it) && unit.movement.canReach(it) } if (reachableTileNearSiegedCity != null) { unit.movement.headTowards(reachableTileNearSiegedCity) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 87aa714bf9..3a13f7d0f2 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -215,7 +215,8 @@ class UnitMovementAlgorithms(val unit:MapUnit) { return unit.currentTile } - /** This is performance-heavy - use as last resort, only after checking everything else! */ + /** This is performance-heavy - use as last resort, only after checking everything else! + * Also note that REACHABLE tiles are not necessarily tiles that the unit CAN ENTER */ fun canReach(destination: TileInfo): Boolean { if (unit.type.isAirUnit() || unit.type.isMissile() || unit.action == Constants.unitActionParadrop) return canReachInCurrentTurn(destination)