From 9e089bd91dee2b12bcd170b9c289841c6670f9e8 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 3 Oct 2023 13:15:00 +0300 Subject: [PATCH] chore: Simplified interception notifications --- .../com/unciv/logic/battle/AirInterception.kt | 49 +++++++++++-------- core/src/com/unciv/logic/battle/Nuke.kt | 2 - 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/core/src/com/unciv/logic/battle/AirInterception.kt b/core/src/com/unciv/logic/battle/AirInterception.kt index 066ad611e6..c982cf0442 100644 --- a/core/src/com/unciv/logic/battle/AirInterception.kt +++ b/core/src/com/unciv/logic/battle/AirInterception.kt @@ -53,18 +53,14 @@ object AirInterception { .shuffled() // randomize Civ .sortedByDescending { it.interceptChance() }) { // No chance of Interceptor to miss (unlike regular Interception). Always want to deal damage - val interceptingCiv = interceptor.civ - val interceptorName = interceptor.name // pairs of LocationAction for Notification val locations = LocationAction( interceptor.currentTile.position, attacker.unit.currentTile.position ) - val locationsInterceptorUnknown = - LocationAction(attackedTile.position, attacker.unit.currentTile.position) - interceptor.attacksThisTurn++ // even if you miss, you took the shot if (!interceptor.baseUnit.isAirUnit()) { + val interceptorName = interceptor.name // Deal no damage (moddable in future?) and no XP val attackerText = "Our [$attackerName] ([-0] HP) was attacked by an intercepting [$interceptorName] ([-0] HP)" @@ -74,7 +70,7 @@ object AirInterception { attackerText, locations, NotificationCategory.War, attackerName, NotificationIcon.War, interceptorName ) - interceptingCiv.addNotification( + interceptor.civ.addNotification( interceptorText, locations, NotificationCategory.War, interceptorName, NotificationIcon.War, attackerName ) @@ -89,14 +85,14 @@ object AirInterception { Battle.addXp(MapUnitCombatant(interceptor), 5, attacker) Battle.addXp(attacker, 5, MapUnitCombatant(interceptor)) - addInterceptionNotifications( + val locationsInterceptorUnknown = + LocationAction(attackedTile.position, attacker.unit.currentTile.position) + + addAirSweepInterceptionNotifications( attacker, interceptor, - attackerName, damageDealt, - interceptorName, locationsInterceptorUnknown, - interceptingCiv, locations ) attacker.unit.action = null @@ -109,16 +105,17 @@ object AirInterception { attacker.unit.action = null } - private fun addInterceptionNotifications( + // TODO: Check overlap with addInterceptionNotifications, and unify what we can + private fun addAirSweepInterceptionNotifications( attacker: MapUnitCombatant, interceptor: MapUnit, - attackerName: String, damageDealt: Battle.DamageDealt, - interceptorName: String, locationsInterceptorUnknown: Sequence, - interceptingCiv: Civilization, locations: Sequence ) { + val attackerName = attacker.getName() + val interceptorName = interceptor.name + val attackerText = if (attacker.isDefeated()) { if (interceptor.getTile() in attacker.getCivInfo().viewableTiles) @@ -137,11 +134,11 @@ object AirInterception { if (attacker.isDefeated()) "Our [$interceptorName] ([-${damageDealt.attackerDealt}] HP) intercepted and destroyed an enemy [$attackerName] ([-${damageDealt.defenderDealt}] HP)" else if (MapUnitCombatant(interceptor).isDefeated()) { - if (attacker.getTile() in interceptingCiv.viewableTiles) "Our [$interceptorName] ([-${damageDealt.attackerDealt}] HP) intercepted and was destroyed by an enemy [$attackerName] ([-${damageDealt.defenderDealt}] HP)" + if (attacker.getTile() in interceptor.civ.viewableTiles) "Our [$interceptorName] ([-${damageDealt.attackerDealt}] HP) intercepted and was destroyed by an enemy [$attackerName] ([-${damageDealt.defenderDealt}] HP)" else "Our [$interceptorName] ([-${damageDealt.attackerDealt}] HP) intercepted and was destroyed by an unknown enemy" } else "Our [$interceptorName] ([-${damageDealt.attackerDealt}] HP) intercepted and attacked an enemy [$attackerName] ([-${damageDealt.defenderDealt}] HP)" - interceptingCiv.addNotification( + interceptor.civ.addNotification( interceptorText, locations, NotificationCategory.War, interceptorName, NotificationIcon.War, attackerName ) @@ -189,10 +186,20 @@ object AirInterception { if (damage > 0) Battle.addXp(MapUnitCombatant(interceptor), 2, attacker) + addInterceptionNotifications(attacker, interceptor, damage) + + return Battle.DamageDealt(0, damage) + } + + private fun addInterceptionNotifications( + attacker: MapUnitCombatant, + interceptor: MapUnit, + damage: Int + ) { val attackerName = attacker.getName() val interceptorName = interceptor.name - val locations = LocationAction(interceptor.currentTile.position, attacker.unit.currentTile.position) + val locations = LocationAction(interceptor.currentTile.position, attacker.unit.currentTile.position) val attackerText = if (!attacker.isDefeated()) "Our [$attackerName] ([-$damage] HP) was attacked by an intercepting [$interceptorName] ([-0] HP)" else if (interceptor.getTile() in attacker.getCivInfo().viewableTiles) @@ -207,10 +214,10 @@ object AirInterception { val interceptorText = if (attacker.isDefeated()) "Our [$interceptorName] ([-0] HP) intercepted and destroyed an enemy [$attackerName] ([-$damage] HP)" else "Our [$interceptorName] ([-0] HP) intercepted and attacked an enemy [$attackerName] ([-$damage] HP)" - interceptingCiv.addNotification(interceptorText, locations, NotificationCategory.War, - interceptorName, NotificationIcon.War, attackerName) - - return Battle.DamageDealt(0, damage) + interceptor.civ.addNotification( + interceptorText, locations, NotificationCategory.War, + interceptorName, NotificationIcon.War, attackerName + ) } } diff --git a/core/src/com/unciv/logic/battle/Nuke.kt b/core/src/com/unciv/logic/battle/Nuke.kt index 02837802ab..6983082ab1 100644 --- a/core/src/com/unciv/logic/battle/Nuke.kt +++ b/core/src/com/unciv/logic/battle/Nuke.kt @@ -301,8 +301,6 @@ object Nuke { targetedCity.population.addPopulation(-populationLoss) } - - private fun City.getAggregateModifier(uniqueType: UniqueType): Float { var modifier = 1f for (unique in getMatchingUniques(uniqueType)) {