From 775f42aa0d1c821d363d677e253d9bee927a7a96 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 2 Aug 2021 21:07:08 +0300 Subject: [PATCH] Resolved #4629 - atomic bomb interception works as intended --- core/src/com/unciv/logic/battle/Battle.kt | 17 ++++++++--------- core/src/com/unciv/logic/city/CityInfo.kt | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 631276825f..b0e9b5ac49 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -44,7 +44,7 @@ object Battle { val attackedTile = defender.getTile() if (attacker is MapUnitCombatant && attacker.getUnitType().isAirUnit()) { - tryInterceptAirAttack(attacker, defender) + tryInterceptAirAttack(attacker, attackedTile, defender.getCivInfo()) if (attacker.isDefeated()) return } @@ -505,10 +505,10 @@ object Battle { } // Declare war on all potentially hit units. They'll try to intercept the nuke before it drops - for (hitUnit in hitTiles.map { it.getUnits() }.flatten()) { - tryDeclareWar(hitUnit.civInfo) + for(civWhoseUnitWasAttacked in hitTiles.flatMap { it.getUnits() }.map { it.civInfo }.distinct()) { + tryDeclareWar(civWhoseUnitWasAttacked) if (attacker.getUnitType().isAirUnit() && !attacker.isDefeated()) { - tryInterceptAirAttack(attacker, MapUnitCombatant(hitUnit)) + tryInterceptAirAttack(attacker, targetTile, civWhoseUnitWasAttacked) } } if (attacker.isDefeated()) return @@ -668,10 +668,9 @@ object Battle { } } - private fun tryInterceptAirAttack(attacker: MapUnitCombatant, defender: ICombatant) { + private fun tryInterceptAirAttack(attacker: MapUnitCombatant, attackedTile:TileInfo, interceptingCiv:CivilizationInfo) { if (attacker.unit.hasUnique("Cannot be intercepted")) return - val attackedTile = defender.getTile() - for (interceptor in defender.getCivInfo().getCivUnits().filter { it.canIntercept(attackedTile) }) { + for (interceptor in interceptingCiv.getCivUnits().filter { it.canIntercept(attackedTile) }) { if (Random().nextFloat() > 100f / interceptor.interceptChance()) continue var damage = BattleDamage.calculateDamageToDefender(MapUnitCombatant(interceptor), null, attacker) @@ -692,14 +691,14 @@ object Battle { attacker.getCivInfo() .addNotification("Our [$attackerName] was destroyed by an intercepting [$interceptorName]", interceptor.currentTile.position, attackerName, NotificationIcon.War, interceptorName) - defender.getCivInfo() + interceptingCiv .addNotification("Our [$interceptorName] intercepted and destroyed an enemy [$attackerName]", locations, interceptorName, NotificationIcon.War, attackerName) } else { attacker.getCivInfo() .addNotification("Our [$attackerName] was attacked by an intercepting [$interceptorName]", interceptor.currentTile.position, attackerName, NotificationIcon.War, interceptorName) - defender.getCivInfo() + interceptingCiv .addNotification("Our [$interceptorName] intercepted and attacked an enemy [$attackerName]", locations, interceptorName, NotificationIcon.War, attackerName) } diff --git a/core/src/com/unciv/logic/city/CityInfo.kt b/core/src/com/unciv/logic/city/CityInfo.kt index 9bbd2471c3..596948533a 100644 --- a/core/src/com/unciv/logic/city/CityInfo.kt +++ b/core/src/com/unciv/logic/city/CityInfo.kt @@ -121,7 +121,7 @@ class CityInfo { if (startingEra in ruleset.eras) { for (building in ruleset.eras[startingEra]!!.settlerBuildings) { if (ruleset.buildings[building]!!.isBuildable(cityConstructions)) { - cityConstructions.addBuilding(civInfo.getEquivalentBuilding(building).name) + try cityConstructions.addBuilding(civInfo.getEquivalentBuilding(building).name) } } }