Converted policies up to Collective Rule

This commit is contained in:
Yair Morgenstern 2020-07-25 22:36:15 +03:00
parent a5f7aee1ea
commit 627283b10b
5 changed files with 58 additions and 36 deletions

View file

@ -2,10 +2,12 @@
{ {
"name": "Tradition", "name": "Tradition",
"era": "Ancient era", "era": "Ancient era",
"effect": "+3 culture in capital and increased rate of border expansion",
"uniques": ["+3 culture in capital", "Increased rate of border expansion"], "uniques": ["+3 culture in capital", "Increased rate of border expansion"],
"policies": [ "policies": [
{ {
"name": "Aristocracy", "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"], "uniques": ["+15% production when constructing wonders", "+1 happiness for every 10 citizens in a city"],
"row": 1, "row": 1,
"column": 1 "column": 1
@ -13,18 +15,21 @@
{ {
"name": "Legalism", "name": "Legalism",
"effect": "Immediately creates a cheapest available cultural building in each of your first 4 cities for free", "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, "row": 1,
"column": 3 "column": 3
}, },
{ {
"name": "Oligarchy", "name": "Oligarchy",
"effect": "Units in cities cost no Maintenance, garrisoned city +50% attacking strength", "effect": "Units in cities cost no Maintenance, garrisoned city +50% attacking strength",
"uniques": ["Units in cities cost no Maintenance"]
"row": 1, "row": 1,
"column": 5 "column": 5
}, },
{ {
"name": "Landed Elite", "name": "Landed Elite",
"effect": "+10% food growth and +2 food in capital", "effect": "+10% food growth and +2 food in capital",
"uniques": ["+10% food growth in capital", "[+2 Food] in capital"],
"requires": ["Legalism"], "requires": ["Legalism"],
"row": 2, "row": 2,
"column": 2 "column": 2
@ -32,13 +37,15 @@
{ {
"name": "Monarchy", "name": "Monarchy",
"effect": "+1 gold and -1 unhappiness for every 2 citizens in capital", "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"], "requires": ["Legalism"],
"row": 2, "row": 2,
"column": 4 "column": 4
}, },
{ {
"name": "Tradition Complete", "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", "name": "Liberty",
"era": "Ancient era", "era": "Ancient era",
"effect": "+1 culture in every city", "effect": "+1 culture in every city",
"uniques": ["[+1 Culture] in all cities"],
"policies": [ "policies": [
{ {
"name": "Collective Rule", "name": "Collective Rule",
"effect": "Training of settlers increased +50% in capital, receive a new settler near the capital", "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, "row": 1,
"column": 1 "column": 1
}, },

View file

@ -12,6 +12,8 @@ import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.ruleset.unit.UnitType import com.unciv.models.ruleset.unit.UnitType
import com.unciv.models.stats.Stat import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats import com.unciv.models.stats.Stats
import com.unciv.models.translations.equalsPlaceholderText
import com.unciv.models.translations.getPlaceholderParameters
class CityStats { class CityStats {
@ -164,9 +166,9 @@ class CityStats {
fun getGrowthBonusFromPolicies(): Float { fun getGrowthBonusFromPolicies(): Float {
var bonus = 0f 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 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 bonus += 0.15f
return bonus return bonus
} }
@ -264,10 +266,12 @@ class CityStats {
val stats = Stats() val stats = Stats()
if (adoptedPolicies.hasEffect("+3 culture in capital") && cityInfo.isCapital()) if (adoptedPolicies.hasEffect("+3 culture in capital") && cityInfo.isCapital())
stats.culture += 3f stats.culture += 3f
if (adoptedPolicies.hasEffect("+10% food growth and +2 food in capital") && cityInfo.isCapital()) for(effect in adoptedPolicies.policyEffects) {
stats.food += 2f if (effect.equalsPlaceholderText("[] in capital") && cityInfo.isCapital())
if (adoptedPolicies.hasEffect("+15% growth and +2 food in all cities")) stats.add(Stats.parse(effect.getPlaceholderParameters()[0]))
stats.food += 2f 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()) if (adoptedPolicies.hasEffect("+1 gold and -1 unhappiness for every 2 citizens in capital") && cityInfo.isCapital())
stats.gold += (cityInfo.population.population / 2).toFloat() stats.gold += (cityInfo.population.population / 2).toFloat()
if (adoptedPolicies.hasEffect("+1 culture in every city")) if (adoptedPolicies.hasEffect("+1 culture in every city"))

View file

@ -20,11 +20,10 @@ class CivInfoStats(val civInfo: CivilizationInfo){
val baseUnitCost = 0.5f val baseUnitCost = 0.5f
val freeUnits = 3 val freeUnits = 3
var unitsToPayFor = civInfo.getCivUnits() 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" // Only land military units can truly "garrison"
unitsToPayFor = unitsToPayFor.filterNot { unitsToPayFor = unitsToPayFor.filterNot {
it.getTile().isCityCenter() it.getTile().isCityCenter() && it.canGarrison()
&& it.canGarrison()
} }
var numberOfUnitsToPayFor = max(0f, unitsToPayFor.count().toFloat() - freeUnits) var numberOfUnitsToPayFor = max(0f, unitsToPayFor.count().toFloat() - freeUnits)

View file

@ -3,6 +3,10 @@ package com.unciv.logic.civilization
import com.unciv.Constants import com.unciv.Constants
import com.unciv.models.ruleset.Policy import com.unciv.models.ruleset.Policy
import com.unciv.models.ruleset.VictoryType 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.min
import kotlin.math.pow import kotlin.math.pow
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -126,10 +130,14 @@ class PolicyManager {
} }
val hasCapital = civInfo.cities.any { it.isCapital() } val hasCapital = civInfo.cities.any { it.isCapital() }
when (policy.effect) {
"Training of settlers increased +50% in capital, receive a new settler near the capital" -> for(effect in policy.uniques.withItem(policy.effect))
if (hasCapital && !civInfo.isOneCityChallenger()) when (effect.getPlaceholderText()) {
civInfo.placeUnitNearTile(civInfo.getCapital().location, Constants.settler) "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" -> "Tile improvement speed +25%, receive a free worker near the capital" ->
if (hasCapital) civInfo.placeUnitNearTile(civInfo.getCapital().location, Constants.worker) if (hasCapital) civInfo.placeUnitNearTile(civInfo.getCapital().location, Constants.worker)
"+1 culture for each monument, temple and monastery. Gain a free policy." -> freePolicies++ "+1 culture for each monument, temple and monastery. Gain a free policy." -> freePolicies++
@ -162,7 +170,7 @@ class PolicyManager {
} }
fun tryAddLegalismBuildings() { 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 return
if(legalismState.size >= 4) return if(legalismState.size >= 4) return

View file

@ -275,9 +275,11 @@ fun String.tr(): String {
return UncivGame.Current.translations.getText(this, UncivGame.Current.settings.language, activeMods) return UncivGame.Current.translations.getText(this, UncivGame.Current.settings.language, activeMods)
} }
fun String.getPlaceholderText() = this.replace(squareBraceRegex, "[]")
fun String.equalsPlaceholderText(str:String): Boolean { fun String.equalsPlaceholderText(str:String): Boolean {
if (first() != str.first()) return false // for quick negative return 95% of the time 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() fun String.getPlaceholderParameters() = squareBraceRegex.findAll(this).map { it.groups[1]!!.value }.toList()