diff --git a/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt b/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt index 6cf6c39d2b..827b41127e 100644 --- a/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt +++ b/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt @@ -47,8 +47,8 @@ class CivInfoTransientCache(val civInfo: Civilization) { val applicableBuildings = ruleset.buildings.values.filter { it.requiresResource(resource, StateForConditionals.IgnoreConditionals) && civInfo.getEquivalentBuilding(it) == it } val applicableUnits = ruleset.units.values.filter { it.requiresResource(resource, StateForConditionals.IgnoreConditionals) && civInfo.getEquivalentUnit(it) == it } - val lastEraForBuilding = applicableBuildings.maxOfOrNull { ruleset.eras[ruleset.technologies[it.requiredTech]?.era()]?.eraNumber ?: 0 } - val lastEraForUnit = applicableUnits.maxOfOrNull { ruleset.eras[ruleset.technologies[it.requiredTech]?.era()]?.eraNumber ?: 0 } + val lastEraForBuilding = applicableBuildings.maxOfOrNull { it.era(ruleset)?.eraNumber ?: 0 } + val lastEraForUnit = applicableUnits.maxOfOrNull { it.era(ruleset)?.eraNumber ?: 0 } if (lastEraForBuilding != null) lastEraResourceUsedForBuilding[resource] = lastEraForBuilding diff --git a/core/src/com/unciv/logic/map/mapunit/UnitUpgradeManager.kt b/core/src/com/unciv/logic/map/mapunit/UnitUpgradeManager.kt index c60eeea251..21fb6573f6 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitUpgradeManager.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitUpgradeManager.kt @@ -102,7 +102,7 @@ class UnitUpgradeManager(val unit:MapUnit) { // do clamping and rounding here so upgrading stepwise costs the same as upgrading far down the chain var stepCost = constants.base stepCost += (constants.perProduction * (baseUnit.cost - currentUnit.cost)).coerceAtLeast(0f) - val era = ruleset.eras[ruleset.technologies[baseUnit.requiredTech]?.era()] + val era = baseUnit.era(ruleset) if (era != null) stepCost *= (1f + era.eraNumber * constants.eraMultiplier) stepCost = (stepCost * civModifier).pow(constants.exponent) diff --git a/core/src/com/unciv/models/ruleset/IConstruction.kt b/core/src/com/unciv/models/ruleset/IConstruction.kt index 19bcf9ef37..50568db747 100644 --- a/core/src/com/unciv/models/ruleset/IConstruction.kt +++ b/core/src/com/unciv/models/ruleset/IConstruction.kt @@ -34,7 +34,7 @@ interface INonPerpetualConstruction : IConstruction, INamed, IHasUniques { @Deprecated("The functionality provided by the requiredTech field is provided by the OnlyAvailableWhen unique.") var requiredTech: String? - fun requiredTechs(): Sequence = if (requiredTech == null) sequenceOf() else sequenceOf(requiredTech!!) + override fun legacyRequiredTechs(): Sequence = if (requiredTech == null) sequenceOf() else sequenceOf(requiredTech!!) fun getProductionCost(civInfo: Civilization): Int fun getStatBuyCost(city: City, stat: Stat): Int? diff --git a/core/src/com/unciv/models/ruleset/unique/IHasUniques.kt b/core/src/com/unciv/models/ruleset/unique/IHasUniques.kt index e1733eba5e..1dda45abaf 100644 --- a/core/src/com/unciv/models/ruleset/unique/IHasUniques.kt +++ b/core/src/com/unciv/models/ruleset/unique/IHasUniques.kt @@ -1,5 +1,8 @@ package com.unciv.models.ruleset.unique +import com.unciv.models.ruleset.Ruleset +import com.unciv.models.ruleset.tech.Era +import com.unciv.models.ruleset.tech.Technology import com.unciv.models.stats.INamed /** @@ -42,4 +45,22 @@ interface IHasUniques : INamed { fun hasUnique(uniqueType: UniqueType, stateForConditionals: StateForConditionals? = null) = getMatchingUniques(uniqueType.placeholderText, stateForConditionals).any() + + fun techsRequiredByUniques(): Sequence { + val uniquesForWhenThisIsAvailable: Sequence = getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals) + val conditionalsForWhenThisIsAvailable: Sequence = uniquesForWhenThisIsAvailable.flatMap{ it.conditionals } + val techRequiringConditionalsForWhenThisIsAvailable: Sequence = conditionalsForWhenThisIsAvailable.filter{ it.isOfType(UniqueType.ConditionalTech) } + return techRequiringConditionalsForWhenThisIsAvailable.map{ it.params[0] } + } + + fun legacyRequiredTechs(): Sequence = sequenceOf() + + fun requiredTechs(): Sequence = legacyRequiredTechs() + techsRequiredByUniques() + + fun requiredTechnologies(ruleset: Ruleset): Sequence = + requiredTechs().map{ ruleset.technologies[it]!! } + + fun era(ruleset: Ruleset): Era? = + requiredTechnologies(ruleset).map{ it.era() }.map{ ruleset.eras[it]!! }.maxByOrNull{ it.eraNumber } + // This will return null only if requiredTechnologies() is empty. } diff --git a/core/src/com/unciv/ui/screens/overviewscreen/WonderOverviewTab.kt b/core/src/com/unciv/ui/screens/overviewscreen/WonderOverviewTab.kt index 66c64f8847..7da7c256db 100644 --- a/core/src/com/unciv/ui/screens/overviewscreen/WonderOverviewTab.kt +++ b/core/src/com/unciv/ui/screens/overviewscreen/WonderOverviewTab.kt @@ -178,7 +178,7 @@ class WonderInfo { val wonderEraMap: Map = ruleSet.buildings.values.asSequence() .filter { it.isWonder } - .associate { it.name to ruleSet.eras[ruleSet.technologies[it.requiredTech]?.era()] } + .associate { it.name to it.era(ruleSet) } // Maps all World Wonders by their position in sort order to their name val allWonderMap: Map =