From 9dd38f5d08dc390cf14a1c0391e3112d18af3411 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Tue, 22 Oct 2024 21:27:28 +0200 Subject: [PATCH 01/27] 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. --- .../logic/automation/unit/SpecificUnitAutomation.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt index 20241c0cbf9aa..da1c6ac410070 100644 --- a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt @@ -192,6 +192,16 @@ object SpecificUnitAutomation { } unit.movement.headTowards(bestCityLocation) + + // This if setement is to check if settler is on the bast tile and has no escort unit and its in a dangerous Tiles and can still move. + // then settle there + if (bestTilesInfo.tileRankMap.containsKey(unit.getTile()) && unit.getOtherEscortUnit() == null && dangerousTiles.contains(unit.getTile()) + && unit.hasMovement()) { + foundCityAction.action.invoke() + return + } + + if (unit.getTile() == bestCityLocation && unit.hasMovement()) foundCityAction.action.invoke() } From 919a08269e94f1ca34d01b7692d0c0c94d660510 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:43:47 +0100 Subject: [PATCH 02/27] Update WorkerAutomation.kt --- .../com/unciv/logic/automation/unit/WorkerAutomation.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt index dfb125254efd7..ec042aecca01a 100644 --- a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt @@ -232,7 +232,7 @@ class WorkerAutomation( if (!tile.hasViewableResource(civInfo) && tile.getTilesInDistance(civInfo.gameInfo.ruleset.modOptions.constants.cityWorkRange) .none { it.isCityCenter() && it.getCity()?.civ == civInfo } ) return false - if (tile.getTileImprovement()?.hasUnique(UniqueType.AutomatedUnitsWillNotReplace) == true) return false + if (tile.getTileImprovement()?.hasUnique(UniqueType.AutomatedUnitsWillNotReplace) == true && !tile.isPillaged()) return false return true } @@ -248,6 +248,7 @@ class WorkerAutomation( var priority = 0f if (tile.getOwner() == civInfo) { priority += Automation.rankStatsValue(tile.stats.getTerrainStatsBreakdown().toStats(), civInfo) + if (tile.providesYield()) priority += 2 if (tile.isPillaged()) priority += 1 if (tile.hasFalloutEquivalent()) priority += 1 @@ -270,8 +271,6 @@ class WorkerAutomation( tileRankings[tile] = TileImprovementRank(priority) return priority + unitSpecificPriority } - - /** * Calculates the priority building the improvement on the tile */ @@ -296,6 +295,7 @@ class WorkerAutomation( if (tile.improvement != null && tile.isPillaged() && tile.owningCity != null) { // Value repairing higher when it is quicker and is in progress + var repairBonusPriority = tile.getImprovementToRepair()!!.getTurnsToBuild(unit.civ,unit) - UnitActionsFromUniques.getRepairTurns(unit) if (tile.improvementInProgress == Constants.repair) repairBonusPriority += UnitActionsFromUniques.getRepairTurns(unit) - tile.turnsToImprovement @@ -307,6 +307,7 @@ class WorkerAutomation( } } } + // A better tile than this unit can build might have been stored in the cache if (!rank.repairImprovment!! && (rank.bestImprovement == null || !unit.canBuildImprovement(rank.bestImprovement!!, tile))) return -100f From ed21943b2c9285b415164529d309ad87c5274793 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Wed, 30 Oct 2024 20:29:08 +0100 Subject: [PATCH 03/27] Update SpecificUnitAutomation.kt --- .../logic/automation/unit/SpecificUnitAutomation.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt index da1c6ac410070..f399c90116137 100644 --- a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt @@ -190,18 +190,8 @@ object SpecificUnitAutomation { throw Exception("City within distance") return } - unit.movement.headTowards(bestCityLocation) - // This if setement is to check if settler is on the bast tile and has no escort unit and its in a dangerous Tiles and can still move. - // then settle there - if (bestTilesInfo.tileRankMap.containsKey(unit.getTile()) && unit.getOtherEscortUnit() == null && dangerousTiles.contains(unit.getTile()) - && unit.hasMovement()) { - foundCityAction.action.invoke() - return - } - - if (unit.getTile() == bestCityLocation && unit.hasMovement()) foundCityAction.action.invoke() } From b9a832a1ed94dfdcc26f3215ee43275bedf4815f Mon Sep 17 00:00:00 2001 From: General_E <121508218+Emandac@users.noreply.github.com> Date: Wed, 30 Oct 2024 20:32:22 +0100 Subject: [PATCH 04/27] Update WorkerAutomation.kt --- core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt index ec042aecca01a..efa4befd77288 100644 --- a/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/WorkerAutomation.kt @@ -248,7 +248,6 @@ class WorkerAutomation( var priority = 0f if (tile.getOwner() == civInfo) { priority += Automation.rankStatsValue(tile.stats.getTerrainStatsBreakdown().toStats(), civInfo) - if (tile.providesYield()) priority += 2 if (tile.isPillaged()) priority += 1 if (tile.hasFalloutEquivalent()) priority += 1 @@ -295,7 +294,6 @@ class WorkerAutomation( if (tile.improvement != null && tile.isPillaged() && tile.owningCity != null) { // Value repairing higher when it is quicker and is in progress - var repairBonusPriority = tile.getImprovementToRepair()!!.getTurnsToBuild(unit.civ,unit) - UnitActionsFromUniques.getRepairTurns(unit) if (tile.improvementInProgress == Constants.repair) repairBonusPriority += UnitActionsFromUniques.getRepairTurns(unit) - tile.turnsToImprovement @@ -307,7 +305,6 @@ class WorkerAutomation( } } } - // A better tile than this unit can build might have been stored in the cache if (!rank.repairImprovment!! && (rank.bestImprovement == null || !unit.canBuildImprovement(rank.bestImprovement!!, tile))) return -100f From 5edf4b7c911ba663b95ca6793c1804ffbcef7349 Mon Sep 17 00:00:00 2001 From: General_E <121508218+Emandac@users.noreply.github.com> Date: Wed, 30 Oct 2024 20:33:25 +0100 Subject: [PATCH 05/27] Update SpecificUnitAutomation.kt --- .../com/unciv/logic/automation/unit/SpecificUnitAutomation.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt index f399c90116137..9104fe1be8d27 100644 --- a/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/SpecificUnitAutomation.kt @@ -191,7 +191,6 @@ object SpecificUnitAutomation { return } unit.movement.headTowards(bestCityLocation) - if (unit.getTile() == bestCityLocation && unit.hasMovement()) foundCityAction.action.invoke() } From aaabab0dcf2e023d294b882fc30cdb040f15eaa9 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Mon, 30 Dec 2024 23:40:50 +0100 Subject: [PATCH 06/27] Now city states get mad when you steal their Lands --- core/src/com/unciv/logic/civilization/PopupAlert.kt | 1 + .../civilization/diplomacy/CityStateFunctions.kt | 11 +++++++++++ .../logic/civilization/diplomacy/DiplomacyManager.kt | 1 + .../com/unciv/ui/screens/worldscreen/AlertPopup.kt | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/core/src/com/unciv/logic/civilization/PopupAlert.kt b/core/src/com/unciv/logic/civilization/PopupAlert.kt index 86ccefc16e2fd..18bddc61ba17d 100644 --- a/core/src/com/unciv/logic/civilization/PopupAlert.kt +++ b/core/src/com/unciv/logic/civilization/PopupAlert.kt @@ -11,6 +11,7 @@ enum class AlertType : IsPartOfGameInfoSerialization { CityConquered, CityTraded, BorderConflict, + BorderOccupation, DemandToStopSettlingCitiesNear, CitySettledNearOtherCivDespiteOurPromise, diff --git a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt index 1c97c9fbe6862..691fa4f42268a 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt @@ -540,6 +540,17 @@ class CityStateFunctions(val civInfo: Civilization) { diplomacy.setFlag(DiplomacyFlags.BorderConflict, 10) } } + + // If citystate gets tile stolen from another civ, then the civ gets a diplomacy Influence debuffer. + if (diplomacy.hasModifier(DiplomaticModifiers.StealingTerritory) && diplomacy.isRelationshipLevelLT(RelationshipLevel.Friend)) { + diplomacy.addInfluence(-25f) + if (!diplomacy.hasFlag(DiplomacyFlags.BorderOccupation)) { + otherCiv.popupAlerts.add(PopupAlert(AlertType.BorderOccupation, civInfo.civName)) + + // to only show popup once. + diplomacy.setFlag(DiplomacyFlags.BorderOccupation, -1) + } + } } } diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index 2b1b4c04b8b9c..0cb06977023f0 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -52,6 +52,7 @@ enum class DiplomacyFlags { DeclinedJoinWarOffer, ResearchAgreement, BorderConflict, + BorderOccupation, SettledCitiesNearUs, AgreedToNotSettleNearUs, diff --git a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt index ac60c032b259f..8826c222850eb 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt @@ -91,6 +91,7 @@ class AlertPopup( AlertType.CityConquered -> addCityConquered() AlertType.CityTraded -> addCityTraded() AlertType.BorderConflict -> addBorderConflict() + AlertType.BorderOccupation -> addBorderOccupation() AlertType.DemandToStopSettlingCitiesNear -> addDemandToStopSettlingCitiesNear() AlertType.CitySettledNearOtherCivDespiteOurPromise -> addCitySettledNearOtherCivDespiteOurPromise() AlertType.DemandToStopSpreadingReligion -> addDemandToStopSpreadingReligion() @@ -118,6 +119,14 @@ class AlertPopup( addCloseButton("Sorry.", KeyboardBinding.Confirm) addCloseButton("Never!", KeyboardBinding.Cancel) } + + private fun addBorderOccupation() { + val civInfo = getCiv(popupAlert.value) + addLeaderName(civInfo) + addGoodSizedLabel("You are occupying our territory!") + addCloseButton("Yes.", KeyboardBinding.Confirm) + addCloseButton("No.", KeyboardBinding.Cancel) + } private fun addBulliedOrAttackedProtectedOrAlliedMinor() { val involvedCivs = popupAlert.value.split('@') From cb96cff37015fc981c7e80a8078ba89c07368412 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Tue, 31 Dec 2024 12:01:58 +0100 Subject: [PATCH 07/27] new version --- core/src/com/unciv/logic/civilization/PopupAlert.kt | 2 +- .../civilization/diplomacy/CityStateFunctions.kt | 11 ----------- .../logic/civilization/diplomacy/DiplomacyManager.kt | 2 +- .../models/ruleset/unique/UniqueTriggerActivation.kt | 11 +++++++++++ .../com/unciv/ui/screens/worldscreen/AlertPopup.kt | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/PopupAlert.kt b/core/src/com/unciv/logic/civilization/PopupAlert.kt index 18bddc61ba17d..787d691327b74 100644 --- a/core/src/com/unciv/logic/civilization/PopupAlert.kt +++ b/core/src/com/unciv/logic/civilization/PopupAlert.kt @@ -11,7 +11,7 @@ enum class AlertType : IsPartOfGameInfoSerialization { CityConquered, CityTraded, BorderConflict, - BorderOccupation, + TilesStolen, DemandToStopSettlingCitiesNear, CitySettledNearOtherCivDespiteOurPromise, diff --git a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt index 691fa4f42268a..1c97c9fbe6862 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/CityStateFunctions.kt @@ -540,17 +540,6 @@ class CityStateFunctions(val civInfo: Civilization) { diplomacy.setFlag(DiplomacyFlags.BorderConflict, 10) } } - - // If citystate gets tile stolen from another civ, then the civ gets a diplomacy Influence debuffer. - if (diplomacy.hasModifier(DiplomaticModifiers.StealingTerritory) && diplomacy.isRelationshipLevelLT(RelationshipLevel.Friend)) { - diplomacy.addInfluence(-25f) - if (!diplomacy.hasFlag(DiplomacyFlags.BorderOccupation)) { - otherCiv.popupAlerts.add(PopupAlert(AlertType.BorderOccupation, civInfo.civName)) - - // to only show popup once. - diplomacy.setFlag(DiplomacyFlags.BorderOccupation, -1) - } - } } } diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index 0cb06977023f0..2349e23958cf8 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -52,7 +52,7 @@ enum class DiplomacyFlags { DeclinedJoinWarOffer, ResearchAgreement, BorderConflict, - BorderOccupation, + TilesStolen, SettledCitiesNearUs, AgreedToNotSettleNearUs, diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt index 22f86e8fe1498..fe048ce67bd7c 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt @@ -16,6 +16,7 @@ import com.unciv.logic.civilization.NotificationIcon import com.unciv.logic.civilization.PolicyAction import com.unciv.logic.civilization.PopupAlert import com.unciv.logic.civilization.TechAction +import com.unciv.logic.civilization.diplomacy.DiplomacyFlags import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers import com.unciv.logic.civilization.managers.ReligionState import com.unciv.logic.map.mapgenerator.NaturalWonderGenerator @@ -1107,6 +1108,16 @@ object UniqueTriggerActivation { otherCiv.getDiplomacyManagerOrMeet(civInfo).addModifier(DiplomaticModifiers.StealingTerritory, -10f) civsToNotify.add(otherCiv) } + // check if civ has steal a tile from a citystate + if (otherCiv != null && otherCiv.isCityState) { + // create this varibale diplomacyCityState for more readability + val diplomacyCityState = otherCiv.getDiplomacyManager(civInfo)!! + diplomacyCityState.addInfluence(-15f) + + if (!diplomacyCityState.hasFlag(DiplomacyFlags.TilesStolen)) { + civInfo.popupAlerts.add(PopupAlert(AlertType.TilesStolen, otherCiv.civName)) + } + } cityToAddTo.expansion.takeOwnership(tileToTakeOver) } diff --git a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt index 8826c222850eb..543d5487a50ce 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt @@ -91,7 +91,7 @@ class AlertPopup( AlertType.CityConquered -> addCityConquered() AlertType.CityTraded -> addCityTraded() AlertType.BorderConflict -> addBorderConflict() - AlertType.BorderOccupation -> addBorderOccupation() + AlertType.TilesStolen -> addTilesStolen() AlertType.DemandToStopSettlingCitiesNear -> addDemandToStopSettlingCitiesNear() AlertType.CitySettledNearOtherCivDespiteOurPromise -> addCitySettledNearOtherCivDespiteOurPromise() AlertType.DemandToStopSpreadingReligion -> addDemandToStopSpreadingReligion() @@ -120,10 +120,10 @@ class AlertPopup( addCloseButton("Never!", KeyboardBinding.Cancel) } - private fun addBorderOccupation() { + private fun addTilesStolen() { val civInfo = getCiv(popupAlert.value) addLeaderName(civInfo) - addGoodSizedLabel("You are occupying our territory!") + addGoodSizedLabel("You stole some of our territory!") addCloseButton("Yes.", KeyboardBinding.Confirm) addCloseButton("No.", KeyboardBinding.Cancel) } From e400964ef185cc023e88b35f9e29a52f5a84b7b9 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Tue, 31 Dec 2024 13:41:10 +0100 Subject: [PATCH 08/27] change to getDiplomacyManagerOrMeet --- .../com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt index fe048ce67bd7c..a33748ce375ae 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt @@ -1111,7 +1111,7 @@ object UniqueTriggerActivation { // check if civ has steal a tile from a citystate if (otherCiv != null && otherCiv.isCityState) { // create this varibale diplomacyCityState for more readability - val diplomacyCityState = otherCiv.getDiplomacyManager(civInfo)!! + val diplomacyCityState = otherCiv.getDiplomacyManagerOrMeet(civInfo) diplomacyCityState.addInfluence(-15f) if (!diplomacyCityState.hasFlag(DiplomacyFlags.TilesStolen)) { From 61f90fac4a460969105b414139eca5332e1f1f54 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Tue, 31 Dec 2024 13:55:17 +0100 Subject: [PATCH 09/27] added text to template.properties and changed AlertPopup.kt --- android/assets/jsons/translations/template.properties | 3 ++- core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index d451fb0053465..ebaca7579d40c 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -1597,7 +1597,8 @@ Destroying the city instantly razes the city to the ground. = Keep it = Remove your troops in our border immediately! = Sorry. = -Never! = +Never! = +Those lands were not yours to take. This has not gone unnoticed = Offer Declaration of Friendship ([30] turns) = My friend, shall we declare our friendship to the world? = diff --git a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt index 543d5487a50ce..288bec727cb39 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt @@ -123,9 +123,8 @@ class AlertPopup( private fun addTilesStolen() { val civInfo = getCiv(popupAlert.value) addLeaderName(civInfo) - addGoodSizedLabel("You stole some of our territory!") - addCloseButton("Yes.", KeyboardBinding.Confirm) - addCloseButton("No.", KeyboardBinding.Cancel) + addGoodSizedLabel("Those lands were not yours to take. This has not gone unnoticed") + addCloseButton() } private fun addBulliedOrAttackedProtectedOrAlliedMinor() { From ff67bb76ec5183d7cca3d63accd277bf2e107e50 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:07:13 +0100 Subject: [PATCH 10/27] Update template.properties --- android/assets/jsons/translations/template.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index ebaca7579d40c..fd1a9c205419a 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -1597,7 +1597,7 @@ Destroying the city instantly razes the city to the ground. = Keep it = Remove your troops in our border immediately! = Sorry. = -Never! = +Never! = Those lands were not yours to take. This has not gone unnoticed = Offer Declaration of Friendship ([30] turns) = From 467e7257c7112d718c259836466666e11f561e6f Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:51:13 +0100 Subject: [PATCH 11/27] with period at the end :b --- android/assets/jsons/translations/template.properties | 2 +- core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index fd1a9c205419a..1b6fa4cd492a9 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -1598,7 +1598,7 @@ Keep it = Remove your troops in our border immediately! = Sorry. = Never! = -Those lands were not yours to take. This has not gone unnoticed = +Those lands were not yours to take. This has not gone unnoticed. = Offer Declaration of Friendship ([30] turns) = My friend, shall we declare our friendship to the world? = diff --git a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt index 288bec727cb39..9f4eb12b45600 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt @@ -123,7 +123,7 @@ class AlertPopup( private fun addTilesStolen() { val civInfo = getCiv(popupAlert.value) addLeaderName(civInfo) - addGoodSizedLabel("Those lands were not yours to take. This has not gone unnoticed") + addGoodSizedLabel("Those lands were not yours to take. This has not gone unnoticed.") addCloseButton() } From aa532e944dd7c13ebf73090e1648f0e5a5ed14b1 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Wed, 1 Jan 2025 14:28:34 +0100 Subject: [PATCH 12/27] add flag now --- .../com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt index a33748ce375ae..f7e67c0108663 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueTriggerActivation.kt @@ -1114,8 +1114,11 @@ object UniqueTriggerActivation { val diplomacyCityState = otherCiv.getDiplomacyManagerOrMeet(civInfo) diplomacyCityState.addInfluence(-15f) + + if (!diplomacyCityState.hasFlag(DiplomacyFlags.TilesStolen)) { civInfo.popupAlerts.add(PopupAlert(AlertType.TilesStolen, otherCiv.civName)) + diplomacyCityState.setFlag(DiplomacyFlags.TilesStolen, 1) } } cityToAddTo.expansion.takeOwnership(tileToTakeOver) From b300c51772cbe9c31a7daae569dd91bb51a1f5af Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Thu, 2 Jan 2025 23:25:52 +0100 Subject: [PATCH 13/27] Made Option to declare war when a city state is bullied unavailable --- core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt index 9f4eb12b45600..edbb7da80e52e 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/AlertPopup.kt @@ -146,13 +146,14 @@ class AlertPopup( "I thought you might like to know that I've launched an invasion of one of your little pet states.\nThe lands of [${cityState.civName}] will make a fine addition to my own." } addGoodSizedLabel(text).row() - - addCloseButton("THIS MEANS WAR!", KeyboardBinding.Confirm) { + + if (!player.isAtWarWith(bullyOrAttacker)) { + addCloseButton("THIS MEANS WAR!", KeyboardBinding.Confirm) { player.getDiplomacyManager(bullyOrAttacker)!!.sideWithCityState() val warReason = if (popupAlert.type == AlertType.AttackedAllyMinor) WarType.AlliedCityStateWar else WarType.ProtectedCityStateWar player.getDiplomacyManager(bullyOrAttacker)!!.declareWar(DeclareWarReason(warReason, cityState)) cityState.getDiplomacyManager(player)!!.influence += 20f // You went to war for us!! - }.row() + }.row()} addCloseButton("You'll pay for this!", KeyboardBinding.Confirm) { player.getDiplomacyManager(bullyOrAttacker)!!.sideWithCityState() From 1623290ad6384b76759aa2e26dbf901c015e486e Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sat, 11 Jan 2025 18:46:46 +0100 Subject: [PATCH 14/27] added option to change the Maximum Autosave turns stored --- .../jsons/translations/template.properties | 1 + core/src/com/unciv/logic/files/UncivFiles.kt | 6 +++++- .../com/unciv/models/metadata/GameSettings.kt | 1 + .../unciv/ui/popups/options/AdvancedTab.kt | 19 +++++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 2755282893cce..9cf0c4f13f7de 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -887,6 +887,7 @@ Could not download music! = ## Advanced tab Advanced = Turns between autosaves = +Maximum Autosave turns stored = Screen orientation = Landscape (fixed) = diff --git a/core/src/com/unciv/logic/files/UncivFiles.kt b/core/src/com/unciv/logic/files/UncivFiles.kt index 7d92fe1449592..9e7ac5f1e7a16 100644 --- a/core/src/com/unciv/logic/files/UncivFiles.kt +++ b/core/src/com/unciv/logic/files/UncivFiles.kt @@ -469,6 +469,9 @@ class Autosaves(val files: UncivFiles) { } fun autoSave(gameInfo: GameInfo, nextTurn: Boolean = false) { + // get GameSettings to check the maxAutosavesStored in the autoSave function + val settings = files.getGeneralSettings() + try { files.saveGame(gameInfo, AUTOSAVE_FILE_NAME) } catch (oom: OutOfMemoryError) { @@ -486,7 +489,8 @@ class Autosaves(val files: UncivFiles) { fun getAutosaves(): Sequence { return files.getSaves().filter { it.name().startsWith(AUTOSAVE_FILE_NAME) } } - while (getAutosaves().count() > 10) { + // added the plus 1 to avoid player choosing 6,11,21,51,101, etc.. in options. + while (getAutosaves().count() > settings.maxAutosavesStored+1) { val saveToDelete = getAutosaves().minByOrNull { it.lastModified() }!! files.deleteSave(saveToDelete.name()) } diff --git a/core/src/com/unciv/models/metadata/GameSettings.kt b/core/src/com/unciv/models/metadata/GameSettings.kt index 8a817ede95aa8..e0dc830091ad2 100644 --- a/core/src/com/unciv/models/metadata/GameSettings.kt +++ b/core/src/com/unciv/models/metadata/GameSettings.kt @@ -56,6 +56,7 @@ class GameSettings { var pauseBetweenTracks = 10 var turnsBetweenAutosaves = 1 + var maxAutosavesStored = 10 var tileSet: String = Constants.defaultTileset var unitSet: String? = Constants.defaultUnitset var skin: String = Constants.defaultSkin diff --git a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt index a8704104feabb..3a8d9f7df9e94 100644 --- a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt +++ b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt @@ -51,6 +51,8 @@ class AdvancedTab( init { pad(10f) defaults().pad(5f) + + addmaxAutosavesStored() addAutosaveTurnsSelectBox() addSeparator() @@ -92,6 +94,23 @@ class AdvancedTab( optionsPopup.reopenAfterDisplayLayoutChange() } } + + private fun addmaxAutosavesStored() { + add("Maximum Autosave turns stored".toLabel()).left().fillX() + + val maxAutosavesStoredSelectBox = SelectBox(skin) + val maxAutosavesStoredArray = Array() + maxAutosavesStoredArray.addAll(1,2,5,10,15,20,35,50,100,150,200,250,500,1000) + maxAutosavesStoredSelectBox.items = maxAutosavesStoredArray + maxAutosavesStoredSelectBox.selected = settings.maxAutosavesStored + + add(maxAutosavesStoredSelectBox).pad(10f).row() + + maxAutosavesStoredSelectBox.onChange { + settings.maxAutosavesStored = maxAutosavesStoredSelectBox.selected + println(settings.maxAutosavesStored) + } + } private fun addAutosaveTurnsSelectBox() { From 4edcd248e7aa6fd8b4771aab3cc3a6c8e2a1a788 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sat, 11 Jan 2025 18:51:58 +0100 Subject: [PATCH 15/27] remove print --- core/src/com/unciv/ui/popups/options/AdvancedTab.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt index 3a8d9f7df9e94..592c113ee7c4c 100644 --- a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt +++ b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt @@ -108,7 +108,6 @@ class AdvancedTab( maxAutosavesStoredSelectBox.onChange { settings.maxAutosavesStored = maxAutosavesStoredSelectBox.selected - println(settings.maxAutosavesStored) } } From 0d5295e9f43a3b95332783c1b9dfc1caa805bd84 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sat, 11 Jan 2025 19:10:39 +0100 Subject: [PATCH 16/27] change letter --- android/assets/jsons/translations/template.properties | 2 +- core/src/com/unciv/ui/popups/options/AdvancedTab.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 9cf0c4f13f7de..e440236d6666b 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -887,7 +887,7 @@ Could not download music! = ## Advanced tab Advanced = Turns between autosaves = -Maximum Autosave turns stored = +Maximum autosave turns stored = Screen orientation = Landscape (fixed) = diff --git a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt index 592c113ee7c4c..a471ffc88543f 100644 --- a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt +++ b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt @@ -96,7 +96,7 @@ class AdvancedTab( } private fun addmaxAutosavesStored() { - add("Maximum Autosave turns stored".toLabel()).left().fillX() + add("Maximum autosave turns stored".toLabel()).left().fillX() val maxAutosavesStoredSelectBox = SelectBox(skin) val maxAutosavesStoredArray = Array() @@ -111,7 +111,6 @@ class AdvancedTab( } } - private fun addAutosaveTurnsSelectBox() { add("Turns between autosaves".toLabel()).left().fillX() From 1599dd2864db7c0856012cfd48da40bdf931c57b Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sat, 11 Jan 2025 19:32:01 +0100 Subject: [PATCH 17/27] should fix issue with building test --- android/assets/jsons/translations/template.properties | 3 ++- core/src/com/unciv/ui/popups/options/AdvancedTab.kt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index e440236d6666b..69977e8e3ab4f 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -886,8 +886,9 @@ Could not download music! = ## Advanced tab Advanced = -Turns between autosaves = Maximum autosave turns stored = +Turns between autosaves = + Screen orientation = Landscape (fixed) = diff --git a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt index a471ffc88543f..57b57f785ba78 100644 --- a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt +++ b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt @@ -100,7 +100,7 @@ class AdvancedTab( val maxAutosavesStoredSelectBox = SelectBox(skin) val maxAutosavesStoredArray = Array() - maxAutosavesStoredArray.addAll(1,2,5,10,15,20,35,50,100,150,200,250,500,1000) + maxAutosavesStoredArray.addAll(1,2,5,10,15,20,35,50,100,150,200,250) maxAutosavesStoredSelectBox.items = maxAutosavesStoredArray maxAutosavesStoredSelectBox.selected = settings.maxAutosavesStored From eab98f29cf260ae0f7df79e07eb45b05d7110fe9 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sat, 11 Jan 2025 20:45:53 +0100 Subject: [PATCH 18/27] update with changes --- android/assets/jsons/translations/template.properties | 2 +- core/src/com/unciv/logic/files/UncivFiles.kt | 3 +++ core/src/com/unciv/ui/popups/options/AdvancedTab.kt | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 69977e8e3ab4f..bfe4a1283af07 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -886,7 +886,7 @@ Could not download music! = ## Advanced tab Advanced = -Maximum autosave turns stored = +Number of autosave files stored = Turns between autosaves = diff --git a/core/src/com/unciv/logic/files/UncivFiles.kt b/core/src/com/unciv/logic/files/UncivFiles.kt index 9e7ac5f1e7a16..11b04e8677bb7 100644 --- a/core/src/com/unciv/logic/files/UncivFiles.kt +++ b/core/src/com/unciv/logic/files/UncivFiles.kt @@ -490,6 +490,9 @@ class Autosaves(val files: UncivFiles) { return files.getSaves().filter { it.name().startsWith(AUTOSAVE_FILE_NAME) } } // added the plus 1 to avoid player choosing 6,11,21,51,101, etc.. in options. +// // with the old version with 10 has example, it would start overriding after 9 instead of 10. + // like from autosave-1 to autosave-9 after the autosave-9 the autosave-1 would override to autosave-2. + // For me it should be after autosave-10 that it should start overriding old autosaves. while (getAutosaves().count() > settings.maxAutosavesStored+1) { val saveToDelete = getAutosaves().minByOrNull { it.lastModified() }!! files.deleteSave(saveToDelete.name()) diff --git a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt index 57b57f785ba78..ef416ca0cce13 100644 --- a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt +++ b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt @@ -52,7 +52,7 @@ class AdvancedTab( pad(10f) defaults().pad(5f) - addmaxAutosavesStored() + addMaxAutosavesStored() addAutosaveTurnsSelectBox() addSeparator() @@ -95,8 +95,8 @@ class AdvancedTab( } } - private fun addmaxAutosavesStored() { - add("Maximum autosave turns stored".toLabel()).left().fillX() + private fun addMaxAutosavesStored() { + add("Number of autosave files stored".toLabel()).left().fillX() val maxAutosavesStoredSelectBox = SelectBox(skin) val maxAutosavesStoredArray = Array() From 4fadce64e0a2b4fda632b551171b7e01dd6cbf8f Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sun, 19 Jan 2025 18:31:38 +0100 Subject: [PATCH 19/27] 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. --- .../unciv/models/ruleset/unique/UniqueType.kt | 1 + .../unit/actions/UnitActionsFromUniques.kt | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index b0c8c55b49035..fad01c5e73f49 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -348,6 +348,7 @@ enum class UniqueType( // Unit actions should look like: "Can {action description}, to allow them to be combined with modifiers FoundCity("Founds a new city", UniqueTarget.UnitAction), + FoundPuppetCity("Founds a new puppet city", UniqueTarget.UnitAction), ConstructImprovementInstantly("Can instantly construct a [improvementFilter] improvement", UniqueTarget.UnitAction), // TODO: Should be replaced by "Can instantly construct a [] improvement " CreateWaterImprovements("May create improvements on water resources", UniqueTarget.Unit), diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt index 33d94c5454601..1129eb988ce63 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsFromUniques.kt @@ -39,8 +39,11 @@ object UnitActionsFromUniques { * (no movement left, too close to another city). */ internal fun getFoundCityAction(unit: MapUnit, tile: Tile): UnitAction? { - val unique = UnitActionModifiers.getUsableUnitActionUniques(unit, UniqueType.FoundCity) - .firstOrNull() ?: return null + // FoundPuppetCity is to found a puppet city for modding. + val unique = UnitActionModifiers.getUsableUnitActionUniques(unit, + UniqueType.FoundCity).firstOrNull() ?: + UnitActionModifiers.getUsableUnitActionUniques(unit, + UniqueType.FoundPuppetCity).firstOrNull() ?: return null if (tile.isWater || tile.isImpassible()) return null // Spain should still be able to build Conquistadors in a one city challenge - but can't settle them @@ -54,12 +57,19 @@ object UnitActionsFromUniques { ) == true } val foundAction = { if (unit.civ.playerType != PlayerType.AI) - UncivGame.Current.settings.addCompletedTutorialTask("Found city") - unit.civ.addCity(tile.position, unit) + // Now takes on the text of the unique. + UncivGame.Current.settings.addCompletedTutorialTask( + unique.text) + // Get the city to be able to change it into puppet, for modding. + val city = unit.civ.addCity(tile.position, unit) if (hasActionModifiers) UnitActionModifiers.activateSideEffects(unit, unique) else unit.destroy() GUI.setUpdateWorldOnNextRender() // Set manually, since this could be triggered from the ConfirmPopup and not from the UnitActionsTable + // If unit has FoundPuppetCity make it into a puppet city. + if (unique.type == UniqueType.FoundPuppetCity) { + city.isPuppet = true + } } if (unit.civ.playerType == PlayerType.AI) From a7a2e7599479fd7cdd43fab8270e21ca4a7ab142 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:33:20 +0100 Subject: [PATCH 20/27] Added save promotion --- .../jsons/translations/template.properties | 1 + core/src/com/unciv/logic/city/City.kt | 13 +++++++++- .../com/unciv/logic/city/CityConstructions.kt | 18 ++++++++++++++ .../ui/popups/CityScreenConstructionMenu.kt | 1 + .../cityscreen/ConstructionInfoTable.kt | 17 +++++++++++-- .../pickerscreens/PromotionPickerScreen.kt | 24 +++++++++++++++++-- 6 files changed, 69 insertions(+), 5 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 8712b0aa063d5..fde10961da0c4 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -113,6 +113,7 @@ Requires [PolicyOrNationalWonder] = Cannot be purchased = Can only be purchased = See also = +Build units with saved UnitType promotion = Requires at least one of the following: = Requires all of the following: = diff --git a/core/src/com/unciv/logic/city/City.kt b/core/src/com/unciv/logic/city/City.kt index ea2d3655eacf5..0dddfdd509d2f 100644 --- a/core/src/com/unciv/logic/city/City.kt +++ b/core/src/com/unciv/logic/city/City.kt @@ -14,6 +14,7 @@ import com.unciv.logic.city.managers.SpyFleeReason import com.unciv.logic.civilization.Civilization import com.unciv.logic.map.TileMap import com.unciv.logic.map.mapunit.MapUnit +import com.unciv.logic.map.mapunit.UnitPromotions import com.unciv.logic.map.tile.RoadStatus import com.unciv.logic.map.tile.Tile import com.unciv.models.Counter @@ -91,7 +92,15 @@ class City : IsPartOfGameInfoSerialization, INamed { var hasSoldBuildingThisTurn = false var isPuppet = false var shouldReassignPopulation = false // flag so that on startTurn() we reassign population - + + // HashMap to check if we can build the unitType with the saved promotion. + // (Saved promotion: meaning that the player checkbox to save the promotion when adding them to a unitType.) + // To not have to redo it for every unit build afterword. + var canBuildUnitTypeWithSavedPromotion = HashMap() + + // To stroe unitType to promotion. + var cityUnitTypePromotion = HashMap() + @delegate:Transient val neighboringCities: List by lazy { civ.gameInfo.getCities().filter { it != this && it.getCenterTile().isExplored(civ) && it.getCenterTile().aerialDistanceTo(getCenterTile()) <= 12 }.toList() @@ -153,6 +162,8 @@ class City : IsPartOfGameInfoSerialization, INamed { toReturn.avoidGrowth = avoidGrowth toReturn.manualSpecialists = manualSpecialists toReturn.connectedToCapitalStatus = connectedToCapitalStatus + toReturn.canBuildUnitTypeWithSavedPromotion = canBuildUnitTypeWithSavedPromotion + toReturn.cityUnitTypePromotion = cityUnitTypePromotion return toReturn } diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index bfcc4942f4f1b..3bff91f1952b8 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -464,6 +464,24 @@ class CityConstructions : IsPartOfGameInfoSerialization { else if (construction is BaseUnit) { unit = construction.construct(this, null) ?: return false // unable to place unit + + // 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. + val savedPromotion = city.cityUnitTypePromotion[unit.baseUnit.unitType] + if (city.canBuildUnitTypeWithSavedPromotion[unit.baseUnit.unitType] != null && + city.canBuildUnitTypeWithSavedPromotion[unit.baseUnit.unitType] == true && + savedPromotion != null) { + + // check if current unit has enough ep + if (unit.promotions.XP >= savedPromotion.XP) { + + // then added it. + for (promotions in savedPromotion.promotions) { + unit.promotions.addPromotion(promotions) + } + } + } } if (construction.name in inProgressConstructions) diff --git a/core/src/com/unciv/ui/popups/CityScreenConstructionMenu.kt b/core/src/com/unciv/ui/popups/CityScreenConstructionMenu.kt index 2d246c2926707..b282139316c77 100644 --- a/core/src/com/unciv/ui/popups/CityScreenConstructionMenu.kt +++ b/core/src/com/unciv/ui/popups/CityScreenConstructionMenu.kt @@ -9,6 +9,7 @@ import com.unciv.logic.city.CityConstructions import com.unciv.models.ruleset.Building import com.unciv.models.ruleset.IConstruction import com.unciv.models.ruleset.PerpetualConstruction +import com.unciv.models.ruleset.unit.BaseUnit import com.unciv.ui.components.input.KeyboardBinding //todo Check move/top/end for "place one improvement" buildings diff --git a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt index 9a1aa92623e58..9eaae751a4dd7 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt @@ -15,6 +15,7 @@ import com.unciv.models.translations.tr import com.unciv.ui.components.extensions.darken import com.unciv.ui.components.extensions.disable import com.unciv.ui.components.extensions.isEnabled +import com.unciv.ui.components.extensions.toCheckBox import com.unciv.ui.components.extensions.toTextButton import com.unciv.ui.components.fonts.Fonts import com.unciv.ui.components.input.onClick @@ -89,7 +90,7 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { val descriptionLabel = Label(description, BaseScreen.skin) // already translated descriptionLabel.wrap = true add(descriptionLabel).colspan(2).width(stage.width / if(cityScreen.isCrampedPortrait()) 3 else 4) - + if (cityConstructions.isBuilt(construction.name)) { showSellButton(construction) } else if (buyButtonFactory.hasBuyButtons(construction)) { @@ -98,6 +99,18 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { it.padTop(5f).colspan(2).center() } } + if (construction is BaseUnit) { + val unitType = construction.unitType + + if (city.canBuildUnitTypeWithSavedPromotion[unitType] != null) { + row() + add(city.canBuildUnitTypeWithSavedPromotion[unitType]?.let { + "Build units with saved UnitType promotion".toCheckBox( + it + ) {city.canBuildUnitTypeWithSavedPromotion[unitType] = it} + }).colspan(2).center() + } + } } } @@ -132,7 +145,7 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { } } } - + private fun sellBuildingClicked(construction: Building, sellText: String) { cityScreen.closeAllPopups() diff --git a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt index 54964fd94cf11..0bbe7f35684cc 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt @@ -15,6 +15,7 @@ import com.unciv.models.ruleset.unit.Promotion import com.unciv.models.translations.tr import com.unciv.ui.audio.SoundPlayer import com.unciv.ui.components.extensions.isEnabled +import com.unciv.ui.components.extensions.toCheckBox import com.unciv.ui.components.extensions.toTextButton import com.unciv.ui.components.input.KeyCharAndCode import com.unciv.ui.components.input.KeyboardBinding @@ -63,7 +64,9 @@ class PromotionPickerScreen private constructor( // Logic private val tree = PromotionTree(unit) - + + // This if we should save the unit promotion or not. + private var saveUnitTypePromotion = false init { closeButton.onActivation { @@ -77,6 +80,16 @@ class PromotionPickerScreen private constructor( rightSideButton.setText("Pick promotion".tr()) rightSideButton.onClick(UncivSound.Silent) { acceptPromotion(selectedPromotion) + + 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.canBuildUnitTypeWithSavedPromotion.put(unit.baseUnit.unitType,true) + unitCurrentCity.cityUnitTypePromotion.put(unit.baseUnit.unitType,unit.promotions) + } + } } } else { rightSideButton.isVisible = false @@ -191,9 +204,16 @@ class PromotionPickerScreen private constructor( } topTable.add(promotionsTable) + saveUnitTypePromotionForCity() addConnectingLines(emptySet()) } - + + // adds the checkBoxs to choice to save unit promotion. + private fun saveUnitTypePromotionForCity() { + val checkBoxSaveUnitPromotion = "Save unitType promotions.".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it} + promotionsTable.add(checkBoxSaveUnitPromotion) + } + private fun getButton(tree: PromotionTree, node: PromotionTree.PromotionNode) : PromotionButton { val isPickable = canPromoteNow && (!node.pathIsAmbiguous || node.distanceToAdopted == 1) && From dc00ad5e8e3a54e406826571387fc1a364ba59af Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Fri, 7 Feb 2025 21:36:23 +0100 Subject: [PATCH 21/27] Updated for PR --- android/assets/jsons/translations/template.properties | 3 ++- .../com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt | 2 +- .../unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 96098680cc557..14fc0f2620c22 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -113,7 +113,8 @@ Requires [PolicyOrNationalWonder] = Cannot be purchased = Can only be purchased = See also = -Build units with saved UnitType promotion = +Default promotions = +"Default promotions for [unitType] = Requires at least one of the following: = Requires all of the following: = diff --git a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt index 2838f5acddc17..f094538749174 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt @@ -106,7 +106,7 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { if (city.canBuildUnitTypeWithSavedPromotion[unitType] != null) { row() add(city.canBuildUnitTypeWithSavedPromotion[unitType]?.let { - "Build units with saved UnitType promotion".toCheckBox( + "Default promotions".toCheckBox( it ) {city.canBuildUnitTypeWithSavedPromotion[unitType] = 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 0bbe7f35684cc..4dd76f661a78c 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt @@ -210,7 +210,7 @@ class PromotionPickerScreen private constructor( // adds the checkBoxs to choice to save unit promotion. private fun saveUnitTypePromotionForCity() { - val checkBoxSaveUnitPromotion = "Save unitType promotions.".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it} + val checkBoxSaveUnitPromotion = "Default promotions for ${unit.baseUnit.unitType}".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it} promotionsTable.add(checkBoxSaveUnitPromotion) } From ef0bb390cad015689af6a2d7a08bdbcb5e37fa32 Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sat, 8 Feb 2025 21:27:18 +0100 Subject: [PATCH 22/27] Updated with requested changes --- .../assets/jsons/translations/template.properties | 2 +- core/src/com/unciv/logic/city/City.kt | 12 ++++-------- core/src/com/unciv/logic/city/CityConstructions.kt | 14 +++++--------- .../ui/screens/cityscreen/ConstructionInfoTable.kt | 8 ++------ .../screens/pickerscreens/PromotionPickerScreen.kt | 4 ++-- 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 14fc0f2620c22..6dab16357a137 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 = Default promotions = -"Default promotions for [unitType] = +Default promotions for [unitType] = Requires at least one of the following: = Requires all of the following: = diff --git a/core/src/com/unciv/logic/city/City.kt b/core/src/com/unciv/logic/city/City.kt index 0dddfdd509d2f..2e71900a59349 100644 --- a/core/src/com/unciv/logic/city/City.kt +++ b/core/src/com/unciv/logic/city/City.kt @@ -93,13 +93,9 @@ class City : IsPartOfGameInfoSerialization, INamed { var isPuppet = false var shouldReassignPopulation = false // flag so that on startTurn() we reassign population - // HashMap to check if we can build the unitType with the saved promotion. - // (Saved promotion: meaning that the player checkbox to save the promotion when adding them to a unitType.) - // To not have to redo it for every unit build afterword. - var canBuildUnitTypeWithSavedPromotion = HashMap() + var unitTypeToPromotion = HashMap() - // To stroe unitType to promotion. - var cityUnitTypePromotion = HashMap() + var cityUnitTypePromotions = HashMap() @delegate:Transient val neighboringCities: List by lazy { @@ -162,8 +158,8 @@ class City : IsPartOfGameInfoSerialization, INamed { toReturn.avoidGrowth = avoidGrowth toReturn.manualSpecialists = manualSpecialists toReturn.connectedToCapitalStatus = connectedToCapitalStatus - toReturn.canBuildUnitTypeWithSavedPromotion = canBuildUnitTypeWithSavedPromotion - toReturn.cityUnitTypePromotion = cityUnitTypePromotion + toReturn.unitTypeToPromotion = unitTypeToPromotion + toReturn.cityUnitTypePromotions = cityUnitTypePromotions return toReturn } diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 94595fa607cc2..6cd4c02c1d11f 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -468,18 +468,14 @@ 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. - val savedPromotion = city.cityUnitTypePromotion[unit.baseUnit.unitType] - if (city.canBuildUnitTypeWithSavedPromotion[unit.baseUnit.unitType] != null && - city.canBuildUnitTypeWithSavedPromotion[unit.baseUnit.unitType] == true && - savedPromotion != null) { + // and finally check if the current unit has enough XP. + val savedPromotion = city.cityUnitTypePromotions[unit.baseUnit.unitType] + if (city.unitTypeToPromotion[unit.baseUnit.unitType] != null && + city.unitTypeToPromotion[unit.baseUnit.unitType] == true && + savedPromotion != null && unit.promotions.XP >= savedPromotion.XP) { - // check if current unit has enough ep - if (unit.promotions.XP >= savedPromotion.XP) { - - // then added it. for (promotions in savedPromotion.promotions) { unit.promotions.addPromotion(promotions) - } } } } diff --git a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt index f094538749174..50f6c360c5cad 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt @@ -103,13 +103,9 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { if (construction is BaseUnit) { val unitType = construction.unitType - if (city.canBuildUnitTypeWithSavedPromotion[unitType] != null) { + if (city.unitTypeToPromotion[unitType] != null) { row() - add(city.canBuildUnitTypeWithSavedPromotion[unitType]?.let { - "Default promotions".toCheckBox( - it - ) {city.canBuildUnitTypeWithSavedPromotion[unitType] = it} - }).colspan(2).center() + add("Default promotions".toCheckBox(city.unitTypeToPromotion[unitType]!!) {city.unitTypeToPromotion[unitType] = 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 4dd76f661a78c..75affe8edf383 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt @@ -86,8 +86,8 @@ class PromotionPickerScreen private constructor( if (unitCurrentCity != null) { // If you are clicked the save unitType promotion, you want the next unitType to have the same promotion. - unitCurrentCity.canBuildUnitTypeWithSavedPromotion.put(unit.baseUnit.unitType,true) - unitCurrentCity.cityUnitTypePromotion.put(unit.baseUnit.unitType,unit.promotions) + unitCurrentCity.unitTypeToPromotion.put(unit.baseUnit.unitType,true) + unitCurrentCity.cityUnitTypePromotions.put(unit.baseUnit.unitType,unit.promotions) } } } From fe66e04ef39e0dd81af04f7d5ff265fcc98d838d Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sat, 8 Feb 2025 21:30:34 +0100 Subject: [PATCH 23/27] Removed unnecessary check --- core/src/com/unciv/logic/city/CityConstructions.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 6cd4c02c1d11f..ea4ce60708e51 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -470,8 +470,7 @@ class CityConstructions : IsPartOfGameInfoSerialization { // and null check. // and finally check if the current unit has enough XP. val savedPromotion = city.cityUnitTypePromotions[unit.baseUnit.unitType] - if (city.unitTypeToPromotion[unit.baseUnit.unitType] != null && - city.unitTypeToPromotion[unit.baseUnit.unitType] == true && + if (city.unitTypeToPromotion[unit.baseUnit.unitType] == true && savedPromotion != null && unit.promotions.XP >= savedPromotion.XP) { for (promotions in savedPromotion.promotions) { From bb78c9eadb5ae1acc739dad05c3e5af5d986fbcc Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Sun, 9 Feb 2025 12:09:08 +0100 Subject: [PATCH 24/27] updated PR --- .../unciv/ui/screens/cityscreen/ConstructionInfoTable.kt | 6 ++++-- .../unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt | 5 ++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt index 50f6c360c5cad..54d23c149ec68 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt @@ -103,9 +103,11 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { if (construction is BaseUnit) { val unitType = construction.unitType - if (city.unitTypeToPromotion[unitType] != null) { + val buildUnitWithPromotions = city.unitTypeToPromotion[unitType] + + if (buildUnitWithPromotions != null) { row() - add("Default promotions".toCheckBox(city.unitTypeToPromotion[unitType]!!) {city.unitTypeToPromotion[unitType] = it}).colspan(2).center() + add("Default promotions".toCheckBox(buildUnitWithPromotions) {city.unitTypeToPromotion[unitType] = 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 75affe8edf383..80db4a595742f 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt @@ -64,7 +64,7 @@ class PromotionPickerScreen private constructor( // Logic private val tree = PromotionTree(unit) - + // This if we should save the unit promotion or not. private var saveUnitTypePromotion = false @@ -210,7 +210,7 @@ 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} + val checkBoxSaveUnitPromotion = "Default promotions for [${unit.baseUnit.unitType}]".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it} promotionsTable.add(checkBoxSaveUnitPromotion) } @@ -372,7 +372,6 @@ class PromotionPickerScreen private constructor( } override fun recreate() = recreate(closeOnPick) - fun recreate(closeOnPick: Boolean): BaseScreen { val newScreen = PromotionPickerScreen(unit, closeOnPick, originalName, onChange) newScreen.setScrollY(scrollPane.scrollY) From 74aa1ff75575b09d3876b9e8081830a6057d196f Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Tue, 11 Feb 2025 19:03:36 +0100 Subject: [PATCH 25/27] Update PromotionPickerScreen.kt to save promotion cells too --- android/assets/Icons.atlas | 98 +++++++++---------- .../jsons/translations/template.properties | 2 +- .../cityscreen/ConstructionInfoTable.kt | 2 +- .../pickerscreens/PromotionPickerScreen.kt | 24 +++-- 4 files changed, 66 insertions(+), 60 deletions(-) diff --git a/android/assets/Icons.atlas b/android/assets/Icons.atlas index 76b259eb39581..57f33fe7d9c61 100644 --- a/android/assets/Icons.atlas +++ b/android/assets/Icons.atlas @@ -200,6 +200,34 @@ OtherIcons/Stop orig: 100, 100 offset: 0, 0 index: -1 +ImprovementIcons/Circle + rotate: false + xy: 289, 1590 + size: 178, 178 + orig: 178, 178 + offset: 0, 0 + index: -1 +OtherIcons/Circle + rotate: false + xy: 289, 1590 + size: 178, 178 + orig: 178, 178 + offset: 0, 0 + index: -1 +ResourceIcons/Circle + rotate: false + xy: 289, 1590 + size: 178, 178 + orig: 178, 178 + offset: 0, 0 + index: -1 +StatIcons/Circle + rotate: false + xy: 289, 1590 + size: 178, 178 + orig: 178, 178 + offset: 0, 0 + index: -1 ImprovementIcons/Citadel rotate: false xy: 4, 62 @@ -459,6 +487,27 @@ StatIcons/Faith orig: 100, 100 offset: 0, 0 index: -1 +NotificationIcons/Loading + rotate: false + xy: 907, 1686 + size: 100, 100 + orig: 100, 100 + offset: 0, 0 + index: -1 +NotificationIcons/Working + rotate: false + xy: 907, 1686 + size: 100, 100 + orig: 100, 100 + offset: 0, 0 + index: -1 +OtherIcons/Loading + rotate: false + xy: 907, 1686 + size: 100, 100 + orig: 100, 100 + offset: 0, 0 + index: -1 NotificationIcons/PickConstruction rotate: false xy: 1771, 1500 @@ -620,34 +669,6 @@ NotificationIcons/NextTurn orig: 100, 100 offset: 0, 0 index: -1 -OtherIcons/Circle - rotate: false - xy: 289, 1590 - size: 178, 178 - orig: 178, 178 - offset: 0, 0 - index: -1 -ImprovementIcons/Circle - rotate: false - xy: 289, 1590 - size: 178, 178 - orig: 178, 178 - offset: 0, 0 - index: -1 -ResourceIcons/Circle - rotate: false - xy: 289, 1590 - size: 178, 178 - orig: 178, 178 - offset: 0, 0 - index: -1 -StatIcons/Circle - rotate: false - xy: 289, 1590 - size: 178, 178 - orig: 178, 178 - offset: 0, 0 - index: -1 OtherIcons/Cities rotate: false xy: 208, 1436 @@ -823,27 +844,6 @@ OtherIcons/Load orig: 100, 100 offset: 0, 0 index: -1 -OtherIcons/Loading - rotate: false - xy: 907, 1686 - size: 100, 100 - orig: 100, 100 - offset: 0, 0 - index: -1 -NotificationIcons/Loading - rotate: false - xy: 907, 1686 - size: 100, 100 - orig: 100, 100 - offset: 0, 0 - index: -1 -NotificationIcons/Working - rotate: false - xy: 907, 1686 - size: 100, 100 - orig: 100, 100 - offset: 0, 0 - index: -1 OtherIcons/LockSmall rotate: false xy: 1398, 1168 diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index a0628bf5ec5c2..c7ba0463fde9e 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -113,7 +113,7 @@ Requires [PolicyOrNationalWonder] = Cannot be purchased = Can only be purchased = See also = -Default promotions = +Use default promotions = Default promotions for [unitType] = Requires at least one of the following: = diff --git a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt index 54d23c149ec68..3f414d1fd4e3b 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt @@ -107,7 +107,7 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { if (buildUnitWithPromotions != null) { row() - add("Default promotions".toCheckBox(buildUnitWithPromotions) {city.unitTypeToPromotion[unitType] = it}).colspan(2).center() + add("Use default promotions".toCheckBox(buildUnitWithPromotions) {city.unitTypeToPromotion[unitType] = 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 80db4a595742f..a599117ca3a4f 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt @@ -81,15 +81,7 @@ class PromotionPickerScreen private constructor( rightSideButton.onClick(UncivSound.Silent) { acceptPromotion(selectedPromotion) - 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.unitTypeToPromotion.put(unit.baseUnit.unitType,true) - unitCurrentCity.cityUnitTypePromotions.put(unit.baseUnit.unitType,unit.promotions) - } - } + checkSaveUnitTypePrormotion() } } else { rightSideButton.isVisible = false @@ -214,6 +206,19 @@ class PromotionPickerScreen private constructor( 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.unitTypeToPromotion.put(unit.baseUnit.unitType,true) + unitCurrentCity.cityUnitTypePromotions.put(unit.baseUnit.unitType,unit.promotions) + } + } + } + private fun getButton(tree: PromotionTree, node: PromotionTree.PromotionNode) : PromotionButton { val isPickable = canPromoteNow && (!node.pathIsAmbiguous || node.distanceToAdopted == 1) && @@ -241,6 +246,7 @@ class PromotionPickerScreen private constructor( if (isPickable) button.onDoubleClick(UncivSound.Silent) { acceptPromotion(button) + checkSaveUnitTypePrormotion() } return button From 547a393edd343b0634f47660485f574bee4e6d2f Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Thu, 13 Feb 2025 15:24:14 +0100 Subject: [PATCH 26/27] change name and added ! --- core/src/com/unciv/logic/city/City.kt | 4 ++-- core/src/com/unciv/logic/city/CityConstructions.kt | 2 +- .../com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt | 4 ++-- .../unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/com/unciv/logic/city/City.kt b/core/src/com/unciv/logic/city/City.kt index 2e71900a59349..53d4351cd2090 100644 --- a/core/src/com/unciv/logic/city/City.kt +++ b/core/src/com/unciv/logic/city/City.kt @@ -93,7 +93,7 @@ class City : IsPartOfGameInfoSerialization, INamed { var isPuppet = false var shouldReassignPopulation = false // flag so that on startTurn() we reassign population - var unitTypeToPromotion = HashMap() + var buildUnitTypePromotion = HashMap() var cityUnitTypePromotions = HashMap() @@ -158,7 +158,7 @@ class City : IsPartOfGameInfoSerialization, INamed { toReturn.avoidGrowth = avoidGrowth toReturn.manualSpecialists = manualSpecialists toReturn.connectedToCapitalStatus = connectedToCapitalStatus - toReturn.unitTypeToPromotion = unitTypeToPromotion + toReturn.buildUnitTypePromotion = buildUnitTypePromotion toReturn.cityUnitTypePromotions = cityUnitTypePromotions return toReturn } diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 626324ab1833b..e7fc45ca07bc0 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -470,7 +470,7 @@ class CityConstructions : IsPartOfGameInfoSerialization { // and null check. // and finally check if the current unit has enough XP. val savedPromotion = city.cityUnitTypePromotions[unit.baseUnit.unitType] - if (city.unitTypeToPromotion[unit.baseUnit.unitType] == true && + if (city.buildUnitTypePromotion[unit.baseUnit.unitType] == true && savedPromotion != null && unit.promotions.XP >= savedPromotion.XP) { for (promotions in savedPromotion.promotions) { diff --git a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt index 3f414d1fd4e3b..b13ce714d9c42 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt @@ -103,11 +103,11 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { if (construction is BaseUnit) { val unitType = construction.unitType - val buildUnitWithPromotions = city.unitTypeToPromotion[unitType] + val buildUnitWithPromotions = city.buildUnitTypePromotion[unitType] if (buildUnitWithPromotions != null) { row() - add("Use default promotions".toCheckBox(buildUnitWithPromotions) {city.unitTypeToPromotion[unitType] = it}).colspan(2).center() + add("Use default promotions".toCheckBox(buildUnitWithPromotions) {city.buildUnitTypePromotion[unitType] = 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 a599117ca3a4f..cdbab41f1df9f 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt @@ -208,12 +208,12 @@ class PromotionPickerScreen private constructor( // going to reuse this bit of code 2 time so turn it into a funtion private fun checkSaveUnitTypePrormotion() { - if (saveUnitTypePromotion) { + 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.unitTypeToPromotion.put(unit.baseUnit.unitType,true) + unitCurrentCity.buildUnitTypePromotion.put(unit.baseUnit.unitType,true) unitCurrentCity.cityUnitTypePromotions.put(unit.baseUnit.unitType,unit.promotions) } } From 503fbe10277f2c2fd98082e9c33c3f710a55794e Mon Sep 17 00:00:00 2001 From: Emandac <121508218+Emandac@users.noreply.github.com> Date: Thu, 13 Feb 2025 18:55:31 +0100 Subject: [PATCH 27/27] updated name of variable --- core/src/com/unciv/logic/city/City.kt | 4 ++-- core/src/com/unciv/logic/city/CityConstructions.kt | 2 +- .../com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt | 4 ++-- .../unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/logic/city/City.kt b/core/src/com/unciv/logic/city/City.kt index 53d4351cd2090..1dfab78de53a9 100644 --- a/core/src/com/unciv/logic/city/City.kt +++ b/core/src/com/unciv/logic/city/City.kt @@ -93,7 +93,7 @@ class City : IsPartOfGameInfoSerialization, INamed { var isPuppet = false var shouldReassignPopulation = false // flag so that on startTurn() we reassign population - var buildUnitTypePromotion = HashMap() + var unitTypeShouldUseSavedPromotion = HashMap() var cityUnitTypePromotions = HashMap() @@ -158,7 +158,7 @@ class City : IsPartOfGameInfoSerialization, INamed { toReturn.avoidGrowth = avoidGrowth toReturn.manualSpecialists = manualSpecialists toReturn.connectedToCapitalStatus = connectedToCapitalStatus - toReturn.buildUnitTypePromotion = buildUnitTypePromotion + toReturn.unitTypeShouldUseSavedPromotion = unitTypeShouldUseSavedPromotion toReturn.cityUnitTypePromotions = cityUnitTypePromotions return toReturn } diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index e7fc45ca07bc0..7d97a02fb1473 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -470,7 +470,7 @@ class CityConstructions : IsPartOfGameInfoSerialization { // and null check. // and finally check if the current unit has enough XP. val savedPromotion = city.cityUnitTypePromotions[unit.baseUnit.unitType] - if (city.buildUnitTypePromotion[unit.baseUnit.unitType] == true && + if (city.unitTypeShouldUseSavedPromotion[unit.baseUnit.unitType] == true && savedPromotion != null && unit.promotions.XP >= savedPromotion.XP) { for (promotions in savedPromotion.promotions) { diff --git a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt index b13ce714d9c42..35cf12005cc9d 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt @@ -103,11 +103,11 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() { if (construction is BaseUnit) { val unitType = construction.unitType - val buildUnitWithPromotions = city.buildUnitTypePromotion[unitType] + val buildUnitWithPromotions = city.unitTypeShouldUseSavedPromotion[unitType] if (buildUnitWithPromotions != null) { row() - add("Use default promotions".toCheckBox(buildUnitWithPromotions) {city.buildUnitTypePromotion[unitType] = it}).colspan(2).center() + add("Use default promotions".toCheckBox(buildUnitWithPromotions) {city.unitTypeShouldUseSavedPromotion[unitType] = 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 cdbab41f1df9f..d186832624558 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/PromotionPickerScreen.kt @@ -213,7 +213,7 @@ class PromotionPickerScreen private constructor( if (unitCurrentCity != null) { // If you are clicked the save unitType promotion, you want the next unitType to have the same promotion. - unitCurrentCity.buildUnitTypePromotion.put(unit.baseUnit.unitType,true) + unitCurrentCity.unitTypeShouldUseSavedPromotion.put(unit.baseUnit.unitType,true) unitCurrentCity.cityUnitTypePromotions.put(unit.baseUnit.unitType,unit.promotions) } }