From 8955d16e6a7c4d5c7ceaaecdc8036d88b3e0c066 Mon Sep 17 00:00:00 2001 From: SeventhM <127357473+SeventhM@users.noreply.github.com> Date: Mon, 28 Aug 2023 00:52:51 -0700 Subject: [PATCH] Fix promotions being available when they shouldn't (#9986) * Fix promotions being available when they shouldn't * Move unreachable code to the bottom * Remove unnecessary comment * Details for adopted nodes technically shouldn't be overriden * Add back in unreachable before we do checks * Just realized we're back to square one. Here's an actual fix --- .../com/unciv/ui/screens/pickerscreens/PromotionTree.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/ui/screens/pickerscreens/PromotionTree.kt b/core/src/com/unciv/ui/screens/pickerscreens/PromotionTree.kt index 05098fd2aa..72422dec68 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionTree.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionTree.kt @@ -118,7 +118,8 @@ class PromotionTree(val unit: MapUnit) { // Also determine preferredParent / pathIsAmbiguous by weighing distanceToAdopted for (node in allRoots()) { node.depth = 0 - node.distanceToAdopted = if (node.unreachable) Int.MAX_VALUE else if (node.isAdopted) 0 else 1 + node.distanceToAdopted = if (node.isAdopted) 0 + else if (node.unreachable) Int.MAX_VALUE else 1 } for (depth in 0..99) { var complete = true @@ -129,8 +130,9 @@ class PromotionTree(val unit: MapUnit) { } if (node.depth != depth) continue for (child in node.children) { - val distance = if (node.distanceToAdopted == Int.MAX_VALUE) Int.MAX_VALUE - else if (child.isAdopted) 0 else node.distanceToAdopted + 1 + val distance = if (child.isAdopted) 0 + else if (node.distanceToAdopted == Int.MAX_VALUE) Int.MAX_VALUE else if (child.unreachable) Int.MAX_VALUE + else node.distanceToAdopted + 1 when { child.depth == Int.MIN_VALUE -> Unit // "New" node / first reached child.distanceToAdopted < distance -> continue // Already reached a better way