From 6a8f4914b8839f5660f8df7916ec929c6e5d6914 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Sun, 25 Jun 2023 18:24:30 +0200 Subject: [PATCH] More defensive coding of speedupWonderConstruction (#9671) --- .../automation/unit/SpecificUnitAutomation.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt index 21c4e2774f..488e99bcc2 100644 --- a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt @@ -304,11 +304,8 @@ object SpecificUnitAutomation { }.mapNotNull { city -> val path = unit.movement.getShortestPath(city.getCenterTile()) if (path.any() && path.size <= 5) city to path.size else null - }.minByOrNull { it.second }?.first - - if (nearbyCityWithAvailableWonders == null) { - return false - } + }.minByOrNull { it.second } + ?.first ?: return false if (unit.currentTile == nearbyCityWithAvailableWonders.getCenterTile()) { val wonderToHurry = @@ -317,11 +314,12 @@ object SpecificUnitAutomation { 0, wonderToHurry.name ) - UnitActions.getUnitActions(unit) - .first { - it.type == UnitActionType.HurryBuilding - || it.type == UnitActionType.HurryWonder } - .action!!.invoke() + unit.showAdditionalActions = false // make sure getUnitActions doesn't skip the important ones + val unitAction = UnitActions.getUnitActions(unit).firstOrNull { + it.type == UnitActionType.HurryBuilding || it.type == UnitActionType.HurryWonder + } ?: return false + if (unitAction.action == null) return false + unitAction.action.invoke() return true }