mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-09 23:39:40 +07:00
"Sleep until healed" knows when you can't (#9003)
This commit is contained in:
@ -414,6 +414,14 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
return getMatchingUniques(UniqueType.HealAdjacentUnits).sumOf { it.params[0].toInt() }
|
||||
}
|
||||
|
||||
fun getHealAmountForCurrentTile() = when {
|
||||
isEmbarked() -> 0 // embarked units can't heal
|
||||
health >= 100 -> 0 // No need to heal if at max health
|
||||
hasUnique(UniqueType.HealOnlyByPillaging, checkCivInfoUniques = true) -> 0
|
||||
else -> rankTileForHealing(getTile())
|
||||
}
|
||||
fun canHealInCurrentTile() = getHealAmountForCurrentTile() > 0
|
||||
|
||||
// Only military land units can truly "garrison"
|
||||
fun canGarrison() = isMilitary() && baseUnit.isLandUnit()
|
||||
|
||||
|
@ -66,11 +66,7 @@ class UnitTurnManager(val unit: MapUnit) {
|
||||
|
||||
|
||||
private fun healUnit() {
|
||||
if (unit.isEmbarked()) return // embarked units can't heal
|
||||
if (unit.health >= 100) return // No need to heal if at max health
|
||||
if (unit.hasUnique(UniqueType.HealOnlyByPillaging, checkCivInfoUniques = true)) return
|
||||
|
||||
val amountToHealBy = unit.rankTileForHealing(unit.getTile())
|
||||
val amountToHealBy = unit.getHealAmountForCurrentTile()
|
||||
if (amountToHealBy == 0) return
|
||||
|
||||
unit.healBy(amountToHealBy)
|
||||
|
@ -601,7 +601,7 @@ object UnitActions {
|
||||
if (isDamaged && !showingAdditionalActions) {
|
||||
actionList += UnitAction(UnitActionType.SleepUntilHealed,
|
||||
action = { unit.action = UnitActionType.SleepUntilHealed.value }
|
||||
.takeIf { !unit.isSleepingUntilHealed() }
|
||||
.takeIf { !unit.isSleepingUntilHealed() && unit.canHealInCurrentTile() }
|
||||
)
|
||||
} else if (isDamaged || !showingAdditionalActions) {
|
||||
actionList += UnitAction(UnitActionType.Sleep,
|
||||
|
Reference in New Issue
Block a user