From 86bbf54cc03c37c358d2b1092967f1b0178b7cab Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Tue, 14 Sep 2021 23:34:20 +0200 Subject: [PATCH] Civilopedia quickie: Units show other direction of upgrade path (#5209) * Civilopedia quickie: Units show other direction of upgrade path * Civilopedia quickie: Units show other direction of upgrade path - spacing --- .../jsons/translations/template.properties | 2 ++ .../com/unciv/models/ruleset/unit/BaseUnit.kt | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index e1c334e74e..43ac28a20d 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -953,6 +953,8 @@ Tutorials = Cost = May contain [listOfResources] = May contain: = +Can upgrade from [unit] = +Can upgrade from: = Upgrades to [upgradedUnit] = Obsolete with [obsoleteTech] = Occurs on [listOfTerrains] = diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index c67556c93e..91f62c567f 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -154,6 +154,24 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText { if (requiredTech != null || upgradesTo != null || obsoleteTech != null) textList += FormattedLine() if (requiredTech != null) textList += FormattedLine("Required tech: [$requiredTech]", link="Technology/$requiredTech") + + val canUpgradeFrom = ruleset.units + .filterValues { + (it.upgradesTo == name || it.upgradesTo != null && it.upgradesTo == replaces) + && (it.uniqueTo == uniqueTo || it.uniqueTo == null) + }.keys + if (canUpgradeFrom.isNotEmpty()) { + if (canUpgradeFrom.size == 1) + textList += FormattedLine("Can upgrade from [${canUpgradeFrom.first()}]", link = "Unit/${canUpgradeFrom.first()}") + else { + textList += FormattedLine() + textList += FormattedLine("Can upgrade from:") + for (unitName in canUpgradeFrom.sorted()) + textList += FormattedLine(unitName, indent = 2, link = "Unit/$unitName") + textList += FormattedLine() + } + } + if (upgradesTo != null) textList += FormattedLine("Upgrades to [$upgradesTo]", link="Unit/$upgradesTo") if (obsoleteTech != null) textList += FormattedLine("Obsolete with [$obsoleteTech]", link="Technology/$obsoleteTech")