From f89765354a74768eef6e55b0cb9312cbcb5d6cfe Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 15 Mar 2023 19:19:35 +0200 Subject: [PATCH] Resolved #8901 - Modding: Units from triggers respect "limited to [amount] per civilization" limits --- .../ruleset/unique/UniqueTriggerActivation.kt | 14 +++++++++++++ docs/Modders/uniques.md | 20 +++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt index 61bc521353..3fe99db8d6 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt @@ -58,6 +58,11 @@ object UniqueTriggerActivation { || unit.hasUnique(UniqueType.FoundCity) && civInfo.isOneCityChallenger()) return false + val limit = unit.getMatchingUniques(UniqueType.MaxNumberBuildable) + .map { it.params[0].toInt() }.minOrNull() + if (limit!=null && limit <= civInfo.units.getCivUnits().count { it.name==unitName }) + return false + val placedUnit = civInfo.units.addUnit(unitName, chosenCity) ?: return false val notificationText = getNotificationText(notification, triggerNotificationText, @@ -78,6 +83,15 @@ object UniqueTriggerActivation { if (chosenCity == null || unit == null || (unit.hasUnique(UniqueType.FoundCity) && civInfo.isOneCityChallenger())) return false + val limit = unit.getMatchingUniques(UniqueType.MaxNumberBuildable) + .map { it.params[0].toInt() }.minOrNull() + val amountFromTriggerable = unique.params[0].toInt() + val actualAmount = + if (limit==null) amountFromTriggerable + else civInfo.units.getCivUnits().count { it.name==unitName } - limit + + if (actualAmount <= 0) return false + val tilesUnitsWerePlacedOn: MutableList = mutableListOf() for (i in 1..unique.params[0].toInt()) { val placedUnit = civInfo.units.addUnit(unitName, chosenCity) diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index 9178239d54..9d0989d016 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -92,6 +92,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Applicable to: Triggerable +??? example "Reveal up to [amount/'all'] [tileFilter] within a [amount] tile radius" + Example: "Reveal up to [3] [Farm] within a [3] tile radius" + + Applicable to: Triggerable + ??? example "Triggers the following global alert: [comment]" Example: "Triggers the following global alert: [comment]" @@ -121,10 +126,13 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl ??? example "This Unit gains [amount] XP" Example: "This Unit gains [3] XP" - Applicable to: UnitTriggerable, Ruins + Applicable to: UnitTriggerable ??? example "This Unit upgrades for free" - Applicable to: UnitTriggerable, Global + Applicable to: UnitTriggerable + +??? example "This Unit upgrades for free including special upgrades" + Applicable to: UnitTriggerable ??? example "This Unit gains the [promotion] promotion" Example: "This Unit gains the [Shock I] promotion" @@ -1625,19 +1633,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Applicable to: Ruins -??? example "Reveal up to [amount/'all'] [tileFilter] within a [amount] tile radius" - Example: "Reveal up to [3] [Farm] within a [3] tile radius" - - Applicable to: Ruins - ??? example "From a randomly chosen tile [amount] tiles away from the ruins, reveal tiles up to [amount] tiles away with [amount]% chance" Example: "From a randomly chosen tile [3] tiles away from the ruins, reveal tiles up to [3] tiles away with [3]% chance" Applicable to: Ruins -??? example "This Unit upgrades for free including special upgrades" - Applicable to: Ruins - ??? example "Hidden after generating a Great Prophet" Applicable to: Ruins