Step 2 - started POC breakdown of policy effects to constituent uniques

This will allow mix&matching of policy effects, AND allow them to be used as building uniques as well!
This commit is contained in:
Yair Morgenstern 2020-07-24 18:18:17 +03:00
parent 937a832b2c
commit e7639c93c4
5 changed files with 12 additions and 8 deletions

View file

@ -2,11 +2,11 @@
{
"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
},

View file

@ -38,7 +38,7 @@ class CityExpansionManager {
cultureToNextTile *= 0.75 //Speciality of Angkor Wat
if (cityInfo.containsBuildingUnique("Culture and Gold costs of acquiring new tiles reduced by 25% in this city"))
cultureToNextTile *= 0.75 // Specialty of Krepost
if (cityInfo.civInfo.policies.isAdopted("Tradition")) cultureToNextTile *= 0.75
if (cityInfo.civInfo.hasUnique("Increased rate of border expansion")) cultureToNextTile *= 0.75
return cultureToNextTile.roundToInt()
}

View file

@ -205,7 +205,7 @@ class CityStats {
newHappinessList["Population"] = -unhappinessFromCitizens * unhappinessModifier
var happinessFromPolicies = 0f
if (civInfo.policies.hasEffect("+15% production when constructing wonders, +1 happiness for every 10 citizens in a city"))
if (civInfo.hasUnique("+1 happiness for every 10 citizens in a city"))
happinessFromPolicies += (cityInfo.population.population / 10).toFloat()
if (civInfo.policies.hasEffect("+1 gold and -1 unhappiness for every 2 citizens in capital")
&& cityInfo.isCapital())
@ -262,7 +262,7 @@ class CityStats {
private fun getStatsFromPolicies(adoptedPolicies: PolicyManager): Stats {
val stats = Stats()
if (adoptedPolicies.hasEffect("+3 culture in capital and increased rate of border expansion") && cityInfo.isCapital())
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
@ -346,7 +346,7 @@ class CityStats {
stats.science += 15f
if (policies.contains("Total War") && currentConstruction is BaseUnit && !currentConstruction.unitType.isCivilian())
stats.production += 15f
if (policies.contains("Aristocracy")
if (cityInfo.civInfo.hasUnique("+15% production when constructing wonders")
&& currentConstruction is Building
&& currentConstruction.isWonder)
stats.production += 15f

View file

@ -36,10 +36,12 @@ class PolicyManager {
return toReturn
}
fun getPolicyByName(name:String): Policy = getAllPolicies().first { it.name==name }
fun setTransients(){
val allPolicies = getAllPolicies()
val effectsOfCurrentPolicies = adoptedPolicies.map { adoptedPolicy -> allPolicies.first { it.name==adoptedPolicy }.effect }
val effectsOfCurrentPolicies = adoptedPolicies.map { getPolicyByName(it).effect }
policyEffects.addAll(effectsOfCurrentPolicies)
adoptedPolicies.map { getPolicyByName(it).uniques }.forEach { policyEffects.addAll(it) }
}
private fun getAllPolicies() = civInfo.gameInfo.ruleSet.policyBranches.values.asSequence()
@ -114,6 +116,7 @@ class PolicyManager {
adoptedPolicies.add(policy.name)
policyEffects.add(policy.effect)
policyEffects.addAll(policy.uniques)
if (!branchCompletion) {
val branch = policy.branch

View file

@ -7,6 +7,7 @@ open class Policy : INamed {
override lateinit var name: String
lateinit var effect: String
var uniques: ArrayList<String> = ArrayList()
var row: Int = 0
var column: Int = 0
var requires: ArrayList<String>? = null