mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-12 08:49:22 +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() }
|
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"
|
// Only military land units can truly "garrison"
|
||||||
fun canGarrison() = isMilitary() && baseUnit.isLandUnit()
|
fun canGarrison() = isMilitary() && baseUnit.isLandUnit()
|
||||||
|
|
||||||
|
@ -66,11 +66,7 @@ class UnitTurnManager(val unit: MapUnit) {
|
|||||||
|
|
||||||
|
|
||||||
private fun healUnit() {
|
private fun healUnit() {
|
||||||
if (unit.isEmbarked()) return // embarked units can't heal
|
val amountToHealBy = unit.getHealAmountForCurrentTile()
|
||||||
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())
|
|
||||||
if (amountToHealBy == 0) return
|
if (amountToHealBy == 0) return
|
||||||
|
|
||||||
unit.healBy(amountToHealBy)
|
unit.healBy(amountToHealBy)
|
||||||
|
@ -601,7 +601,7 @@ object UnitActions {
|
|||||||
if (isDamaged && !showingAdditionalActions) {
|
if (isDamaged && !showingAdditionalActions) {
|
||||||
actionList += UnitAction(UnitActionType.SleepUntilHealed,
|
actionList += UnitAction(UnitActionType.SleepUntilHealed,
|
||||||
action = { unit.action = UnitActionType.SleepUntilHealed.value }
|
action = { unit.action = UnitActionType.SleepUntilHealed.value }
|
||||||
.takeIf { !unit.isSleepingUntilHealed() }
|
.takeIf { !unit.isSleepingUntilHealed() && unit.canHealInCurrentTile() }
|
||||||
)
|
)
|
||||||
} else if (isDamaged || !showingAdditionalActions) {
|
} else if (isDamaged || !showingAdditionalActions) {
|
||||||
actionList += UnitAction(UnitActionType.Sleep,
|
actionList += UnitAction(UnitActionType.Sleep,
|
||||||
|
Reference in New Issue
Block a user