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:
Xander Lenstra
2022-03-31 22:06:42 +02:00
committed by GitHub
parent d87d83f686
commit d417556720
4 changed files with 11 additions and 5 deletions

View File

@ -92,8 +92,8 @@ object BattleHelper {
fun containsAttackableEnemy(tile: TileInfo, combatant: ICombatant): Boolean { fun containsAttackableEnemy(tile: TileInfo, combatant: ICombatant): Boolean {
if (combatant is MapUnitCombatant && combatant.unit.isEmbarked()) { if (combatant is MapUnitCombatant && combatant.unit.isEmbarked()) {
if (tile.isWater) return false // can't attack water units while embarked, only land // Can't attack water units while embarked, only land
if (combatant.isRanged()) return false if (tile.isWater || combatant.isRanged()) return combatant.hasUnique(UniqueType.AttackOnSea)
} }
val tileCombatant = Battle.getMapCombatantOfTile(tile) ?: return false val tileCombatant = Battle.getMapCombatantOfTile(tile) ?: return false

View File

@ -76,9 +76,10 @@ object Battle {
// Withdraw from melee ability // Withdraw from melee ability
if (attacker is MapUnitCombatant && attacker.isMelee() && defender is MapUnitCombatant) { if (attacker is MapUnitCombatant && attacker.isMelee() && defender is MapUnitCombatant) {
val withdraw = defender.unit.getMatchingUniques(UniqueType.MayWithdraw) val withdrawUniques = defender.unit.getMatchingUniques(UniqueType.MayWithdraw)
.sumOf{ it.params[0].toInt() } // If a mod allows multiple withdraw properties, ensure the best is used val baseWithdrawChance = 100-withdrawUniques.fold(100) { probability, unique -> probability * (100-unique.params[0].toInt()) }
if (withdraw != 0 && doWithdrawFromMeleeAbility(attacker, defender, withdraw)) return // 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() val isAlreadyDefeatedCity = defender is CityCombatant && defender.isDefeated()
@ -820,6 +821,7 @@ object Battle {
} }
private fun doWithdrawFromMeleeAbility(attacker: ICombatant, defender: ICombatant, baseWithdrawChance: Int): Boolean { private fun doWithdrawFromMeleeAbility(attacker: ICombatant, defender: ICombatant, baseWithdrawChance: Int): Boolean {
if (baseWithdrawChance == 0) return false
// Some notes... // Some notes...
// unit.getUniques() is a union of BaseUnit uniques and Promotion effects. // 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, // according to some strategy guide the Slinger's withdraw ability is inherited on upgrade,

View File

@ -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")) @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), AttackFromSea("Eliminates combat penalty for attacking from the sea", UniqueTarget.Unit),
AttackAcrossCoast("Eliminates combat penalty for attacking across a coast", 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), NoSight("No Sight", UniqueTarget.Unit),
CanSeeOverObstacles("Can see over obstacles", UniqueTarget.Unit), CanSeeOverObstacles("Can see over obstacles", UniqueTarget.Unit),

View File

@ -1010,6 +1010,9 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
??? example "Eliminates combat penalty for attacking across a coast" ??? example "Eliminates combat penalty for attacking across a coast"
Applicable to: Unit Applicable to: Unit
??? example "May attack when embarked"
Applicable to: Unit
??? example "No Sight" ??? example "No Sight"
Applicable to: Unit Applicable to: Unit