From 2ffec93ae8839cadc0ea3c2c396b994cb537e1eb Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 8 Dec 2023 12:16:49 +0200 Subject: [PATCH] invokeUnitAction will take the first *actionable* action, instead of the first one that exists, which may not be actionable --- .../ui/screens/worldscreen/unit/actions/UnitActions.kt | 7 ++++--- docs/Modders/uniques.md | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt index 787a90b00d..406e593be0 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt @@ -23,9 +23,10 @@ object UnitActions { /** Returns whether the action was invoked */ fun invokeUnitAction(unit: MapUnit, unitActionType: UnitActionType): Boolean { - val unitAction = actionTypeToFunctions[unitActionType]?.invoke(unit, unit.getTile())?.firstOrNull() - ?: getNormalActions(unit).firstOrNull { it.type == unitActionType } - ?: getAdditionalActions(unit).firstOrNull { it.type == unitActionType } + val unitAction = if (unitActionType in actionTypeToFunctions) actionTypeToFunctions[unitActionType]!!.invoke(unit, unit.getTile()) + .firstOrNull{ it.action != null } + else getNormalActions(unit).firstOrNull { it.type == unitActionType && it.action != null } + ?: getAdditionalActions(unit).firstOrNull { it.type == unitActionType && it.action != null } val internalAction = unitAction?.action ?: return false internalAction.invoke() return true diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index 9c832f2317..6a52dd5330 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -1158,14 +1158,14 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Uniques that can be added to units, unit types, or promotions +??? example "May create improvements on water resources" + Applicable to: Unit + ??? example "Can build [improvementFilter/terrainFilter] improvements on tiles" Example: "Can build [All Road] improvements on tiles" Applicable to: Unit -??? example "May create improvements on water resources" - Applicable to: Unit - ??? example "Can be added to [comment] in the Capital" Example: "Can be added to [comment] in the Capital"