From a765caa97c15f028fc94d32ede3108fbd632fdd2 Mon Sep 17 00:00:00 2001 From: Arthur van der Staaij <32672293+avdstaaij@users.noreply.github.com> Date: Thu, 3 Jun 2021 06:31:39 +0200 Subject: [PATCH] Add global alerts for certain constructions (#4039) * Add global alerts for certain constructions In the original game, certain constructions alert all players upon their completion. This commit introduces a new unique for this behavior and adds this unique to the relevant constructions. The code that implements the new unique is placed in Building.postBuildEvent, so it can only be activated by buildings. If other kinds of constructions require a global alert as well, the code could be moved to CityConstructions.constructionComplete. * Removed redundant line in template.properties * Moved global alert logic to CityConstructions Moved the implementation of "Triggers a global alert upon completion" from Building.postBuildEvent to CityConstructions.constructionComplete, close to the similar Wonder notification logic. --- android/assets/jsons/Civ V - Vanilla/Buildings.json | 12 ++++++------ .../assets/jsons/translations/template.properties | 2 ++ core/src/com/unciv/logic/city/CityConstructions.kt | 11 ++++++++++- core/src/com/unciv/models/ruleset/Building.kt | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Buildings.json b/android/assets/jsons/Civ V - Vanilla/Buildings.json index 3aa16f3845..0fff03ded6 100644 --- a/android/assets/jsons/Civ V - Vanilla/Buildings.json +++ b/android/assets/jsons/Civ V - Vanilla/Buildings.json @@ -937,7 +937,7 @@ { "name": "Manhattan Project", "isNationalWonder": true, - "uniques": ["Enables nuclear weapon"], + "uniques": ["Enables nuclear weapon", "Triggers a global alert upon completion"], "requiredTech": "Nuclear Fission" }, { @@ -1014,13 +1014,13 @@ "name": "SS Booster", "requiredResource": "Aluminum", "requiredTech": "Robotics", - "uniques": ["Spaceship part", "Cannot be purchased"] + "uniques": ["Spaceship part", "Triggers a global alert upon completion", "Cannot be purchased"] }, { "name": "Apollo Program", "cost": 1500, "isNationalWonder": true, - "uniques": ["Enables construction of Spaceship parts"], + "uniques": ["Enables construction of Spaceship parts", "Triggers a global alert upon completion"], "requiredTech": "Rocketry" }, @@ -1044,18 +1044,18 @@ "name": "SS Cockpit", "requiredResource": "Aluminum", "requiredTech": "Satellites", - "uniques": ["Spaceship part", "Cannot be purchased"] + "uniques": ["Spaceship part", "Triggers a global alert upon completion", "Cannot be purchased"] }, { "name": "SS Engine", "requiredResource": "Aluminum", "requiredTech": "Particle Physics", - "uniques": ["Spaceship part", "Cannot be purchased"] + "uniques": ["Spaceship part", "Triggers a global alert upon completion", "Cannot be purchased"] }, { "name": "SS Stasis Chamber", "requiredResource": "Aluminum", "requiredTech": "Nanotechnology", - "uniques": ["Spaceship part", "Cannot be purchased"] + "uniques": ["Spaceship part", "Triggers a global alert upon completion", "Cannot be purchased"] } ] diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 0be55ba60c..79a02d55fb 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -395,6 +395,8 @@ Cannot provide unit upkeep for [unitName] - unit has been disbanded! = [cityName] is starving! = [construction] has been built in [cityName] = [wonder] has been built in a faraway land = +[civName] has completed [construction]! = +An unknown civilization has completed [construction]! = Work has started on [construction] = [cityName] cannot continue work on [construction] = [cityName] has expanded its borders! = diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index e493fc9eb9..1d0c09d28c 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -347,7 +347,16 @@ class CityConstructions { cityInfo.civInfo.addNotification("[${construction.name}] has been built in [" + cityInfo.name + "]", cityInfo.location, NotificationIcon.Construction, icon) } - + if (construction is Building && "Triggers a global alert upon completion" in construction.uniques) { + for (otherCiv in cityInfo.civInfo.gameInfo.civilizations) { + // No need to notify ourself, since we already got the building notification anyway + if (otherCiv == cityInfo.civInfo) continue + val completingCivDescription = + if (otherCiv.knows(cityInfo.civInfo)) "[${cityInfo.civInfo.civName}]" else "An unknown civilization" + otherCiv.addNotification("$completingCivDescription has completed [${construction.name}]!", + NotificationIcon.Construction, buildingIcon) + } + } } fun addBuilding(buildingName: String) { diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index 6331e14713..9f1854483e 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -413,8 +413,8 @@ class Building : NamedStats(), IConstruction { civInfo.victoryManager.currentsSpaceshipParts.add(name, 1) return true } - cityConstructions.addBuilding(name) + cityConstructions.addBuilding(name) val improvement = getImprovement(civInfo.gameInfo.ruleSet) if (improvement != null) {