Resolved #586 - units now upgrade to the most recent upgrade, not to the next possible one

This commit is contained in:
Yair Morgenstern
2019-03-17 23:10:11 +02:00
parent f1f3753231
commit c33b0a67fe
2 changed files with 6 additions and 6 deletions

View File

@ -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 {

View File

@ -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