Can now handle multiple civ-wide uniques of the same type!

This commit is contained in:
Yair Morgenstern 2020-07-28 19:56:57 +03:00
parent f583c04d38
commit 97def95817
5 changed files with 18 additions and 11 deletions

View file

@ -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"],
}
]
},{

View file

@ -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
}
]

View file

@ -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) {

View file

@ -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<MapUnit> = units.asSequence()

View file

@ -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