From 3e6cb2c80e949f3028ba96116a8ab780f1ec59eb Mon Sep 17 00:00:00 2001 From: General_E <121508218+Emandac@users.noreply.github.com> Date: Wed, 26 Feb 2025 20:06:53 +0100 Subject: [PATCH] Change save promotion from unitType to just baseUnit (#12960) * Settler settle best tile when not escort and dangerous Tiles instead of running away Settler unit will now settle on best tile in dangerous Tiles without escort instead of running away. * Update WorkerAutomation.kt * Update SpecificUnitAutomation.kt * Update WorkerAutomation.kt * Update SpecificUnitAutomation.kt * Now city states get mad when you steal their Lands * new version * change to getDiplomacyManagerOrMeet * added text to template.properties and changed AlertPopup.kt * Update template.properties * with period at the end :b * add flag now * Made Option to declare war when a city state is bullied unavailable * added option to change the Maximum Autosave turns stored * remove print * change letter * should fix issue with building test * update with changes * Added UniqueType.FoundPuppetCity with "Founds a new puppet city" in "uniques" of an unit in Units.json. Making it so you can now settle a puppet city. * Added save promotion * Updated for PR * Updated with requested changes * Removed unnecessary check * updated PR * Update PromotionPickerScreen.kt to save promotion cells too * change name and added ! * updated name of variable * updated version from unitType to BaseUnit * updated variable name * Added unitType to reduce the xp cost of promotions for all units in a civ This was a unique type that the Zulu have in civ 5 * updated name * remove UniqueTarget.FollowerBelief * Experience from to XP * fix ? * XP * change it back to Experience because it didn't want to build on git :( * back to XP then * update auto promotion and fix negative XP on unit * Fix build issues and remove the XPForPromotionModifier from xpForNextPromotion and xpForNextNPromotions * remove XPForPromotionModifier * re added Statuses and remove duplicate comment * remove some white space and 1 used import "com.unciv.ui.components.extensions.toPercent" * remove unique from uniques.md --- .../jsons/translations/template.properties | 2 +- core/src/com/unciv/logic/city/City.kt | 8 ++++---- .../com/unciv/logic/city/CityConstructions.kt | 16 ++++++++++------ .../unciv/logic/map/mapunit/UnitPromotions.kt | 2 +- .../cityscreen/ConstructionInfoTable.kt | 7 +++---- .../pickerscreens/PromotionPickerScreen.kt | 19 ++++++++++--------- 6 files changed, 29 insertions(+), 25 deletions(-) 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 } }