@@ -471,20 +471,26 @@ class CityConstructions : IsPartOfGameInfoSerialization {
471
471
and do a null check.
472
472
and finally check if the current unit has enough XP. */
473
473
val possiblePromotions = hashSetOf<String >()
474
+ // to get promotion in order for nodes
475
+ val prmotionTreeOrder = mutableSetOf<String >()
474
476
475
477
/* Added all the possible Prmotion that the unit can be promoted,
476
478
to avoid edge case where upgrading a scout to spearman
477
479
whould give the rest of the spearman the "ignore terrain cost" promotion
478
480
when built with auto promotion. */
479
481
for (promotion in PromotionTree (unit).possiblePromotions) possiblePromotions.add(promotion.name)
482
+ for (roots in PromotionTree (unit).allNodes()) prmotionTreeOrder.add(roots.promotion.name)
483
+
480
484
val savedPromotion = city.unitToPromotions[unit.baseUnit.name]
481
485
482
486
if (city.unitShouldUseSavedPromotion[unit.baseUnit.name] == true &&
483
487
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) {
486
492
if (unit.promotions.XP >= savedPromotion.XP ) {
487
- unit.promotions.addPromotion(promotions)
493
+ if (promotions in possiblePromotionFilted) unit.promotions.addPromotion(promotions)
488
494
} else {
489
495
break
490
496
}
0 commit comments