From 97def958174737540a19c9fbab755f0d754596f5 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 28 Jul 2020 19:56:57 +0300 Subject: [PATCH] Can now handle multiple civ-wide uniques of the same type! --- android/assets/jsons/Civ V - Vanilla/Policies.json | 2 ++ android/assets/jsons/Civ V - Vanilla/Units.json | 10 +++++----- core/src/com/unciv/logic/battle/Battle.kt | 2 +- .../com/unciv/logic/civilization/CivilizationInfo.kt | 11 +++++++++-- core/src/com/unciv/logic/map/MapUnit.kt | 4 +--- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Policies.json b/android/assets/jsons/Civ V - Vanilla/Policies.json index 6c13a31e..38d55254 100644 --- a/android/assets/jsons/Civ V - Vanilla/Policies.json +++ b/android/assets/jsons/Civ V - Vanilla/Policies.json @@ -139,6 +139,7 @@ { "name": "Professional Army", "effect": "Gold cost of upgrading military units reduced by 33%", + "uniques": ["Gold cost of upgrading military units reduced by 33%"], "requires": ["Military Caste"], "row": 3, "column": 4 @@ -146,6 +147,7 @@ { "name": "Honor Complete", "effect": "Gain gold for each unit killed" + "uniques": ["Gain gold for each unit killed"], } ] },{ diff --git a/android/assets/jsons/Civ V - Vanilla/Units.json b/android/assets/jsons/Civ V - Vanilla/Units.json index a74dcfb9..a716320e 100644 --- a/android/assets/jsons/Civ V - Vanilla/Units.json +++ b/android/assets/jsons/Civ V - Vanilla/Units.json @@ -1290,13 +1290,13 @@ { "name": "Great Artist", "unitType": "Civilian", - "uniques": ["Can start an 8-turn golden age","Can construct [Landmark]", "Unbuildable"], + "uniques": ["Can start an 8-turn golden age", "Can construct [Landmark]", "Unbuildable"], "movement": 2 }, { "name": "Great Scientist", "unitType": "Civilian", - "uniques": ["Can hurry technology research","Can construct [Academy]", "Unbuildable"], + "uniques": ["Can hurry technology research", "Can construct [Academy]", "Unbuildable"], "movement": 2 }, { @@ -1309,13 +1309,13 @@ { "name": "Great Engineer", "unitType": "Civilian", - "uniques": ["Can speed up construction of a wonder","Can construct [Manufactory]", "Unbuildable"], + "uniques": ["Can speed up construction of a wonder", "Can construct [Manufactory]", "Unbuildable"], "movement": 2 }, { "name": "Great General", "unitType": "Civilian", - "uniques": ["Can start an 8-turn golden age","Bonus for units in 2 tile radius 15%", "Can construct [Citadel]", "Unbuildable"], + "uniques": ["Can start an 8-turn golden age", "Bonus for units in 2 tile radius 15%", "Can construct [Citadel]", "Unbuildable"], "movement": 2 }, { @@ -1324,7 +1324,7 @@ "uniqueTo": "Mongolia", "replaces": "Great General", "uniques": ["Can start an 8-turn golden age","Bonus for units in 2 tile radius 15%", "Unbuildable", - "Heal adjacent units for an additional 15 HP per turn", "Can build improvement: Citadel"], + "Heal adjacent units for an additional 15 HP per turn", "Can construct [Citadel]"], "movement": 5 } ] diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 38bdc5b5..919e0b13 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -82,7 +82,7 @@ object Battle { tryGetCultureFromHonor(defender, attacker) if (defender.isDefeated() && defender is MapUnitCombatant && !defender.getUnitType().isCivilian() - && attacker.getCivInfo().policies.isAdopted("Honor Complete")) + && attacker.getCivInfo().hasUnique("Gain gold for each unit killed")) attacker.getCivInfo().gold += defender.unit.baseUnit.getProductionCost(attacker.getCivInfo()) / 10 if (attacker is MapUnitCombatant) { diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index a3b2785e..a89f1ba4 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -22,6 +22,7 @@ import com.unciv.models.ruleset.VictoryType import com.unciv.models.ruleset.tile.ResourceSupplyList import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.models.stats.Stats +import com.unciv.models.translations.equalsPlaceholderText import com.unciv.models.translations.tr import com.unciv.ui.victoryscreen.RankingType import java.util.* @@ -177,9 +178,15 @@ class CivilizationInfo { fun hasResource(resourceName:String): Boolean = getCivResourcesByName()[resourceName]!!>0 - fun hasUnique(unique:String) = policies.hasEffect(unique) - || cities.any { it.containsBuildingUnique(unique) } + private fun getCivUniques() = policies.policyEffects.asSequence() + cities.asSequence().flatMap { it.getBuildingUniques() } + // This is + fun hasUnique(unique:String) = getCivUniques().contains(unique) + + fun getMatchingUniques(uniqueTemplate: String) = + if (uniqueTemplate.contains('[')) + getCivUniques().filter { it.equalsPlaceholderText(uniqueTemplate) } + else getCivUniques().filter { it==uniqueTemplate } //region Units fun getCivUnits(): Sequence = units.asSequence() diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index fbf6fe2f..8ec029a1 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -263,9 +263,7 @@ class MapUnit { fun getCostOfUpgrade(): Int { val unitToUpgradeTo = getUnitToUpgradeTo() var goldCostOfUpgrade = (unitToUpgradeTo.cost - baseUnit().cost) * 2 + 10 - if (civInfo.policies.isAdopted("Professional Army")) - goldCostOfUpgrade = (goldCostOfUpgrade * 0.66f).toInt() - if(civInfo.hasUnique("Gold cost of upgrading military units reduced by 33%")) + for(unique in civInfo.getMatchingUniques("Gold cost of upgrading military units reduced by 33%")) goldCostOfUpgrade = (goldCostOfUpgrade * 0.66f).toInt() if(goldCostOfUpgrade<0) return 0 // For instance, Landsknecht costs less than Spearman, so upgrading would cost negative gold return goldCostOfUpgrade