From b69507255f0ec2f5c22c91f529f667076fa11594 Mon Sep 17 00:00:00 2001 From: Xander Lenstra <71121390+xlenstra@users.noreply.github.com> Date: Mon, 24 Jan 2022 18:52:35 +0100 Subject: [PATCH] Fixed the problems with the food carry-over unique (#6040) --- .../assets/jsons/Civ V - Gods & Kings/Buildings.json | 4 ++-- android/assets/jsons/Civ V - Vanilla/Buildings.json | 4 ++-- .../unciv/logic/automation/ConstructionAutomation.kt | 10 +++++++--- core/src/com/unciv/logic/city/PopulationManager.kt | 9 ++++++--- core/src/com/unciv/models/ruleset/unique/UniqueType.kt | 6 +++++- docs/uniques.md | 6 ++++-- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/android/assets/jsons/Civ V - Gods & Kings/Buildings.json b/android/assets/jsons/Civ V - Gods & Kings/Buildings.json index cd7d5b5f6b..41d161583d 100644 --- a/android/assets/jsons/Civ V - Gods & Kings/Buildings.json +++ b/android/assets/jsons/Civ V - Gods & Kings/Buildings.json @@ -398,7 +398,7 @@ "name": "Aqueduct", "maintenance": 1, "hurryCostModifier": 0, - "uniques": ["[40]% of food is carried over [in this city] after population increases"], + "uniques": ["[40]% Food is carried over after population increases [in this city]"], "requiredTech": "Engineering" }, { @@ -1022,7 +1022,7 @@ "requiredBuilding": "Hospital", "maintenance": 3, "requiredTech": "Pharmaceuticals", - "uniques": ["[25]% of food is carried over [in this city] after population increases"] + "uniques": ["[25]% Food is carried over after population increases [in this city]"] }, { "name": "Manhattan Project", diff --git a/android/assets/jsons/Civ V - Vanilla/Buildings.json b/android/assets/jsons/Civ V - Vanilla/Buildings.json index 037242b9f9..29c4d94023 100644 --- a/android/assets/jsons/Civ V - Vanilla/Buildings.json +++ b/android/assets/jsons/Civ V - Vanilla/Buildings.json @@ -351,7 +351,7 @@ "name": "Aqueduct", "maintenance": 1, "hurryCostModifier": 0, - "uniques": ["[40]% of food is carried over [in this city] after population increases"], + "uniques": ["[40]% Food is carried over after population increases [in this city]"], "requiredTech": "Engineering" }, { @@ -867,7 +867,7 @@ "requiredBuilding": "Hospital", "maintenance": 3, "requiredTech": "Pharmaceuticals", - "uniques": ["[25]% of food is carried over [in this city] after population increases"] + "uniques": ["[25]% Food is carried over after population increases [in this city]"] }, { "name": "Hydro Plant", diff --git a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt index 60a7be6a99..b24812b957 100644 --- a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt +++ b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt @@ -9,11 +9,11 @@ import com.unciv.logic.civilization.PlayerType import com.unciv.logic.map.BFS import com.unciv.models.ruleset.Building import com.unciv.models.ruleset.VictoryType +import com.unciv.models.ruleset.unique.StateForConditionals import com.unciv.models.ruleset.unique.UniqueType import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.stats.Stat import kotlin.math.max -import kotlin.math.min import kotlin.math.sqrt class ConstructionAutomation(val cityConstructions: CityConstructions){ @@ -325,10 +325,14 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ } private fun addFoodBuildingChoice() { + val conditionalState = StateForConditionals(civInfo, cityInfo) val foodBuilding = buildableNotWonders.asSequence() .filter { - (it.isStatRelated(Stat.Food) || it.hasUnique(UniqueType.CarryOverFood)) - && Automation.allowSpendingResource(civInfo, it) + (it.isStatRelated(Stat.Food) + || it.hasUnique(UniqueType.CarryOverFoodDeprecated, conditionalState) + || it.hasUnique(UniqueType.CarryOverFoodAlsoDeprecated, conditionalState) + || it.hasUnique(UniqueType.CarryOverFood, conditionalState) + ) && Automation.allowSpendingResource(civInfo, it) }.minByOrNull { it.cost } if (foodBuilding != null) { var modifier = 1f diff --git a/core/src/com/unciv/logic/city/PopulationManager.kt b/core/src/com/unciv/logic/city/PopulationManager.kt index 2305293704..bba13d0fd9 100644 --- a/core/src/com/unciv/logic/city/PopulationManager.kt +++ b/core/src/com/unciv/logic/city/PopulationManager.kt @@ -4,6 +4,7 @@ import com.unciv.logic.automation.Automation import com.unciv.logic.civilization.NotificationIcon import com.unciv.logic.map.TileInfo import com.unciv.models.Counter +import com.unciv.models.ruleset.unique.UniqueType import com.unciv.ui.utils.withItem import com.unciv.ui.utils.withoutItem import kotlin.math.floor @@ -61,9 +62,11 @@ class PopulationManager { } if (foodStored >= getFoodToNextPopulation()) { // growth! foodStored -= getFoodToNextPopulation() - var percentOfFoodCarriedOver = cityInfo - .getMatchingUniques("[]% of food is carried over [] after population increases") - .filter { cityInfo.matchesFilter(it.params[1]) } + var percentOfFoodCarriedOver = + (cityInfo.getMatchingUniques(UniqueType.CarryOverFood) + + cityInfo.getMatchingUniques(UniqueType.CarryOverFoodDeprecated) + + cityInfo.getMatchingUniques(UniqueType.CarryOverFoodAlsoDeprecated) + ).filter { cityInfo.matchesFilter(it.params[1]) } .sumOf { it.params[0].toInt() } // Try to avoid runaway food gain in mods, just in case if (percentOfFoodCarriedOver > 95) percentOfFoodCarriedOver = 95 diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 74302bce8d..ef683d18b4 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -147,7 +147,11 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: ProvidesResources("Provides [amount] [resource]", UniqueTarget.Improvement, UniqueTarget.Building), GrowthPercentBonus("[amount]% growth [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief), - CarryOverFood("[amount]% of food is carried over after population increases", UniqueTarget.Global, UniqueTarget.FollowerBelief), + CarryOverFood("[amount]% Food is carried over after population increases [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief), + @Deprecated("As of 3.19.2", ReplaceWith("[amount]% Food is carried over after population increases [cityFilter]")) + CarryOverFoodDeprecated("[amount]% of food is carried over after population increases", UniqueTarget.Global, UniqueTarget.FollowerBelief), + @Deprecated("As of 3.19.2", ReplaceWith("[amount]% Food is carried over after population increases [cityFilter]")) + CarryOverFoodAlsoDeprecated("[amount]% of food is carried over [cityFilter] after population increases", UniqueTarget.Global, UniqueTarget.FollowerBelief), GainFreeBuildings("Gain a free [buildingName] [cityFilter]", UniqueTarget.Global), diff --git a/docs/uniques.md b/docs/uniques.md index 8290146b46..9444e935be 100644 --- a/docs/uniques.md +++ b/docs/uniques.md @@ -182,8 +182,8 @@ Example: "[20]% growth [in all cities]" Applicable to: Global, FollowerBelief -#### [amount]% of food is carried over after population increases -Example: "[20]% of food is carried over after population increases" +#### [amount]% Food is carried over after population increases [cityFilter] +Example: "[20]% Food is carried over after population increases [in all cities]" Applicable to: Global, FollowerBelief @@ -1369,6 +1369,8 @@ Applicable to: Conditional - "City-State Influence degrades [amount]% slower" - Deprecated As of 3.18.17, replace with "[-amount]% City-State Influence degradation" - "Quantity of Resources gifted by City-States increased by [amount]%" - Deprecated As of 3.18.17, replace with "[+amount]% resources gifted by City-States" - "Happiness from Luxury Resources gifted by City-States increased by [amount]%" - Deprecated As of 3.18.17, replace with "[+amount]% Happiness from luxury resources gifted by City-States" + - "[amount]% of food is carried over after population increases" - Deprecated As of 3.19.2, replace with "[amount]% Food is carried over after population increases [cityFilter]" + - "[amount]% of food is carried over [cityFilter] after population increases" - Deprecated As of 3.19.2, replace with "[amount]% Food is carried over after population increases [cityFilter]" - "-[amount]% food consumption by specialists [cityFilter]" - Deprecated As of 3.18.2, replace with "[-amount]% Food consumption by specialists [cityFilter]" - "50% of excess happiness added to culture towards policies" - Deprecated As of 3.18.2, replace with "[50]% of excess happiness converted to [Culture]" - "-[amount]% Culture cost of acquiring tiles [cityFilter]" - Deprecated As of 3.19.1, replace with "[-amount] Culture cost of natural border growth [cityFilter]"