Skip to content

Commit a22d081

Browse files
committed
Now applying auto promotion in a using promotion tree Node
1 parent e86ffe7 commit a22d081

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

core/src/com/unciv/logic/city/CityConstructions.kt

+9-3
Original file line numberDiff line numberDiff line change
@@ -471,20 +471,26 @@ class CityConstructions : IsPartOfGameInfoSerialization {
471471
and do a null check.
472472
and finally check if the current unit has enough XP. */
473473
val possiblePromotions = hashSetOf<String>()
474+
// to get promotion in order for nodes
475+
val prmotionTreeOrder = mutableSetOf<String>()
474476

475477
/* Added all the possible Prmotion that the unit can be promoted,
476478
to avoid edge case where upgrading a scout to spearman
477479
whould give the rest of the spearman the "ignore terrain cost" promotion
478480
when built with auto promotion. */
479481
for (promotion in PromotionTree(unit).possiblePromotions) possiblePromotions.add(promotion.name)
482+
for (roots in PromotionTree(unit).allNodes()) prmotionTreeOrder.add(roots.promotion.name)
483+
480484
val savedPromotion = city.unitToPromotions[unit.baseUnit.name]
481485

482486
if (city.unitShouldUseSavedPromotion[unit.baseUnit.name] == true &&
483487
savedPromotion != null && unit.promotions.XP >= savedPromotion.XP) {
484-
// sort it to avoid getting Accuracy III before Accuracy I
485-
for (promotions in savedPromotion.promotions.sorted().filter { it in possiblePromotions }) {
488+
// this variable is the filted promotion from savedPrmotion to only get promotion that are possible for this unit.
489+
val possiblePromotionFilted = savedPromotion.promotions.sorted().filter { it in possiblePromotions }
490+
// sort in order to avoid getting Accuracy III before Accuracy I
491+
for (promotions in prmotionTreeOrder) {
486492
if (unit.promotions.XP >= savedPromotion.XP) {
487-
unit.promotions.addPromotion(promotions)
493+
if (promotions in possiblePromotionFilted) unit.promotions.addPromotion(promotions)
488494
} else {
489495
break
490496
}

0 commit comments

Comments
 (0)