"Sleep until healed" knows when you can't (#9003)

This commit is contained in:
SomeTroglodyte
2023-03-23 08:17:12 +01:00
committed by GitHub
parent a1d0248f6a
commit cb25e32762
3 changed files with 10 additions and 6 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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,