From 64925adc7ec6a28629e774511b57198c32b55159 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 2 Mar 2023 21:12:11 +0200 Subject: [PATCH] 'founds a new city' now accepts action modifiers --- .../com/unciv/models/ruleset/unique/UniqueType.kt | 1 + .../worldscreen/unit/actions/UnitActions.kt | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 609105f68b..dceb18a44d 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -350,6 +350,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: // Unit actions should look like: "Can {action description}, to allow them to be combined with modifiers FoundCity("Founds a new city", UniqueTarget.Unit), + ConstructImprovementInstantly("Can instantly construct a [improvementName] improvement", UniqueTarget.Unit), @Deprecated("as of 4.5.2", ReplaceWith("Can instantly construct a [improvementName] improvement ")) ConstructImprovementConsumingUnit("Can construct [improvementName]", UniqueTarget.Unit), 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 7f369af574..bc59ce0dfd 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 @@ -176,14 +176,15 @@ object UnitActions { * (no movement left, too close to another city). */ fun getFoundCityAction(unit: MapUnit, tile: Tile): UnitAction? { - if (!unit.hasUnique(UniqueType.FoundCity) - || tile.isWater || tile.isImpassible()) return null + val unique = unit.getMatchingUniques(UniqueType.FoundCity).firstOrNull() + if (unique == null || tile.isWater || tile.isImpassible()) return null // Spain should still be able to build Conquistadors in a one city challenge - but can't settle them if (unit.civ.isOneCityChallenger() && unit.civ.hasEverOwnedOriginalCapital == true) return null if (unit.currentMovement <= 0 || !tile.canBeSettled()) return UnitAction(UnitActionType.FoundCity, action = null) + val hasActionModifiers = unique.conditionals.any { it.type?.targetTypes?.contains(UniqueTarget.UnitActionModifier) == true } val foundAction = { if (unit.civ.playerType != PlayerType.AI) UncivGame.Current.settings.addCompletedTutorialTask("Found city") @@ -191,8 +192,9 @@ object UnitActions { if (tile.ruleset.tileImprovements.containsKey("City center")) tile.changeImprovement("City center") tile.removeRoad() - unit.destroy() - GUI.setUpdateWorldOnNextRender() + + if (hasActionModifiers) activateSideEffects(unit, unique) + else unit.destroy() } if (unit.civ.playerType == PlayerType.AI) @@ -684,7 +686,9 @@ object UnitActions { } fun getMovementPointsToUse(actionUnique: Unique): Int { - val movementCost = actionUnique.conditionals.filter { it.type == UniqueType.UnitActionMovementCost }.minOfOrNull { it.params[0].toInt() } + val movementCost = actionUnique.conditionals + .filter { it.type == UniqueType.UnitActionMovementCost } + .minOfOrNull { it.params[0].toInt() } if (movementCost != null) return movementCost return 1 }