Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to save unitType promotion. #12894

Merged
merged 41 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9dd38f5
Settler settle best tile when not escort and dangerous Tiles instead …
Emandac Oct 22, 2024
ab36bac
Merge branch 'master' of https://github.com/Emandac/Unciv
Emandac Oct 24, 2024
3a67ef7
Merge branch 'yairm210:master' into master
Emandac Oct 27, 2024
919a082
Update WorkerAutomation.kt
Emandac Oct 30, 2024
ed21943
Update SpecificUnitAutomation.kt
Emandac Oct 30, 2024
b9a832a
Update WorkerAutomation.kt
Emandac Oct 30, 2024
5edf4b7
Update SpecificUnitAutomation.kt
Emandac Oct 30, 2024
545572f
Merge branch 'yairm210:master' into master
Emandac Nov 10, 2024
904e5a8
Merge branch 'yairm210:master' into master
Emandac Nov 15, 2024
938091f
Merge branch 'yairm210:master' into master
Emandac Dec 14, 2024
6faa088
Merge branch 'master' of https://github.com/Emandac/Unciv
Emandac Dec 30, 2024
aaabab0
Now city states get mad when you steal their Lands
Emandac Dec 30, 2024
cb96cff
new version
Emandac Dec 31, 2024
e400964
change to getDiplomacyManagerOrMeet
Emandac Dec 31, 2024
61f90fa
added text to template.properties and changed AlertPopup.kt
Emandac Dec 31, 2024
ff67bb7
Update template.properties
Emandac Dec 31, 2024
467e725
with period at the end :b
Emandac Dec 31, 2024
aa532e9
add flag now
Emandac Jan 1, 2025
5ee629f
Merge branch 'yairm210:master' into master
Emandac Jan 1, 2025
b300c51
Made Option to declare war when a city state is bullied unavailable
Emandac Jan 2, 2025
342d56a
Merge branch 'yairm210:master' into master
Emandac Jan 2, 2025
04f6be5
Merge branch 'yairm210:master' into master
Emandac Jan 10, 2025
1623290
added option to change the Maximum Autosave turns stored
Emandac Jan 11, 2025
4edcd24
remove print
Emandac Jan 11, 2025
0d5295e
change letter
Emandac Jan 11, 2025
1599dd2
should fix issue with building test
Emandac Jan 11, 2025
eab98f2
update with changes
Emandac Jan 11, 2025
bd60cc4
Merge branch 'yairm210:master' into master
Emandac Jan 19, 2025
4fadce6
Added UniqueType.FoundPuppetCity
Emandac Jan 19, 2025
9d0ac5f
Merge branch 'yairm210:master' into master
Emandac Jan 31, 2025
a7a2e75
Added save promotion
Emandac Feb 1, 2025
48d4770
Merge branch 'master' of https://github.com/Emandac/Unciv
Emandac Feb 1, 2025
eb54ab4
Merge branch 'yairm210:master' into master
Emandac Feb 7, 2025
dc00ad5
Updated for PR
Emandac Feb 7, 2025
ef0bb39
Updated with requested changes
Emandac Feb 8, 2025
fe66e04
Removed unnecessary check
Emandac Feb 8, 2025
bb78c9e
updated PR
Emandac Feb 9, 2025
b02d9cb
Merge branch 'yairm210:master' into master
Emandac Feb 11, 2025
74aa1ff
Update PromotionPickerScreen.kt to save promotion cells too
Emandac Feb 11, 2025
547a393
change name and added !
Emandac Feb 13, 2025
503fbe1
updated name of variable
Emandac Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 49 additions & 49 deletions android/assets/Icons.atlas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions android/assets/jsons/translations/template.properties
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Requires [PolicyOrNationalWonder] =
Cannot be purchased =
Can only be purchased =
See also =
Use default promotions =
Default promotions for [unitType] =

Requires at least one of the following: =
Requires all of the following: =
Expand Down
9 changes: 8 additions & 1 deletion core/src/com/unciv/logic/city/City.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,7 +92,11 @@ class City : IsPartOfGameInfoSerialization, INamed {
var hasSoldBuildingThisTurn = false
var isPuppet = false
var shouldReassignPopulation = false // flag so that on startTurn() we reassign population


var unitTypeToPromotion = HashMap<String, Boolean>()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, rename these :)

Copy link
Contributor Author

@Emandac Emandac Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a good name for this variable 😅

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly are you saving here? unitType is the key, sure but the value isn't promotion, is it?

Similarly the bottom hashmap
Maps should almost always be named in such a way that you can understand what is being mapped to what - "unitTypeTo" is a great start, e.g. "unitTypeToShouldUseSavedPromotion" or something

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorter is better, but "long and understandable" is better than "short but not understandable"

Copy link
Contributor Author

@Emandac Emandac Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would 'unitTypeBuildWithSavedPromtion' be a good name ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the boolen is true build unit with save promotion

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand - per city there are saved promotions per type, right?
And also you can decide to... Not use them?

Copy link
Contributor Author

@Emandac Emandac Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes like the player can build a unit without the saved promotion, like that with that unit they can change the save promotion to something else if needed

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this config will stick to all other units of this type?
By type do you mean like "archery" or like "archer"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

var cityUnitTypePromotions = HashMap<String, UnitPromotions>()

@delegate:Transient
val neighboringCities: List<City> by lazy {
civ.gameInfo.getCities().filter { it != this && it.getCenterTile().isExplored(civ) && it.getCenterTile().aerialDistanceTo(getCenterTile()) <= 12 }.toList()
Expand Down Expand Up @@ -153,6 +158,8 @@ class City : IsPartOfGameInfoSerialization, INamed {
toReturn.avoidGrowth = avoidGrowth
toReturn.manualSpecialists = manualSpecialists
toReturn.connectedToCapitalStatus = connectedToCapitalStatus
toReturn.unitTypeToPromotion = unitTypeToPromotion
toReturn.cityUnitTypePromotions = cityUnitTypePromotions
return toReturn
}

Expand Down
13 changes: 13 additions & 0 deletions core/src/com/unciv/logic/city/CityConstructions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,19 @@ 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.
// and finally check if the current unit has enough XP.
val savedPromotion = city.cityUnitTypePromotions[unit.baseUnit.unitType]
if (city.unitTypeToPromotion[unit.baseUnit.unitType] == true &&
savedPromotion != null && unit.promotions.XP >= savedPromotion.XP) {

for (promotions in savedPromotion.promotions) {
unit.promotions.addPromotion(promotions)
}
}
}

if (construction.name in inProgressConstructions)
Expand Down
1 change: 1 addition & 0 deletions core/src/com/unciv/ui/popups/CityScreenConstructionMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions core/src/com/unciv/ui/screens/cityscreen/ConstructionInfoTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +91,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)) {
Expand All @@ -99,6 +100,16 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() {
selectedConstructionTable.add(button).padTop(5f).colspan(2).center().row()
}
}
if (construction is BaseUnit) {
val unitType = construction.unitType

val buildUnitWithPromotions = city.unitTypeToPromotion[unitType]

if (buildUnitWithPromotions != null) {
row()
add("Use default promotions".toCheckBox(buildUnitWithPromotions) {city.unitTypeToPromotion[unitType] = it}).colspan(2).center()
}
}
}
}

Expand Down Expand Up @@ -133,7 +144,7 @@ class ConstructionInfoTable(val cityScreen: CityScreen) : Table() {
}
}
}

private fun sellBuildingClicked(construction: Building, sellText: String) {
cityScreen.closeAllPopups()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,6 +65,8 @@ 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 {
Expand All @@ -77,6 +80,8 @@ class PromotionPickerScreen private constructor(
rightSideButton.setText("Pick promotion".tr())
rightSideButton.onClick(UncivSound.Silent) {
acceptPromotion(selectedPromotion)

checkSaveUnitTypePrormotion()
}
} else {
rightSideButton.isVisible = false
Expand Down Expand Up @@ -191,9 +196,29 @@ class PromotionPickerScreen private constructor(
}

topTable.add(promotionsTable)
saveUnitTypePromotionForCity()
addConnectingLines(emptySet())
}


// adds the checkBoxs to choice to save unit promotion.
private fun saveUnitTypePromotionForCity() {
val checkBoxSaveUnitPromotion = "Default promotions for [${unit.baseUnit.unitType}]".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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverse the if checks, e.g. if (!save) return

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) &&
Expand Down Expand Up @@ -221,6 +246,7 @@ class PromotionPickerScreen private constructor(
if (isPickable)
button.onDoubleClick(UncivSound.Silent) {
acceptPromotion(button)
checkSaveUnitTypePrormotion()
}

return button
Expand Down Expand Up @@ -352,7 +378,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)
Expand Down
Loading