mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-03 04:45:34 +07:00
Added a unique for attacking when embarked (#6464)
* Added a unique for attacking when embarked * Implemented requested changes * Fixed withdrawel probability
This commit is contained in:
parent
d87d83f686
commit
d417556720
@ -92,8 +92,8 @@ object BattleHelper {
|
||||
|
||||
fun containsAttackableEnemy(tile: TileInfo, combatant: ICombatant): Boolean {
|
||||
if (combatant is MapUnitCombatant && combatant.unit.isEmbarked()) {
|
||||
if (tile.isWater) return false // can't attack water units while embarked, only land
|
||||
if (combatant.isRanged()) return false
|
||||
// Can't attack water units while embarked, only land
|
||||
if (tile.isWater || combatant.isRanged()) return combatant.hasUnique(UniqueType.AttackOnSea)
|
||||
}
|
||||
|
||||
val tileCombatant = Battle.getMapCombatantOfTile(tile) ?: return false
|
||||
|
@ -76,9 +76,10 @@ object Battle {
|
||||
|
||||
// Withdraw from melee ability
|
||||
if (attacker is MapUnitCombatant && attacker.isMelee() && defender is MapUnitCombatant) {
|
||||
val withdraw = defender.unit.getMatchingUniques(UniqueType.MayWithdraw)
|
||||
.sumOf{ it.params[0].toInt() } // If a mod allows multiple withdraw properties, ensure the best is used
|
||||
if (withdraw != 0 && doWithdrawFromMeleeAbility(attacker, defender, withdraw)) return
|
||||
val withdrawUniques = defender.unit.getMatchingUniques(UniqueType.MayWithdraw)
|
||||
val baseWithdrawChance = 100-withdrawUniques.fold(100) { probability, unique -> probability * (100-unique.params[0].toInt()) }
|
||||
// If a mod allows multiple withdraw properties, they stack multiplicatively
|
||||
if (baseWithdrawChance != 0 && doWithdrawFromMeleeAbility(attacker, defender, baseWithdrawChance)) return
|
||||
}
|
||||
|
||||
val isAlreadyDefeatedCity = defender is CityCombatant && defender.isDefeated()
|
||||
@ -820,6 +821,7 @@ object Battle {
|
||||
}
|
||||
|
||||
private fun doWithdrawFromMeleeAbility(attacker: ICombatant, defender: ICombatant, baseWithdrawChance: Int): Boolean {
|
||||
if (baseWithdrawChance == 0) return false
|
||||
// Some notes...
|
||||
// unit.getUniques() is a union of BaseUnit uniques and Promotion effects.
|
||||
// according to some strategy guide the Slinger's withdraw ability is inherited on upgrade,
|
||||
|
@ -448,6 +448,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
|
||||
@Deprecated("as of 3.19.8", ReplaceWith("Eliminates combat penalty for attacking across a coast"))
|
||||
AttackFromSea("Eliminates combat penalty for attacking from the sea", UniqueTarget.Unit),
|
||||
AttackAcrossCoast("Eliminates combat penalty for attacking across a coast", UniqueTarget.Unit),
|
||||
AttackOnSea("May attack when embarked", UniqueTarget.Unit),
|
||||
|
||||
NoSight("No Sight", UniqueTarget.Unit),
|
||||
CanSeeOverObstacles("Can see over obstacles", UniqueTarget.Unit),
|
||||
|
@ -1010,6 +1010,9 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
|
||||
??? example "Eliminates combat penalty for attacking across a coast"
|
||||
Applicable to: Unit
|
||||
|
||||
??? example "May attack when embarked"
|
||||
Applicable to: Unit
|
||||
|
||||
??? example "No Sight"
|
||||
Applicable to: Unit
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user