diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt index c571ad693a..6a827a1d07 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt @@ -25,6 +25,7 @@ import com.unciv.models.stats.Stats import com.unciv.ui.components.extensions.filterAndLogic import java.text.DecimalFormat import kotlin.math.pow +import kotlin.math.ulp /** @@ -266,9 +267,24 @@ class MapUnit : IsPartOfGameInfoSerialization { if (movement < 1) movement = 1 + // Hakkapeliitta movement boost + // For every double-stacked tile, check if our cohabitant can boost our speed + // (a test `count() > 1` is no optimization - two iterations of a sequence instead of one) + for (boostingUnit in currentTile.getUnits()) { + if (boostingUnit == this) continue + if (boostingUnit.getMatchingUniques(UniqueType.TransferMovement) + .none { matchesFilter(it.params[0]) } ) continue + movement = movement.coerceAtLeast(boostingUnit.getMaxMovement()) + } + return movement } + fun hasUnitMovedThisTurn(): Boolean { + val max = getMaxMovement().toFloat() + return currentMovement < max - max.ulp + } + /** * Determines this (land or sea) unit's current maximum vision range from unit properties, civ uniques and terrain. * @return Maximum distance of tiles this unit may possibly see diff --git a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt index 3f3bc0a0d3..03c6bbd811 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt @@ -15,15 +15,14 @@ class UnitTurnManager(val unit: MapUnit) { && unit.getTile().improvementInProgress != null && unit.canBuildImprovement(unit.getTile().getTileImprovementInProgress()!!) ) workOnImprovement() - if (unit.currentMovement == unit.getMaxMovement().toFloat() && unit.isFortified() && unit.turnsFortified < 2) { + if (!unit.hasUnitMovedThisTurn() && unit.isFortified() && unit.turnsFortified < 2) { unit.turnsFortified++ } if (!unit.isFortified()) unit.turnsFortified = 0 - if (unit.currentMovement == unit.getMaxMovement().toFloat() // didn't move this turn - || unit.hasUnique(UniqueType.HealsEvenAfterAction) - ) healUnit() + if (!unit.hasUnitMovedThisTurn() || unit.hasUnique(UniqueType.HealsEvenAfterAction)) + healUnit() if (unit.action != null && unit.health > 99) if (unit.isActionUntilHealed()) { @@ -137,17 +136,6 @@ class UnitTurnManager(val unit: MapUnit) { unit.attacksThisTurn = 0 unit.due = true - // Hakkapeliitta movement boost - // For every double-stacked tile, check if our cohabitant can boost our speed - // (a test `count() > 1` is no optimization - two iterations of a sequence instead of one) - for (boostingUnit in unit.getTile().getUnits()) { - if (boostingUnit == unit) continue - - if (boostingUnit.getMatchingUniques(UniqueType.TransferMovement) - .none { unit.matchesFilter(it.params[0]) } ) continue - unit.currentMovement = unit.currentMovement.coerceAtLeast(boostingUnit.getMaxMovement().toFloat()) - } - // Wake sleeping units if there's an enemy in vision range: // Military units always but civilians only if not protected. if (unit.isSleeping() && (unit.isMilitary() || (unit.currentTile.militaryUnit == null && !unit.currentTile.isCityCenter())) && 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 505fe7a5d2..4ec883dcf2 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 @@ -277,9 +277,9 @@ object UnitActions { if (unit.isPreparingParadrop()) unit.action = null else unit.action = UnitActionType.Paradrop.value }.takeIf { - unit.currentMovement == unit.getMaxMovement().toFloat() && - unit.currentTile.isFriendlyTerritory(unit.civ) && - !unit.isEmbarked() + !unit.hasUnitMovedThisTurn() && + unit.currentTile.isFriendlyTerritory(unit.civ) && + !unit.isEmbarked() }) }