From c33b0a67fef504bba3f5e4f291ea43a4df95ebcf Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 17 Mar 2019 23:10:11 +0200 Subject: [PATCH] Resolved #586 - units now upgrade to the most recent upgrade, not to the next possible one --- core/src/com/unciv/logic/map/MapUnit.kt | 10 +++++----- core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 01c6f6f432..b020cc1aa8 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -214,12 +214,12 @@ class MapUnit { } fun getUnitToUpgradeTo(): BaseUnit { - var upgradedUnit = baseUnit().getUpgradeUnit(civInfo) + var unit = baseUnit() - // Go up the upgrade tree until you find the first one which isn't obsolete - while (upgradedUnit.obsoleteTech!=null && civInfo.tech.isResearched(upgradedUnit.obsoleteTech!!)) - upgradedUnit = upgradedUnit.getUpgradeUnit(civInfo) - return upgradedUnit + // Go up the upgrade tree until you find the last one which is buildable + while (unit.upgradesTo!=null && civInfo.tech.isResearched(unit.getDirectUpgradeUnit(civInfo).requiredTech!!)) + unit = unit.getDirectUpgradeUnit(civInfo) + return unit } fun canUpgrade(): Boolean { diff --git a/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt b/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt index 8793a3bc15..76b6550155 100644 --- a/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt @@ -138,7 +138,7 @@ class BaseUnit : INamed, IConstruction, ICivilopedia { unit.promotions.addPromotion("Drill I", isFree = true) } - fun getUpgradeUnit(civInfo: CivilizationInfo):BaseUnit{ + fun getDirectUpgradeUnit(civInfo: CivilizationInfo):BaseUnit{ val uniqueUnitReplacesUpgrade: BaseUnit? = GameBasics.Units.values .firstOrNull{it.uniqueTo==civInfo.civName && it.replaces == upgradesTo} if(uniqueUnitReplacesUpgrade!=null) return uniqueUnitReplacesUpgrade