mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-10 15:59:33 +07:00
Added a unique limiting what units can be intercepted (#7488)
* Added a unique limiting what units can be intercepted * Cleaned up implementation and added stateForConditionals
This commit is contained in:
@ -811,12 +811,20 @@ object Battle {
|
||||
}
|
||||
|
||||
private fun tryInterceptAirAttack(attacker: MapUnitCombatant, attackedTile: TileInfo, interceptingCiv: CivilizationInfo, defender: ICombatant?) {
|
||||
if (attacker.unit.hasUnique(UniqueType.CannotBeIntercepted)) return
|
||||
if (attacker.unit.hasUnique(UniqueType.CannotBeIntercepted, StateForConditionals(attacker.getCivInfo(), ourCombatant = attacker, theirCombatant = defender, attackedTile = attackedTile)))
|
||||
return
|
||||
// Pick highest chance interceptor
|
||||
for (interceptor in interceptingCiv.getCivUnits()
|
||||
.filter { it.canIntercept(attackedTile) }
|
||||
.sortedByDescending { it.interceptChance() }) {
|
||||
// defender can't also intercept
|
||||
.filter { it.canIntercept(attackedTile) }
|
||||
.sortedByDescending { it.interceptChance() }
|
||||
) {
|
||||
// Can't intercept if we have a unique preventing it
|
||||
val conditionalState = StateForConditionals(interceptingCiv, ourCombatant = MapUnitCombatant(interceptor), theirCombatant = attacker, combatAction = CombatAction.Intercept, attackedTile = attackedTile)
|
||||
if (interceptor.getMatchingUniques(UniqueType.CannotInterceptUnits, conditionalState)
|
||||
.any { attacker.matchesCategory(it.params[0]) }
|
||||
) continue
|
||||
|
||||
// Defender can't intercept either
|
||||
if (defender != null && defender is MapUnitCombatant && interceptor == defender.unit) continue
|
||||
interceptor.attacksThisTurn++ // even if you miss, you took the shot
|
||||
// Does Intercept happen? If not, exit
|
||||
|
@ -429,6 +429,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
||||
DamageWhenIntercepting("[relativeAmount]% Damage when intercepting", UniqueTarget.Unit),
|
||||
ExtraInterceptionsPerTurn("[amount] extra interceptions may be made per turn", UniqueTarget.Unit),
|
||||
CannotBeIntercepted("Cannot be intercepted", UniqueTarget.Unit),
|
||||
CannotInterceptUnits("Cannot intercept [mapUnitFilter] units", UniqueTarget.Unit),
|
||||
|
||||
UnitMaintenanceDiscount("[relativeAmount]% maintenance costs", UniqueTarget.Unit, UniqueTarget.Global),
|
||||
UnitUpgradeCost("[relativeAmount]% Gold cost of upgrading", UniqueTarget.Unit, UniqueTarget.Global),
|
||||
|
@ -1139,6 +1139,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
|
||||
??? example "Cannot be intercepted"
|
||||
Applicable to: Unit
|
||||
|
||||
??? example "Cannot intercept [mapUnitFilter] units"
|
||||
Example: "Cannot intercept [Wounded] units"
|
||||
|
||||
Applicable to: Unit
|
||||
|
||||
??? example "May capture killed [mapUnitFilter] units"
|
||||
Example: "May capture killed [Wounded] units"
|
||||
|
||||
|
Reference in New Issue
Block a user