Skip to content

Commit

Permalink
Resolved #12823 - "Cannot attack" accepts "vs" conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Jan 18, 2025
1 parent 263bb53 commit 629081f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions core/src/com/unciv/logic/battle/TargetHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.unciv.logic.city.City
import com.unciv.logic.map.mapunit.MapUnit
import com.unciv.logic.map.mapunit.movement.PathsToTilesWithinTurn
import com.unciv.logic.map.tile.Tile
import com.unciv.models.ruleset.unique.StateForConditionals
import com.unciv.models.ruleset.unique.UniqueType

object TargetHelper {
Expand Down Expand Up @@ -112,29 +113,35 @@ object TargetHelper {
)
return false

if (combatant is MapUnitCombatant && combatant.hasUnique(UniqueType.CannotAttack))
return false

if (combatant is MapUnitCombatant) {
val stateForConditionals = StateForConditionals(
unit = (combatant as? MapUnitCombatant)?.unit, tile = tile,
ourCombatant = combatant, theirCombatant = tileCombatant, combatAction = CombatAction.Attack)

if (combatant is MapUnitCombatant &&
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackUnits).run {
any() && none { tileCombatant.matchesFilter(it.params[0]) }
}
)
return false
if (combatant.hasUnique(UniqueType.CannotAttack, stateForConditionals))
return false

if (combatant is MapUnitCombatant &&
combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackTiles).run {
any() && none { tile.matchesFilter(it.params[0]) }
}
)
return false
if (combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackUnits, stateForConditionals).run {
any() && none { tileCombatant.matchesFilter(it.params[0]) }
}
)
return false

if (combatant.unit.getMatchingUniques(UniqueType.CanOnlyAttackTiles, stateForConditionals).run {
any() && none { tile.matchesFilter(it.params[0]) }
}
)
return false
}

// Only units with the right unique can view submarines (or other invisible units) from more then one tile away.
// Garrisoned invisible units can be attacked by anyone, as else the city will be in invincible.
if (tileCombatant.isInvisible(combatant.getCivInfo()) && !tile.isCityCenter()) {
return combatant is MapUnitCombatant
&& combatant.getCivInfo().viewableInvisibleUnitsTiles.map { it.position }.contains(tile.position)
}

return true
}

Expand Down

0 comments on commit 629081f

Please sign in to comment.