Add IHasUniques.era() (#10593)

* Update IHasUniques.kt

* Update IHasUniques.kt

* Update IConstruction.kt

* Update IHasUniques.kt

* Update CivInfoTransientCache.kt

* Update UnitUpgradeManager.kt

* Update WonderOverviewTab.kt

* Update IHasUniques.kt
This commit is contained in:
dHannasch 2023-11-28 05:36:45 -07:00 committed by GitHub
parent 7162011d26
commit 03698e47ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 5 deletions

View File

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

View File

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

View File

@ -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<String> = if (requiredTech == null) sequenceOf() else sequenceOf(requiredTech!!)
override fun legacyRequiredTechs(): Sequence<String> = if (requiredTech == null) sequenceOf() else sequenceOf(requiredTech!!)
fun getProductionCost(civInfo: Civilization): Int
fun getStatBuyCost(city: City, stat: Stat): Int?

View File

@ -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<String> {
val uniquesForWhenThisIsAvailable: Sequence<Unique> = getMatchingUniques(UniqueType.OnlyAvailableWhen, StateForConditionals.IgnoreConditionals)
val conditionalsForWhenThisIsAvailable: Sequence<Unique> = uniquesForWhenThisIsAvailable.flatMap{ it.conditionals }
val techRequiringConditionalsForWhenThisIsAvailable: Sequence<Unique> = conditionalsForWhenThisIsAvailable.filter{ it.isOfType(UniqueType.ConditionalTech) }
return techRequiringConditionalsForWhenThisIsAvailable.map{ it.params[0] }
}
fun legacyRequiredTechs(): Sequence<String> = sequenceOf()
fun requiredTechs(): Sequence<String> = legacyRequiredTechs() + techsRequiredByUniques()
fun requiredTechnologies(ruleset: Ruleset): Sequence<Technology> =
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.
}

View File

@ -178,7 +178,7 @@ class WonderInfo {
val wonderEraMap: Map<String, Era?> =
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<Int, String> =