From 920d81959591c51b47cf593877e326073a613a2d Mon Sep 17 00:00:00 2001 From: Oskar Niesen Date: Tue, 26 Sep 2023 06:47:13 -0500 Subject: [PATCH] Fix Nuke Notification (#10167) * Added notifications to Civs that didn't have tiles hit by nuke * Changed notifications based on if the nuke fails to detonate * Moved nuke notifications above unit hit notification * Added translations for new messages * Moved a line of code back to preserve original order * Changed notification messages --- .../jsons/translations/template.properties | 5 ++- core/src/com/unciv/logic/battle/Battle.kt | 37 +++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 62ec6c2a72..94646493a9 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -929,7 +929,10 @@ Your city [cityName] can bombard the enemy! = [amount] of your cities can bombard the enemy! = [amount] enemy units were spotted near our territory = [amount] enemy units were spotted in our territory = -A(n) [nukeType] exploded in our territory! = +A(n) [nukeType] from [civName] has exploded in our territory! = +A(n) [nukeType] has been detonated by [civName]! = +A(n) [nukeType] has been detonated by an unkown civilization! = +After an attempted attack by our [nukeType], [civName] has declared war on us! = After being hit by our [nukeType], [civName] has declared war on us! = The civilization of [civName] has been destroyed! = The City-State of [name] has been destroyed! = diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index f766ac7298..f5c55e62ab 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -8,8 +8,10 @@ import com.unciv.logic.automation.unit.SpecificUnitAutomation import com.unciv.logic.city.City import com.unciv.logic.civilization.AlertType import com.unciv.logic.civilization.Civilization +import com.unciv.logic.civilization.CivilopediaAction import com.unciv.logic.civilization.LocationAction import com.unciv.logic.civilization.MapUnitAction +import com.unciv.logic.civilization.NotificationAction import com.unciv.logic.civilization.NotificationCategory import com.unciv.logic.civilization.NotificationIcon import com.unciv.logic.civilization.PlayerType @@ -787,13 +789,14 @@ object Battle { @Suppress("FunctionName") // Yes we want this name to stand out fun NUKE(attacker: MapUnitCombatant, targetTile: Tile) { val attackingCiv = attacker.getCivInfo() + val notifyDeclaredWarCivs = ArrayList() fun tryDeclareWar(civSuffered: Civilization) { if (civSuffered != attackingCiv && civSuffered.knows(attackingCiv) && civSuffered.getDiplomacyManager(attackingCiv).diplomaticStatus != DiplomaticStatus.War ) { attackingCiv.getDiplomacyManager(civSuffered).declareWar() - attackingCiv.addNotification("After being hit by our [${attacker.getName()}], [${civSuffered}] has declared war on us!", targetTile.position, NotificationCategory.Diplomacy, NotificationIcon.War) + if (!notifyDeclaredWarCivs.contains(civSuffered)) notifyDeclaredWarCivs.add(civSuffered) } } @@ -805,10 +808,11 @@ object Battle { // Calculate the tiles that are hit val hitTiles = targetTile.getTilesInDistance(blastRadius) - + + val hitCivsTerritory = ArrayList() // Declare war on the owners of all hit tiles for (hitCiv in hitTiles.mapNotNull { it.getOwner() }.distinct()) { - hitCiv.addNotification("A(n) [${attacker.getName()}] exploded in our territory!", targetTile.position, NotificationCategory.War, NotificationIcon.War) + hitCivsTerritory.add(hitCiv) tryDeclareWar(hitCiv) } @@ -822,7 +826,18 @@ object Battle { tryInterceptAirAttack(attacker, targetTile, civWhoseUnitWasAttacked, null) } } - if (attacker.isDefeated()) return + val nukeNotificationAction = sequenceOf( LocationAction(targetTile.position), CivilopediaAction("Units/" + attacker.getName())) + // If the nuke has been intercepted and destroyed then it fails to detonate + if (attacker.isDefeated()) { + // Notify attacker that they are now at war for the attempt + for (defendingCiv in notifyDeclaredWarCivs) + attackingCiv.addNotification("After an attempted attack by our [${attacker.getName()}], [${defendingCiv}] has declared war on us!", nukeNotificationAction, NotificationCategory.Diplomacy, defendingCiv.civName, NotificationIcon.War, attacker.getName()) + return + } + + // Notify attacker that they are now at war + for (defendingCiv in notifyDeclaredWarCivs) + attackingCiv.addNotification("After being hit by our [${attacker.getName()}], [${defendingCiv}] has declared war on us!", nukeNotificationAction, NotificationCategory.Diplomacy, defendingCiv.civName, NotificationIcon.War, attacker.getName()) attacker.unit.attacksSinceTurnStart.add(Vector2(targetTile.position)) @@ -831,6 +846,20 @@ object Battle { doNukeExplosionForTile(attacker, tile, nukeStrength, targetTile == tile) } + // Message all other civs + for (otherCiv in attackingCiv.gameInfo.civilizations) { + if (!otherCiv.isAlive() || otherCiv == attackingCiv) continue + if (hitCivsTerritory.contains(otherCiv)) + otherCiv.addNotification("A(n) [${attacker.getName()}] from [${attackingCiv.civName}] has exploded in our territory!", + nukeNotificationAction, NotificationCategory.War, attackingCiv.civName, NotificationIcon.War, attacker.getName()) + else if (otherCiv.knows(attackingCiv)) + otherCiv.addNotification("A(n) [${attacker.getName()}] has been detonated by [${attackingCiv.civName}]!", + nukeNotificationAction, NotificationCategory.War, attackingCiv.civName, NotificationIcon.War, attacker.getName()) + else + otherCiv.addNotification("A(n) [${attacker.getName()}] has been detonated by an unkown civilization!", + nukeNotificationAction, NotificationCategory.War, NotificationIcon.War, attacker.getName()) + } + // Instead of postBattleAction() just destroy the unit, all other functions are not relevant if (attacker.unit.hasUnique(UniqueType.SelfDestructs)) attacker.unit.destroy()