mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 15:27:27 +07:00
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:
parent
55a068d0a0
commit
7fae32c595
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user