From 627283b10b2b555b26fbe622d5e41d3b78ccad60 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 25 Jul 2020 22:36:15 +0300 Subject: [PATCH] Converted policies up to Collective Rule --- .../jsons/Civ V - Vanilla/Policies.json | 11 +++- core/src/com/unciv/logic/city/CityStats.kt | 16 +++-- .../unciv/logic/civilization/CivInfoStats.kt | 5 +- .../unciv/logic/civilization/PolicyManager.kt | 58 +++++++++++-------- .../unciv/models/translations/Translations.kt | 4 +- 5 files changed, 58 insertions(+), 36 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Policies.json b/android/assets/jsons/Civ V - Vanilla/Policies.json index 8127f30b..d9518cfd 100644 --- a/android/assets/jsons/Civ V - Vanilla/Policies.json +++ b/android/assets/jsons/Civ V - Vanilla/Policies.json @@ -2,10 +2,12 @@ { "name": "Tradition", "era": "Ancient era", + "effect": "+3 culture in capital and increased rate of border expansion", "uniques": ["+3 culture in capital", "Increased rate of border expansion"], "policies": [ { "name": "Aristocracy", + "effect": "+15% production when constructing wonders, +1 happiness for every 10 citizens in a city", "uniques": ["+15% production when constructing wonders", "+1 happiness for every 10 citizens in a city"], "row": 1, "column": 1 @@ -13,18 +15,21 @@ { "name": "Legalism", "effect": "Immediately creates a cheapest available cultural building in each of your first 4 cities for free", + "uniques":["Immediately creates a cheapest available cultural building in each of your first 4 cities for free"], "row": 1, "column": 3 }, { "name": "Oligarchy", "effect": "Units in cities cost no Maintenance, garrisoned city +50% attacking strength", + "uniques": ["Units in cities cost no Maintenance"] "row": 1, "column": 5 }, { "name": "Landed Elite", "effect": "+10% food growth and +2 food in capital", + "uniques": ["+10% food growth in capital", "[+2 Food] in capital"], "requires": ["Legalism"], "row": 2, "column": 2 @@ -32,13 +37,15 @@ { "name": "Monarchy", "effect": "+1 gold and -1 unhappiness for every 2 citizens in capital", + "uniques": ["+1 gold and -1 unhappiness for every 2 citizens in capital"], "requires": ["Legalism"], "row": 2, "column": 4 }, { "name": "Tradition Complete", - "effect": "+15% growth and +2 food in all cities" + "effect": "+15% growth and +2 food in all cities", + "uniques": ["+15% growth in all cities","[+2 Food] in all cities"] } ] }, @@ -46,10 +53,12 @@ "name": "Liberty", "era": "Ancient era", "effect": "+1 culture in every city", + "uniques": ["[+1 Culture] in all cities"], "policies": [ { "name": "Collective Rule", "effect": "Training of settlers increased +50% in capital, receive a new settler near the capital", + "uniques": ["Training of settlers increased +50% in capital", "Free [Settler] appears"] "row": 1, "column": 1 }, diff --git a/core/src/com/unciv/logic/city/CityStats.kt b/core/src/com/unciv/logic/city/CityStats.kt index aa5d1e32..1fe72a34 100644 --- a/core/src/com/unciv/logic/city/CityStats.kt +++ b/core/src/com/unciv/logic/city/CityStats.kt @@ -12,6 +12,8 @@ import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.ruleset.unit.UnitType import com.unciv.models.stats.Stat import com.unciv.models.stats.Stats +import com.unciv.models.translations.equalsPlaceholderText +import com.unciv.models.translations.getPlaceholderParameters class CityStats { @@ -164,9 +166,9 @@ class CityStats { fun getGrowthBonusFromPolicies(): Float { var bonus = 0f - if (cityInfo.civInfo.policies.hasEffect("+10% food growth and +2 food in capital") && cityInfo.isCapital()) + if (cityInfo.civInfo.hasUnique("+10% food growth in capital") && cityInfo.isCapital()) bonus += 0.1f - if (cityInfo.civInfo.policies.hasEffect("+15% growth and +2 food in all cities")) + if (cityInfo.civInfo.hasUnique("+15% growth in all cities")) bonus += 0.15f return bonus } @@ -264,10 +266,12 @@ class CityStats { val stats = Stats() if (adoptedPolicies.hasEffect("+3 culture in capital") && cityInfo.isCapital()) stats.culture += 3f - if (adoptedPolicies.hasEffect("+10% food growth and +2 food in capital") && cityInfo.isCapital()) - stats.food += 2f - if (adoptedPolicies.hasEffect("+15% growth and +2 food in all cities")) - stats.food += 2f + for(effect in adoptedPolicies.policyEffects) { + if (effect.equalsPlaceholderText("[] in capital") && cityInfo.isCapital()) + stats.add(Stats.parse(effect.getPlaceholderParameters()[0])) + else if(effect.equalsPlaceholderText("[] in all cities")) + stats.add(Stats.parse(effect.getPlaceholderParameters()[0])) + } if (adoptedPolicies.hasEffect("+1 gold and -1 unhappiness for every 2 citizens in capital") && cityInfo.isCapital()) stats.gold += (cityInfo.population.population / 2).toFloat() if (adoptedPolicies.hasEffect("+1 culture in every city")) diff --git a/core/src/com/unciv/logic/civilization/CivInfoStats.kt b/core/src/com/unciv/logic/civilization/CivInfoStats.kt index 11b50b49..6a6bab2f 100644 --- a/core/src/com/unciv/logic/civilization/CivInfoStats.kt +++ b/core/src/com/unciv/logic/civilization/CivInfoStats.kt @@ -20,11 +20,10 @@ class CivInfoStats(val civInfo: CivilizationInfo){ val baseUnitCost = 0.5f val freeUnits = 3 var unitsToPayFor = civInfo.getCivUnits() - if(civInfo.policies.hasEffect("Units in cities cost no Maintenance, garrisoned city +50% attacking strength")) + if(civInfo.hasUnique("Units in cities cost no Maintenance")) // Only land military units can truly "garrison" unitsToPayFor = unitsToPayFor.filterNot { - it.getTile().isCityCenter() - && it.canGarrison() + it.getTile().isCityCenter() && it.canGarrison() } var numberOfUnitsToPayFor = max(0f, unitsToPayFor.count().toFloat() - freeUnits) diff --git a/core/src/com/unciv/logic/civilization/PolicyManager.kt b/core/src/com/unciv/logic/civilization/PolicyManager.kt index 451775cd..4854b591 100644 --- a/core/src/com/unciv/logic/civilization/PolicyManager.kt +++ b/core/src/com/unciv/logic/civilization/PolicyManager.kt @@ -3,6 +3,10 @@ package com.unciv.logic.civilization import com.unciv.Constants import com.unciv.models.ruleset.Policy import com.unciv.models.ruleset.VictoryType +import com.unciv.models.translations.equalsPlaceholderText +import com.unciv.models.translations.getPlaceholderParameters +import com.unciv.models.translations.getPlaceholderText +import com.unciv.ui.utils.withItem import kotlin.math.min import kotlin.math.pow import kotlin.math.roundToInt @@ -126,32 +130,36 @@ class PolicyManager { } val hasCapital = civInfo.cities.any { it.isCapital() } - when (policy.effect) { - "Training of settlers increased +50% in capital, receive a new settler near the capital" -> - if (hasCapital && !civInfo.isOneCityChallenger()) - civInfo.placeUnitNearTile(civInfo.getCapital().location, Constants.settler) - "Tile improvement speed +25%, receive a free worker near the capital" -> - if (hasCapital) civInfo.placeUnitNearTile(civInfo.getCapital().location, Constants.worker) - "+1 culture for each monument, temple and monastery. Gain a free policy." -> freePolicies++ - "Each city founded increases culture cost of policies 33% less than normal. Starts a golden age.", - "+33% culture in all cities with a world wonder, immediately enter a golden age" -> - civInfo.goldenAges.enterGoldenAge() - "Free Great Person of choice near capital" -> { - if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++ - else { - val preferredVictoryType = civInfo.victoryType() - val greatPerson = when (preferredVictoryType) { - VictoryType.Cultural -> "Great Artist" - VictoryType.Scientific -> "Great Scientist" - VictoryType.Domination, VictoryType.Neutral -> - civInfo.gameInfo.ruleSet.units.keys.filter { it.startsWith("Great") }.random() - } - civInfo.addGreatPerson(greatPerson) + + for(effect in policy.uniques.withItem(policy.effect)) + when (effect.getPlaceholderText()) { + "Free [] appears" -> { + val unitName = effect.getPlaceholderParameters()[0] + if (hasCapital && (unitName != Constants.settler || !civInfo.isOneCityChallenger())) + civInfo.placeUnitNearTile(civInfo.getCapital().location, unitName) } + "Tile improvement speed +25%, receive a free worker near the capital" -> + if (hasCapital) civInfo.placeUnitNearTile(civInfo.getCapital().location, Constants.worker) + "+1 culture for each monument, temple and monastery. Gain a free policy." -> freePolicies++ + "Each city founded increases culture cost of policies 33% less than normal. Starts a golden age.", + "+33% culture in all cities with a world wonder, immediately enter a golden age" -> + civInfo.goldenAges.enterGoldenAge() + "Free Great Person of choice near capital" -> { + if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++ + else { + val preferredVictoryType = civInfo.victoryType() + val greatPerson = when (preferredVictoryType) { + VictoryType.Cultural -> "Great Artist" + VictoryType.Scientific -> "Great Scientist" + VictoryType.Domination, VictoryType.Neutral -> + civInfo.gameInfo.ruleSet.units.keys.filter { it.startsWith("Great") }.random() + } + civInfo.addGreatPerson(greatPerson) + } + } + "Quantity of strategic resources produced by the empire increased by 100%" -> civInfo.updateDetailedCivResources() + "+20% attack bonus to all Military Units for 30 turns" -> autocracyCompletedTurns = 30 } - "Quantity of strategic resources produced by the empire increased by 100%" -> civInfo.updateDetailedCivResources() - "+20% attack bonus to all Military Units for 30 turns" -> autocracyCompletedTurns = 30 - } tryAddLegalismBuildings() // This ALSO has the side-effect of updating the CivInfo statForNextTurn so we don't need to call it explicitly @@ -162,7 +170,7 @@ class PolicyManager { } fun tryAddLegalismBuildings() { - if(!civInfo.policies.hasEffect("Immediately creates a cheapest available cultural building in each of your first 4 cities for free")) + if(!civInfo.hasUnique("Immediately creates a cheapest available cultural building in each of your first 4 cities for free")) return if(legalismState.size >= 4) return diff --git a/core/src/com/unciv/models/translations/Translations.kt b/core/src/com/unciv/models/translations/Translations.kt index 556540c1..6b734c9e 100644 --- a/core/src/com/unciv/models/translations/Translations.kt +++ b/core/src/com/unciv/models/translations/Translations.kt @@ -275,9 +275,11 @@ fun String.tr(): String { return UncivGame.Current.translations.getText(this, UncivGame.Current.settings.language, activeMods) } +fun String.getPlaceholderText() = this.replace(squareBraceRegex, "[]") + fun String.equalsPlaceholderText(str:String): Boolean { if (first() != str.first()) return false // for quick negative return 95% of the time - return this.replace(squareBraceRegex, "[]") == str + return this.getPlaceholderText() == str } fun String.getPlaceholderParameters() = squareBraceRegex.findAll(this).map { it.groups[1]!!.value }.toList() \ No newline at end of file