Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add AutomaticallyUpgradesInProduction Unique #10654

4 changes: 2 additions & 2 deletions core/src/com/unciv/logic/civilization/managers/TechManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ class TechManager : IsPartOfGameInfoSerialization {
return civInfo.getEquivalentUnit(upgradesTo!!)
}
val obsoleteUnits = getRuleset().units.asSequence()
.filter { it.value.isObsoletedBy(techName) }
.map { it.key to it.value.getEquivalentUpgradeOrNull() }
.filter { it.value.getEquivalentAutoUpgradeOrNull(civInfo, techName) != null }
.map { it.key to it.value.getEquivalentAutoUpgradeOrNull(civInfo, techName) }
.toMap()
if (obsoleteUnits.isEmpty()) return

Expand Down
1 change: 1 addition & 0 deletions core/src/com/unciv/models/ruleset/unique/UniqueType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ enum class UniqueType(

UnitMaintenanceDiscount("[relativeAmount]% maintenance costs", UniqueTarget.Unit, UniqueTarget.Global),
UnitUpgradeCost("[relativeAmount]% Gold cost of upgrading", UniqueTarget.Unit, UniqueTarget.Global),
AutomaticallyUpgradesInProduction("In-production automatically upgrades to [unit] retaining invested production when [tech] is discovered", UniqueTarget.Unit),

// Gains from battle
DamageUnitsPlunder("Earn [amount]% of the damage done to [combatantFilter] units as [civWideStat]", UniqueTarget.Unit, UniqueTarget.Global),
Expand Down
18 changes: 18 additions & 0 deletions core/src/com/unciv/models/ruleset/unit/BaseUnit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,24 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
return true
}

fun automaticallyUpgradedInProductionByTech(techName: String): String? {
val autoUpgrades: List<String> = getMatchingUniques(UniqueType.AutomaticallyUpgradesInProduction, StateForConditionals.IgnoreConditionals)
.filter{ it.params[1] == techName }
.map{ it.params[0] }.filterNotNull().toList() + if(obsoleteTech != null && obsoleteTech == techName && upgradesTo != null) listOf(upgradesTo!!) else listOf()
if (autoUpgrades.size > 1)
throw Exception("$this appears to automatically upgrade to more than one unit at $techName.")
if (autoUpgrades.size == 0)
return null
return autoUpgrades[0]
}

fun getEquivalentAutoUpgradeOrNull(civInfo: Civilization, techName: String): BaseUnit? {
val upgradeNameOrNull: String? = automaticallyUpgradedInProductionByTech(techName)
if (upgradeNameOrNull == null)
return null
return civInfo.getEquivalentUnit(upgradeNameOrNull!!)
}

fun addConstructionBonuses(unit: MapUnit, cityConstructions: CityConstructions) {
val civInfo = cityConstructions.city.civ

Expand Down
Loading