From 47e6b788af1c9d9855f6efdbe41f77e58f94f9d7 Mon Sep 17 00:00:00 2001 From: dHannasch Date: Mon, 4 Dec 2023 11:26:39 -0700 Subject: [PATCH] Add TechManager.isObsolete(unit) (#10659) * Update TechManager.kt * Update CityStateFunctions.kt --- .../unciv/logic/civilization/diplomacy/CityStateFunctions.kt | 2 +- core/src/com/unciv/logic/civilization/managers/TechManager.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt index 45d864beec..0ff3c967d0 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt @@ -94,7 +94,7 @@ class CityStateFunctions(val civInfo: Civilization) { ?: return null if (!receivingCiv.tech.isResearched(uniqueUnit)) return null - if (uniqueUnit.obsoleteTech != null && receivingCiv.tech.isResearched(uniqueUnit.obsoleteTech!!)) + if (receivingCiv.tech.isObsolete(uniqueUnit)) return null return uniqueUnit } diff --git a/core/src/com/unciv/logic/civilization/managers/TechManager.kt b/core/src/com/unciv/logic/civilization/managers/TechManager.kt index 07c65721ad..ffb5fe0c66 100644 --- a/core/src/com/unciv/logic/civilization/managers/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/managers/TechManager.kt @@ -157,6 +157,8 @@ class TechManager : IsPartOfGameInfoSerialization { fun isResearched(construction: INonPerpetualConstruction): Boolean = construction.requiredTechs().all{ requiredTech -> isResearched(requiredTech) } + fun isObsolete(unit: BaseUnit): Boolean = unit.techsThatObsoleteThis().any{ obsoleteTech -> isResearched(obsoleteTech) } + fun canBeResearched(techName: String): Boolean { val tech = getRuleset().technologies[techName]!! if (tech.uniqueObjects.any { it.type == UniqueType.OnlyAvailableWhen && !it.conditionalsApply(civInfo) })