mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 00:09:23 +07:00
Centralize hasUnitMovedThisTurn and fix by moving TransferMovement implementation to getMaxMovement (#9950)
This commit is contained in:
@ -25,6 +25,7 @@ import com.unciv.models.stats.Stats
|
|||||||
import com.unciv.ui.components.extensions.filterAndLogic
|
import com.unciv.ui.components.extensions.filterAndLogic
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
import kotlin.math.ulp
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -266,9 +267,24 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
|||||||
|
|
||||||
if (movement < 1) movement = 1
|
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
|
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.
|
* 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
|
* @return Maximum distance of tiles this unit may possibly see
|
||||||
|
@ -15,15 +15,14 @@ class UnitTurnManager(val unit: MapUnit) {
|
|||||||
&& unit.getTile().improvementInProgress != null
|
&& unit.getTile().improvementInProgress != null
|
||||||
&& unit.canBuildImprovement(unit.getTile().getTileImprovementInProgress()!!)
|
&& unit.canBuildImprovement(unit.getTile().getTileImprovementInProgress()!!)
|
||||||
) workOnImprovement()
|
) workOnImprovement()
|
||||||
if (unit.currentMovement == unit.getMaxMovement().toFloat() && unit.isFortified() && unit.turnsFortified < 2) {
|
if (!unit.hasUnitMovedThisTurn() && unit.isFortified() && unit.turnsFortified < 2) {
|
||||||
unit.turnsFortified++
|
unit.turnsFortified++
|
||||||
}
|
}
|
||||||
if (!unit.isFortified())
|
if (!unit.isFortified())
|
||||||
unit.turnsFortified = 0
|
unit.turnsFortified = 0
|
||||||
|
|
||||||
if (unit.currentMovement == unit.getMaxMovement().toFloat() // didn't move this turn
|
if (!unit.hasUnitMovedThisTurn() || unit.hasUnique(UniqueType.HealsEvenAfterAction))
|
||||||
|| unit.hasUnique(UniqueType.HealsEvenAfterAction)
|
healUnit()
|
||||||
) healUnit()
|
|
||||||
|
|
||||||
if (unit.action != null && unit.health > 99)
|
if (unit.action != null && unit.health > 99)
|
||||||
if (unit.isActionUntilHealed()) {
|
if (unit.isActionUntilHealed()) {
|
||||||
@ -137,17 +136,6 @@ class UnitTurnManager(val unit: MapUnit) {
|
|||||||
unit.attacksThisTurn = 0
|
unit.attacksThisTurn = 0
|
||||||
unit.due = true
|
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:
|
// Wake sleeping units if there's an enemy in vision range:
|
||||||
// Military units always but civilians only if not protected.
|
// Military units always but civilians only if not protected.
|
||||||
if (unit.isSleeping() && (unit.isMilitary() || (unit.currentTile.militaryUnit == null && !unit.currentTile.isCityCenter())) &&
|
if (unit.isSleeping() && (unit.isMilitary() || (unit.currentTile.militaryUnit == null && !unit.currentTile.isCityCenter())) &&
|
||||||
|
@ -277,7 +277,7 @@ object UnitActions {
|
|||||||
if (unit.isPreparingParadrop()) unit.action = null
|
if (unit.isPreparingParadrop()) unit.action = null
|
||||||
else unit.action = UnitActionType.Paradrop.value
|
else unit.action = UnitActionType.Paradrop.value
|
||||||
}.takeIf {
|
}.takeIf {
|
||||||
unit.currentMovement == unit.getMaxMovement().toFloat() &&
|
!unit.hasUnitMovedThisTurn() &&
|
||||||
unit.currentTile.isFriendlyTerritory(unit.civ) &&
|
unit.currentTile.isFriendlyTerritory(unit.civ) &&
|
||||||
!unit.isEmbarked()
|
!unit.isEmbarked()
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user