mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-05 21:11:35 +07:00
Centralize hasUnitMovedThisTurn and fix by moving TransferMovement implementation to getMaxMovement (#9950)
This commit is contained in:
parent
c79d1d4d52
commit
40fe93888f
@ -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
|
||||
|
@ -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())) &&
|
||||
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user