diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt index b557092f87..1d3d38b117 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt @@ -55,6 +55,7 @@ class MapUnit : IsPartOfGameInfoSerialization { */ var instanceName: String? = null + /** Should not be changed directly - instead use [useMovementPoints] */ var currentMovement: Float = 0f var health: Int = 100 var id: Int = Constants.NO_ID @@ -701,10 +702,15 @@ class MapUnit : IsPartOfGameInfoSerialization { } } + /** Can accept a negative number to gain movement points */ fun useMovementPoints(amount: Float) { turnsFortified = 0 currentMovement -= amount if (currentMovement < 0) currentMovement = 0f + if (amount < 0) { + val maxMovement = getMaxMovement().toFloat() + if (currentMovement > maxMovement) currentMovement = maxMovement + } } fun fortify() { diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt index 867a8bf2be..114c09806d 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt @@ -971,7 +971,6 @@ object UniqueTriggerActivation { } UniqueType.OneTimeUnitGainXP -> { if (unit == null) return null - if (!unit.baseUnit.isMilitary) return null return { unit.promotions.XP += unique.params[0].toInt() if (notification != null) @@ -979,20 +978,21 @@ object UniqueTriggerActivation { true } } - UniqueType.OneTimeUnitUpgrade -> { + UniqueType.OneTimeUnitGainMovement, UniqueType.OneTimeUnitLoseMovement -> { if (unit == null) return null - val upgradeAction = UnitActionsUpgrade.getFreeUpgradeAction(unit) - if (upgradeAction.none()) return null return { - (upgradeAction.minBy { (it as UpgradeUnitAction).unitToUpgradeTo.cost }).action!!() - if (notification != null) - unit.civ.addNotification(notification, MapUnitAction(unit), NotificationCategory.Units) + val movementToUse = + if (unique.type == UniqueType.OneTimeUnitLoseMovement) unique.params[0].toFloat() + else -unique.params[0].toFloat() + unit.useMovementPoints(movementToUse) true } } - UniqueType.OneTimeUnitSpecialUpgrade -> { + UniqueType.OneTimeUnitUpgrade, UniqueType.OneTimeUnitSpecialUpgrade -> { if (unit == null) return null - val upgradeAction = UnitActionsUpgrade.getAncientRuinsUpgradeAction(unit) + val upgradeAction = + if (unique.type == UniqueType.OneTimeUnitSpecialUpgrade) UnitActionsUpgrade.getAncientRuinsUpgradeAction(unit) + else UnitActionsUpgrade.getFreeUpgradeAction(unit) if (upgradeAction.none()) return null return { (upgradeAction.minBy { (it as UpgradeUnitAction).unitToUpgradeTo.cost }).action!!() diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index db26611f74..506aef809b 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -836,6 +836,8 @@ enum class UniqueType( OneTimeUnitSpecialUpgrade("This Unit upgrades for free including special upgrades", UniqueTarget.UnitTriggerable), OneTimeUnitGainPromotion("This Unit gains the [promotion] promotion", UniqueTarget.UnitTriggerable), // Not used in Vanilla OneTimeUnitRemovePromotion("This Unit loses the [promotion] promotion", UniqueTarget.UnitTriggerable), + OneTimeUnitGainMovement("This Unit gains [amount] movement", UniqueTarget.UnitTriggerable), + OneTimeUnitLoseMovement("This Unit loses [amount] movement", UniqueTarget.UnitTriggerable), SkipPromotion("Doing so will consume this opportunity to choose a Promotion", UniqueTarget.Promotion), FreePromotion("This Promotion is free", UniqueTarget.Promotion),