From 5d6765a879ac994842a56a3eb29902ea1da9c56a Mon Sep 17 00:00:00 2001 From: yairm210 Date: Wed, 22 Sep 2021 18:31:13 +0300 Subject: [PATCH] Resolved crash in unit civilopedia lines that depended on unitType being initialized --- .../com/unciv/models/ruleset/unit/BaseUnit.kt | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index fa69ed76e1..f097e1f9a7 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -116,7 +116,7 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText { stats += "$rangedStrength${Fonts.rangedStrength}" stats += "$range${Fonts.range}" } - if (movement != 0 && !movesLikeAirUnits()) stats += "$movement${Fonts.movement}" + if (movement != 0 && ruleset.unitTypes[unitType]?.isAirUnit() != true) stats += "$movement${Fonts.movement}" if (stats.isNotEmpty()) textList += FormattedLine(stats.joinToString(", ")) @@ -143,28 +143,39 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText { for ((resource, amount) in resourceRequirements) { textList += FormattedLine( if (amount == 1) "Consumes 1 [$resource]" else "Consumes [$amount] [$resource]", - link="Resource/$resource", color="#F42") + link = "Resource/$resource", color = "#F42" + ) } } if (uniqueTo != null) { textList += FormattedLine() - textList += FormattedLine("Unique to [$uniqueTo]", link="Nation/$uniqueTo") + textList += FormattedLine("Unique to [$uniqueTo]", link = "Nation/$uniqueTo") if (replaces != null) - textList += FormattedLine("Replaces [$replaces]", link="Unit/$replaces", indent=1) + textList += FormattedLine( + "Replaces [$replaces]", + link = "Unit/$replaces", + indent = 1 + ) } if (requiredTech != null || upgradesTo != null || obsoleteTech != null) textList += FormattedLine() - if (requiredTech != null) textList += FormattedLine("Required tech: [$requiredTech]", link="Technology/$requiredTech") + 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) + && (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()}") + textList += FormattedLine( + "Can upgrade from [${canUpgradeFrom.first()}]", + link = "Unit/${canUpgradeFrom.first()}" + ) else { textList += FormattedLine() textList += FormattedLine("Can upgrade from:") @@ -174,28 +185,35 @@ class BaseUnit : INamed, INonPerpetualConstruction, ICivilopediaText { } } - if (upgradesTo != null) textList += FormattedLine("Upgrades to [$upgradesTo]", link="Unit/$upgradesTo") - if (obsoleteTech != null) textList += FormattedLine("Obsolete with [$obsoleteTech]", link="Technology/$obsoleteTech") + if (upgradesTo != null) textList += FormattedLine( + "Upgrades to [$upgradesTo]", + link = "Unit/$upgradesTo" + ) + if (obsoleteTech != null) textList += FormattedLine( + "Obsolete with [$obsoleteTech]", + link = "Technology/$obsoleteTech" + ) if (promotions.isNotEmpty()) { textList += FormattedLine() promotions.withIndex().forEach { textList += FormattedLine( - when { - promotions.size == 1 -> "{Free promotion:} " - it.index == 0 -> "{Free promotions:} " - else -> "" - } + "{${it.value}}" + - (if (promotions.size == 1 || it.index == promotions.size - 1) "" else ","), - link="Promotions/${it.value}", - indent=if(it.index==0) 0 else 1) + when { + promotions.size == 1 -> "{Free promotion:} " + it.index == 0 -> "{Free promotions:} " + else -> "" + } + "{${it.value}}" + + (if (promotions.size == 1 || it.index == promotions.size - 1) "" else ","), + link = "Promotions/${it.value}", + indent = if (it.index == 0) 0 else 1 + ) } } val seeAlso = ArrayList() for ((other, unit) in ruleset.units) { - if (unit.replaces == name || uniques.contains("[$name]") ) { - seeAlso += FormattedLine(other, link="Unit/$other", indent=1) + if (unit.replaces == name || uniques.contains("[$name]")) { + seeAlso += FormattedLine(other, link = "Unit/$other", indent = 1) } } if (seeAlso.isNotEmpty()) {