From 7fae32c59598ca7cbfb72d6e5bd1f01d8021b521 Mon Sep 17 00:00:00 2001 From: dHannasch Date: Sat, 2 Dec 2023 13:54:52 -0700 Subject: [PATCH] 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 --- .../civilization/diplomacy/CityStateFunctions.kt | 3 +-- .../com/unciv/models/ruleset/unique/IHasUniques.kt | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt index 169ffe64f3..45d864beec 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt @@ -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 } diff --git a/core/src/com/unciv/models/ruleset/unique/IHasUniques.kt b/core/src/com/unciv/models/ruleset/unique/IHasUniques.kt index 1dda45abaf..3c3906fba2 100644 --- a/core/src/com/unciv/models/ruleset/unique/IHasUniques.kt +++ b/core/src/com/unciv/models/ruleset/unique/IHasUniques.kt @@ -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 + } }