Add iHasUniques.availableInEra() (#10594)

* Update IHasUniques.kt

* Update IHasUniques.kt

* Update IConstruction.kt

* Update IHasUniques.kt

* Update CivInfoTransientCache.kt

* Update UnitUpgradeManager.kt

* Update WonderOverviewTab.kt

* Update IHasUniques.kt

* Update IHasUniques.kt

* Update CityStateFunctions.kt

* Update CityStateFunctions.kt

* Update IHasUniques.kt

* Update CityStateFunctions.kt

* Update CityStateFunctions.kt

* Update CityStateFunctions.kt

* Update CityStateFunctions.kt
This commit is contained in:
dHannasch 2023-12-02 13:54:52 -07:00 committed by GitHub
parent 55a068d0a0
commit 7fae32c595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -52,8 +52,7 @@ class CityStateFunctions(val civInfo: Civilization) {
// Unique unit for militaristic city-states
if (uniqueTypes.contains(UniqueType.CityStateMilitaryUnits)) {
val possibleUnits = ruleset.units.values.filter {
val era = it.era(ruleset)
return@filter era != null && era.eraNumber > ruleset.eras[startingEra]!!.eraNumber // Not from the start era or before
return@filter !it.availableInEra(ruleset, startingEra) // Not from the start era or before
&& it.uniqueTo != null && it.uniqueTo in unusedMajorCivs // Must be from a major civ not in the game
&& ruleset.unitTypes[it.unitType]!!.isLandUnit() && (it.strength > 0 || it.rangedStrength > 0) // Must be a land military unit
}

View File

@ -63,4 +63,16 @@ interface IHasUniques : INamed {
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.
fun availableInEra(ruleset: Ruleset, requestedEra: String): Boolean {
val eraAvailable: Era? = era(ruleset)
if (eraAvailable == null)
// No technologies are required, so available in the starting era.
return true
// This is not very efficient, because era() inspects the eraNumbers and then returns the whole object.
// We could take a max of the eraNumbers directly.
// But it's unlikely to make any significant difference.
// Currently this is only used in CityStateFunctions.kt.
return eraAvailable.eraNumber <= ruleset.eras[requestedEra]!!.eraNumber
}
}