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
This commit is contained in:
Oskar Niesen 2023-09-26 06:47:13 -05:00 committed by GitHub
parent 1ec83c62bd
commit 920d819595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 5 deletions

View File

@ -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! =

View File

@ -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<Civilization>()
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)
}
}
@ -806,9 +809,10 @@ object Battle {
// Calculate the tiles that are hit
val hitTiles = targetTile.getTilesInDistance(blastRadius)
val hitCivsTerritory = ArrayList<Civilization>()
// 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()