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

Conversation

Emandac
Copy link
Contributor

@Emandac Emandac commented Feb 1, 2025

This is to save unitType promotion, to not have to redo it when you are building an another unit with the same unitType.
This can help if you are building units in bulk with the same unitType and promotions.

…of running away

Settler unit will now settle on best tile in dangerous Tiles without escort instead of running away.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
with "Founds a new puppet city" in "uniques" of an unit in Units.json.
Making it so you can now settle a puppet city.
@Emandac Emandac marked this pull request as draft February 2, 2025 20:13
@@ -113,6 +113,7 @@ Requires [PolicyOrNationalWonder] =
Cannot be purchased =
Can only be purchased =
See also =
Build units with saved UnitType promotion =
Copy link
Contributor

@sulai sulai Feb 3, 2025

Choose a reason for hiding this comment

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

Edit: I noticed the checkbox is only shown when a default promotion was previously saved, so I think it's a good spot to place the checkbox!

Having the limited screen space on Android in mind, please keep the caption as short as possible. For example:
[ ] auto promote


// adds the checkBoxs to choice to save unit promotion.
private fun saveUnitTypePromotionForCity() {
val checkBoxSaveUnitPromotion = "Save unitType promotions.".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it}
Copy link
Contributor

@sulai sulai Feb 3, 2025

Choose a reason for hiding this comment

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

The wording could be better. Short and descriptive and no period at the end. What about:

[ ] default for <Warrior>

in case you are promoting a Warrior. And in the city screen the checkbox would say

[ ] default promotions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this but instead Warrior it could be Sword to not mislead the player into thinking it's only for the warrior unit😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Emandac Emandac marked this pull request as ready for review February 7, 2025 20:54
@@ -113,6 +113,8 @@ Requires [PolicyOrNationalWonder] =
Cannot be purchased =
Can only be purchased =
See also =
Default promotions =
"Default promotions for [unitType] =
Copy link
Owner

Choose a reason for hiding this comment

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

Extra "

// To not have to redo it for every unit build afterword.
var canBuildUnitTypeWithSavedPromotion = HashMap<String, Boolean>()

// To stroe unitType to promotion.
Copy link
Owner

Choose a reason for hiding this comment

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

Remove comment, call this "unitTypeToPromotion"
We already know it's for city since it's in the city class

// 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 &&
Copy link
Owner

Choose a reason for hiding this comment

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

Unnecessary check, "== true" is enough

savedPromotion != null) {

// check if current unit has enough ep
if (unit.promotions.XP >= savedPromotion.XP) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can be merged into previous if

if (city.canBuildUnitTypeWithSavedPromotion[unitType] != null) {
row()
add(city.canBuildUnitTypeWithSavedPromotion[unitType]?.let {
"Default promotions".toCheckBox(
Copy link
Owner

Choose a reason for hiding this comment

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

Do not use .let here, instead use regular assignment
If this is bull then you'd get add(null) which is not what we want, probably


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)
Copy link
Owner

Choose a reason for hiding this comment

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

I'm unclear why we need this second hashmap

Copy link
Contributor Author

@Emandac Emandac Feb 8, 2025

Choose a reason for hiding this comment

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

This hashmap needed for the checkbox at ConstructionInfoTable.kt to turn on and off the auto promotion of the unit

Copy link
Owner

Choose a reason for hiding this comment

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

So the name should be like "should" etc, "can" usually means "is there nothing preventing us while "should" means "do we want to". "Can" is about ability, "Should" is about desire.

More philosophically, Can and Should sit on opposite sides of Hume's Guillotine.


// adds the checkBoxs to choice to save unit promotion.
private fun saveUnitTypePromotionForCity() {
val checkBoxSaveUnitPromotion = "Default promotions for ${unit.baseUnit.unitType}".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it}
Copy link
Owner

Choose a reason for hiding this comment

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

Wrap parameter in square brackets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like this [saveUnitTypePromotion] ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

More like val checkBoxSaveUnitPromotion = "Default promotions for [${unit.baseUnit.unitType}]".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it} - the square brackets are part of the string and passed to the translation engine, which will then translate Default promotions for [placeholder] and the unit type string separately...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohhh ok 😅

if (construction is BaseUnit) {
val unitType = construction.unitType

if (city.unitTypeToPromotion[unitType] != null) {
Copy link
Owner

Choose a reason for hiding this comment

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

Extract city.unitTypeToPromotion[unitType] into val - you use it 3 times here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The {city.unitTypeToPromotion[unitType] = it} it's to avoid adding an another line just to assign it, in the updated version.

@Emandac
Copy link
Contributor Author

Emandac commented Feb 11, 2025

Is it normal that I still have the "changes requested" 😅


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

Choose a reason for hiding this comment

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

Why is this not "for unittype" like the other one?

Copy link
Contributor

Choose a reason for hiding this comment

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

To save space on android-portrait. Because this text is in the info table of the unit, the context is set and it's clear that the checkbox counts for this unit type only.

"Default promotions" is very short and descriptive, but I could also live with
"use Default promotions" if that sounds better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and i also added that clicking a promotion button when save promotion is on to save it too.
Just like promotion pick button.


// 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



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

@yairm210
Copy link
Owner

I think it's good enough for now, can always change it later

@yairm210 yairm210 merged commit 2a8edb3 into yairm210:master Feb 13, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants