diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 925fd8b67b..07b2d6fc9e 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -114,7 +114,7 @@ Cannot be purchased = Can only be purchased = See also = Use default promotions = -Default promotions for [unitType] = +Default promotions for [unitName] = Statuses = Requires at least one of the following: = diff --git a/core/src/com/unciv/logic/city/City.kt b/core/src/com/unciv/logic/city/City.kt index 1dfab78de5..cda96355ee 100644 --- a/core/src/com/unciv/logic/city/City.kt +++ b/core/src/com/unciv/logic/city/City.kt @@ -93,9 +93,9 @@ class City : IsPartOfGameInfoSerialization, INamed { var isPuppet = false var shouldReassignPopulation = false // flag so that on startTurn() we reassign population - var unitTypeShouldUseSavedPromotion = HashMap() + var unitShouldUseSavedPromotion = HashMap() - var cityUnitTypePromotions = HashMap() + var unitToPromotions = HashMap() @delegate:Transient val neighboringCities: List by lazy { @@ -158,8 +158,8 @@ class City : IsPartOfGameInfoSerialization, INamed { toReturn.avoidGrowth = avoidGrowth toReturn.manualSpecialists = manualSpecialists toReturn.connectedToCapitalStatus = connectedToCapitalStatus - toReturn.unitTypeShouldUseSavedPromotion = unitTypeShouldUseSavedPromotion - toReturn.cityUnitTypePromotions = cityUnitTypePromotions + toReturn.unitShouldUseSavedPromotion = unitShouldUseSavedPromotion + toReturn.unitToPromotions = unitToPromotions return toReturn } diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 7d97a02fb1..712e1b5800 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -468,13 +468,17 @@ class CityConstructions : IsPartOfGameInfoSerialization { // checking if it's true that we should load saved promotion for the unitType // Check if the player want to rebuild the unit the saved promotion // and null check. - // and finally check if the current unit has enough XP. - val savedPromotion = city.cityUnitTypePromotions[unit.baseUnit.unitType] - if (city.unitTypeShouldUseSavedPromotion[unit.baseUnit.unitType] == true && + // and finally check if the current unit has enough XP. + val savedPromotion = city.unitToPromotions[unit.baseUnit.name] + if (city.unitShouldUseSavedPromotion[unit.baseUnit.name] == true && savedPromotion != null && unit.promotions.XP >= savedPromotion.XP) { - - for (promotions in savedPromotion.promotions) { - unit.promotions.addPromotion(promotions) + // sorting it to avoid getting Accuracy III before Accuracy I + for (promotions in savedPromotion.promotions.sorted()) { + if (unit.promotions.XP >= savedPromotion.XP) { + unit.promotions.addPromotion(promotions) + } else { + break + } } } } diff --git a/core/src/com/unciv/logic/map/mapunit/UnitPromotions.kt b/core/src/com/unciv/logic/map/mapunit/UnitPromotions.kt index f05a823f85..ffe8848cda 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitPromotions.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitPromotions.kt @@ -49,7 +49,7 @@ class UnitPromotions : IsPartOfGameInfoSerialization { /** @return the XP points needed to "buy" the next promotion. 10, 30, 60, 100, 150,... */ fun xpForNextPromotion() = (numberOfPromotions + 1) * 10 - + /** @return the XP points needed to "buy" the next [count] promotions. */ fun xpForNextNPromotions(count: Int) = (1..count).sumOf { (numberOfPromotions + it) * 10 } diff --git a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt index 35cf12005c..fdcba348db 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt @@ -101,13 +101,12 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { } } if (construction is BaseUnit) { - val unitType = construction.unitType - - val buildUnitWithPromotions = city.unitTypeShouldUseSavedPromotion[unitType] + val baseUnit = construction.name + val buildUnitWithPromotions = city.unitShouldUseSavedPromotion[baseUnit] if (buildUnitWithPromotions != null) { row() - add("Use default promotions".toCheckBox(buildUnitWithPromotions) {city.unitTypeShouldUseSavedPromotion[unitType] = it}).colspan(2).center() + add("Use default promotions".toCheckBox(buildUnitWithPromotions) {city.unitShouldUseSavedPromotion[baseUnit] = it}).colspan(2).center() } } } diff --git a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt index 89625cec3e..55e9042211 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt @@ -199,20 +199,21 @@ class PromotionPickerScreen private constructor( // adds the checkBoxs to choice to save unit promotion. private fun saveUnitTypePromotionForCity() { - val checkBoxSaveUnitPromotion = "Default promotions for [${unit.baseUnit.unitType}]".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it} + // if you are not in a city tile then don't show up + if (unit.currentTile.getCity() == null) return + val checkBoxSaveUnitPromotion = "Default promotions for [${unit.baseUnit.name}]".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it} promotionsTable.add(checkBoxSaveUnitPromotion) } // going to reuse this bit of code 2 time so turn it into a funtion private fun checkSaveUnitTypePrormotion() { - if (!saveUnitTypePromotion) { - val unitCurrentCity = unit.currentTile.getCity() - - if (unitCurrentCity != null) { - // If you are clicked the save unitType promotion, you want the next unitType to have the same promotion. - unitCurrentCity.unitTypeShouldUseSavedPromotion.put(unit.baseUnit.unitType,true) - unitCurrentCity.cityUnitTypePromotions.put(unit.baseUnit.unitType,unit.promotions) - } + if (!saveUnitTypePromotion) return + + val unitCurrentCity = unit.currentTile.getCity() + if (unitCurrentCity != null) { + // If you are clicked the save baseUnit promotion, you want the next baseUnit to have the same promotion. + unitCurrentCity.unitShouldUseSavedPromotion[unit.baseUnit.name] = true + unitCurrentCity.unitToPromotions[unit.baseUnit.name] = unit.promotions } }