Skip to content

Commit

Permalink
Resolved #12687 - Flank attack unique works with 'vs' conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Dec 22, 2024
1 parent 7eb642d commit efc0cf0
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions core/src/com/unciv/logic/battle/BattleDamage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ object BattleDamage {
private fun getGeneralModifiers(combatant: ICombatant, enemy: ICombatant, combatAction: CombatAction, tileToAttackFrom: Tile): Counter<String> {
val modifiers = Counter<String>()

val conditionalState = getStateForConditionals(combatAction, combatant, enemy)
val civInfo = combatant.getCivInfo()
val attackedTile =
if (combatAction == CombatAction.Attack) enemy.getTile()
else combatant.getTile()

val conditionalState = StateForConditionals(civInfo, city = (combatant as? CityCombatant)?.city, ourCombatant = combatant, theirCombatant = enemy,
attackedTile = attackedTile, combatAction = combatAction)

if (combatant is MapUnitCombatant) {

Expand Down Expand Up @@ -73,6 +68,26 @@ object BattleDamage {
return modifiers
}

private fun getStateForConditionals(
combatAction: CombatAction,
combatant: ICombatant,
enemy: ICombatant,
): StateForConditionals {
val attackedTile =
if (combatAction == CombatAction.Attack) enemy.getTile()
else combatant.getTile()

val conditionalState = StateForConditionals(
combatant.getCivInfo(),
city = (combatant as? CityCombatant)?.city,
ourCombatant = combatant,
theirCombatant = enemy,
attackedTile = attackedTile,
combatAction = combatAction
)
return conditionalState
}

private fun addUnitUniqueModifiers(combatant: MapUnitCombatant, enemy: ICombatant, conditionalState: StateForConditionals,
tileToAttackFrom: Tile, modifiers: Counter<String>) {
val civInfo = combatant.getCivInfo()
Expand Down Expand Up @@ -124,7 +139,7 @@ object BattleDamage {
defender: ICombatant, tileToAttackFrom: Tile
): Counter<String> {
val modifiers = getGeneralModifiers(attacker, defender, CombatAction.Attack, tileToAttackFrom)

if (attacker is MapUnitCombatant) {

addTerrainAttackModifiers(attacker, defender, tileToAttackFrom, modifiers)
Expand All @@ -143,7 +158,8 @@ object BattleDamage {
var flankingBonus = BattleConstants.BASE_FLANKING_BONUS

// e.g., Discipline policy - https://civilization.fandom.com/wiki/Discipline_(Civ5)
for (unique in attacker.unit.getMatchingUniques(UniqueType.FlankAttackBonus, checkCivInfoUniques = true))
for (unique in attacker.unit.getMatchingUniques(UniqueType.FlankAttackBonus, checkCivInfoUniques = true,
stateForConditionals = getStateForConditionals(CombatAction.Attack, attacker, defender)))
flankingBonus *= unique.params[0].toPercent()
modifiers["Flanking"] =
(flankingBonus * numberOfOtherAttackersSurroundingDefender).toInt()
Expand Down

0 comments on commit efc0cf0

Please sign in to comment.