From c764324e81de927f9ab2f18addc1f16d6ce1b6c1 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 17 Apr 2020 17:15:21 +0300 Subject: [PATCH] Unique units do not need to replace existing units --- .../automation/SpecificUnitAutomation.kt | 4 +- core/src/com/unciv/models/ruleset/Nation.kt | 47 ++++++++++--------- .../ui/newgamescreen/PlayerPickerTable.kt | 3 +- .../unciv/ui/worldscreen/unit/UnitActions.kt | 4 +- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt index e1b62056b9..1b59fc99d7 100644 --- a/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/SpecificUnitAutomation.kt @@ -61,7 +61,7 @@ object SpecificUnitAutomation { // try to build a citadel if (WorkerAutomation(unit).evaluateFortPlacement(unit.currentTile, unit.civInfo)) - UnitActions.getGreatPersonBuildImprovementAction(unit)?.action?.invoke() + UnitActions.getBuildImprovementAction(unit)?.action?.invoke() //if no unit to follow, take refuge in city or build citadel there. val reachableTest : (TileInfo) -> Boolean = {it.civilianUnit == null && @@ -189,7 +189,7 @@ object SpecificUnitAutomation { unit.movement.headTowards(chosenTile) if (unit.currentTile == chosenTile) - UnitActions.getGreatPersonBuildImprovementAction(unit)?.action?.invoke() + UnitActions.getBuildImprovementAction(unit)?.action?.invoke() return } } diff --git a/core/src/com/unciv/models/ruleset/Nation.kt b/core/src/com/unciv/models/ruleset/Nation.kt index 186d5e0585..4bcef718d4 100644 --- a/core/src/com/unciv/models/ruleset/Nation.kt +++ b/core/src/com/unciv/models/ruleset/Nation.kt @@ -123,27 +123,32 @@ class Nation : INamed { private fun addUniqueUnitsText(textList: ArrayList, ruleset: Ruleset) { for (unit in ruleset.units.values .filter { it.uniqueTo == name }) { - val originalUnit = ruleset.units[unit.replaces!!]!! - - textList += unit.name.tr() + " - "+"Replaces [${originalUnit.name}]".tr() - if (unit.cost != originalUnit.cost) - textList += " {Cost} " + "[${unit.cost}] vs [${originalUnit.cost}]".tr() - if (unit.strength != originalUnit.strength) - textList += " {Strength} " + "[${unit.strength}] vs [${originalUnit.strength}]".tr() - if (unit.rangedStrength != originalUnit.rangedStrength) - textList += " {Ranged strength} " + "[${unit.rangedStrength}] vs [${originalUnit.rangedStrength}]".tr() - if (unit.range != originalUnit.range) - textList += " {Range} " + "[${unit.range}] vs [${originalUnit.range}]".tr() - if (unit.movement != originalUnit.movement) - textList += " {Movement} " + "[${unit.movement}] vs [${originalUnit.movement}]".tr() - if (originalUnit.requiredResource != null && unit.requiredResource == null) - textList += " " + "[${originalUnit.requiredResource}] not required".tr() - for (unique in unit.uniques.filterNot { it in originalUnit.uniques }) - textList += " " + Translations.translateBonusOrPenalty(unique) - for (unique in originalUnit.uniques.filterNot { it in unit.uniques }) - textList += " " + "Lost ability".tr() + "(vs " + originalUnit.name.tr() + "): " + Translations.translateBonusOrPenalty(unique) - for (promotion in unit.promotions.filter { it !in originalUnit.promotions }) - textList += " " + promotion.tr() + " (" + Translations.translateBonusOrPenalty(ruleset.unitPromotions[promotion]!!.effect) + ")" + if(unit.replaces != null) { + val originalUnit = ruleset.units[unit.replaces!!]!! + textList += unit.name.tr() + " - " + "Replaces [${originalUnit.name}]".tr() + if (unit.cost != originalUnit.cost) + textList += " {Cost} " + "[${unit.cost}] vs [${originalUnit.cost}]".tr() + if (unit.strength != originalUnit.strength) + textList += " {Strength} " + "[${unit.strength}] vs [${originalUnit.strength}]".tr() + if (unit.rangedStrength != originalUnit.rangedStrength) + textList += " {Ranged strength} " + "[${unit.rangedStrength}] vs [${originalUnit.rangedStrength}]".tr() + if (unit.range != originalUnit.range) + textList += " {Range} " + "[${unit.range}] vs [${originalUnit.range}]".tr() + if (unit.movement != originalUnit.movement) + textList += " {Movement} " + "[${unit.movement}] vs [${originalUnit.movement}]".tr() + if (originalUnit.requiredResource != null && unit.requiredResource == null) + textList += " " + "[${originalUnit.requiredResource}] not required".tr() + for (unique in unit.uniques.filterNot { it in originalUnit.uniques }) + textList += " " + Translations.translateBonusOrPenalty(unique) + for (unique in originalUnit.uniques.filterNot { it in unit.uniques }) + textList += " " + "Lost ability".tr() + "(vs " + originalUnit.name.tr() + "): " + Translations.translateBonusOrPenalty(unique) + for (promotion in unit.promotions.filter { it !in originalUnit.promotions }) + textList += " " + promotion.tr() + " (" + Translations.translateBonusOrPenalty(ruleset.unitPromotions[promotion]!!.effect) + ")" + } + else { + textList += unit.name.tr() + textList += " " + unit.getDescription(true).split("\n").joinToString("\n ") + } textList += "" } diff --git a/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt b/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt index 39d2c0c488..e95320fe3a 100644 --- a/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt @@ -153,7 +153,8 @@ class PlayerPickerTable(val newGameScreen: NewGameScreen, val newGameParameters: nationListTable.add(randomPlayerTable).pad(10f).width(nationsPopupWidth).row() - for (nation in newGameScreen.ruleset.nations.values.filter { !it.isCityState() && it.name != "Barbarians" }) { + for (nation in newGameScreen.ruleset.nations.values + .filter { !it.isCityState() && it.name != "Barbarians" }) { if (player.chosenCiv != nation.name && newGameParameters.players.any { it.chosenCiv == nation.name }) continue diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index f464a2d1ce..ed38371dc1 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -346,11 +346,11 @@ object UnitActions { }.takeIf { canConductTradeMission }) } - val buildImprovementAction = getGreatPersonBuildImprovementAction(unit) + val buildImprovementAction = getBuildImprovementAction(unit) if (buildImprovementAction != null) actionList += buildImprovementAction } - fun getGreatPersonBuildImprovementAction(unit: MapUnit): UnitAction? { + fun getBuildImprovementAction(unit: MapUnit): UnitAction? { val tile = unit.currentTile for (unique in unit.getUniques().filter { it.startsWith("Can build improvement: ") }) { val improvementName = unique.replace("Can build improvement: ", "")