Skip to content

Refund wasted production as gold #4058

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

Merged
merged 4 commits into from
Jun 7, 2021
Merged

Refund wasted production as gold #4058

merged 4 commits into from
Jun 7, 2021

Conversation

Thyrum
Copy link
Contributor

@Thyrum Thyrum commented Jun 5, 2021

Any wasted production, from for instance a partially completed wonder or obsolete units, will now be refunded as gold (in a 1:1 ratio). When obsolete units get replaced by their new version, this code should probably be updated.

I first added the gold refund code in validateInProgressConstructions, but this function is only called upon endTurn. Hence a refund for a wonder build elsewhere would occur after the relevant turn instead of before the turn. Hence the implementation is now put in validateConstructionQueue.

The current implementation does result in code duplication between validateInProgressConstructions and validateConstructionQueue. Any ideas on how to neatly remove this duplication are appreciated.

Another thing to consider would be a notification/popup explaining why the gold was added, but this probably clutters the interface too much.

Fixes #4047

@Thyrum
Copy link
Contributor Author

Thyrum commented Jun 5, 2021

Just noticed a quite big bug. This only accounts for constructions that were in your queue when they became obsolete, not for ones that you had already removed from your queue. I will fix this shortly, until then this will be a draft.

@Thyrum Thyrum marked this pull request as draft June 5, 2021 16:59
Any wasted production, from for instance a partially completed wonder or
obsolete units, will now be refunded as gold (in a 1:1 ratio).

We update both at the start and end of the user turn. Updating at the
start to account for wonders completed after our previous turn and
updating at the end to account for obsolete buildings/units as a
consequence of our own turn.

When obsolete units get replaced by their upgraded version (as in civ 5)
this code should probably be updated.
@Thyrum
Copy link
Contributor Author

Thyrum commented Jun 5, 2021

The code has now been updated. This did however require calling validateInProgressConstructions from constructIfEnough since constructIfEnough is called at the start of each turn. It might therefore be better to add a startTurn function which calls both constructIfEnough and validateInProgressConstructions.

@Thyrum Thyrum marked this pull request as ready for review June 5, 2021 17:21
@ravignir
Copy link
Contributor

ravignir commented Jun 5, 2021

in civ5 all of the production invested into obsoleted units is transferred to progress towards their respective upgrades.

@Thyrum
Copy link
Contributor Author

Thyrum commented Jun 5, 2021

in civ5 all of the production invested into obsoleted units is transferred to progress towards their respective upgrades.

I am aware of this but decided not to implement this yet because the issue did not include this (and I still need to get a little more familiar with the codebase 🙃). It can always be added in a later pull request.

@SomeTroglodyte
Copy link
Collaborator

I'm not convinced the original game refunded you for a lost wonder race at all. I would be fully in favour of this if the refund ratio were moddable - then we could easily make it zero in the vanilla ruleset and thereby postpone the final decision while mods could do what they want...

Production for obsoleted units being preserved and applied to the successor units is IMHO a completely separate matter, as is production overflow - which Civ4 (four not five) definitely had, and Civ5 99.9% not.

@xlenstra
Copy link
Collaborator

xlenstra commented Jun 5, 2021

I'm not convinced the original game refunded you for a lost wonder race at all.

Here is a link saying it's a 1-to-1 ratio:
https://gaming.stackexchange.com/questions/126105/how-to-calculate-gold-earned-from-a-wonder-if-another-civilization-finishes-firs

[...], as is production overflow - which Civ4 (four not five) definitely had, and Civ5 99.9% not.

Actually, according to this page of the civ 5 forums, this is an extensively documented mechanic:
https://forums.civfanatics.com/threads/hammer-overflow.419352/

@ravignir
Copy link
Contributor

ravignir commented Jun 5, 2021

I've recorded all of the cases in vanilla civ5:

production.overflow.mp4
production.transfer.mp4
wonder.compensation.mp4

anyway, the topic on civfanatics linked by @xlenstra explains production overflow really well.

@SomeTroglodyte
Copy link
Collaborator

... and ravignir's input of course is beyond doubt. 👍

@ravignir
Copy link
Contributor

ravignir commented Jun 5, 2021

Here is what happens when an obsoleted unit has no upgrade:
https://user-images.githubusercontent.com/30041793/120907153-8c1f8200-c65f-11eb-9340-4ca25a31626b.mp4

You get a regular production overflow and nothing more.

@Thyrum
Copy link
Contributor Author

Thyrum commented Jun 6, 2021

So if I understand it correctly, we have observed that in Civ 5:

  • production spent on a wonder built elsewhere is converted into gold (with a 1:1 ratio, notified to the user via notification).
  • production spent on a unit which has become obsolete is put into the upgraded version of the unit.
  • all other 'overflow' production is stored separately (as overflow) and added to the production of the next turn. The overflow stored can be at most the current production income or cost of the last item (the one that caused overflow), whichever is greater.

I suggest these points get added to #663. I can implement the first two points quite easily and then have this branch merged. The third point can then be added in a later pull request.

@ravignir
Copy link
Contributor

ravignir commented Jun 6, 2021

So if I understand it correctly, we have observed that in Civ 5:

* production spent on a wonder built elsewhere is converted into gold (with a 1:1 ratio, notified to the user via notification).

* production spent on a unit which has become obsolete is put into the upgraded version of the unit.

* all other 'lost' production is stored separately (as overflow) and added to the production of the next turn. The overflow stored can be at most the current production income or cost of the last item (the one that caused overflow), whichever is greater.

I suggest these points get added to #663. I can implement the first to points quite easily and then have this branch merged. The third point can then be added in a later pull request.

yes, notice the 12 production invested into scout in the last video is lost forever.

@yairm210
Copy link
Owner

yairm210 commented Jun 6, 2021

This looks good - I have no comments at all on the existing code!
I do have another addition, though - if the user is getting refunded, the user notification (could not continue work on []) should also contain "Excess Production converted to [] Gold", in both the notification itself and the translation line in template.properties

@SomeTroglodyte
Copy link
Collaborator

The overflow stored can be at most...

Didn't I read a -1 somewhere?

Otherwise 👍. I could only add the reminder - If it's not too much hassle then allowing mods to change the behaviours implemented for this might be nice.

@Thyrum
Copy link
Contributor Author

Thyrum commented Jun 6, 2021

I have implemented both gold refund for wonders and changing obsolete units into their upgraded form (if available). The relevant notifications can be seen in the screenshots below. I currently only alert users of the unit production transfer if the relevant unit was queued. I have chosen to do it this way since you probably don't care for the production swap if the unit wasn't queued.

The civlopedia should probably also be updated to reflect the changes made.
image
image
(note the last screenshot has a comma in the notification, not a dot)

If a wonder is built somewhere else but the user has production in this
wonder, the production will be refunded as gold in a 1:1 ratio. A
notification will be shown to indicate this. This reflects the behaviour
in Civ 5.

If a unit becomes obsolete and an upgrade is available, the production
put into this unit will now be transferred to the upgraded version. If
the unit is queued, the queued unit will also be changed to the new
version and the user will be notified via notification.
@SomeTroglodyte
Copy link
Collaborator

Time to optimize the wording (not nitpicking, if this weren't so good I woudn't bother)? I feel the notifications are a bit long (I can already see the issues from people with 640x360 @ 72dpi screens) and 'has been obsolete' doesn't sound quite perfect... So, just thinking & feel free to ignore:

  • Could not continue work on [wonder], excess production converted to [goldAmount] gold = hmm - if it's guaranteed you'll be getting the "[wonder] has been built by those other meanies" note right alongside, might "Excess production for [wonder] converted to [goldAmount] gold = " suffice?
  • [oldUnit] has been obsolete and production will be changed to [newUnit] in [cityName]! = ... ... "[cityName] changed production from [oldUnit] to [newUnit]"? Maybe people are clever enought to guess - or learn - that the reason is obsoletion? Also: If N cities have these - maybe a single message "[count] cities..." with a LocationAction cycling through all of them? Just to save screen 'real estate'?

@avdstaaij
Copy link
Contributor

So if I understand it correctly, we have observed that in Civ 5:
(...)

  • all other 'lost' production is stored separately (as overflow) and added to the production of the next turn. The overflow stored can be at most the current production income or cost of the last item (the one that caused overflow), whichever is greater.

Minor note: I'm fairly sure that production put into a building that you then rush-buy is not refunded in any way.

@Thyrum
Copy link
Contributor Author

Thyrum commented Jun 6, 2021

I feel the notifications are a bit long

I totally agree but couldn't think of a shorter wording at that time. I will shorten the wording to your suggestions.

[...] and 'has been obsolete' doesn't sound quite perfect

I agree but the existing notification for removing obsolete constructions was

[construction] has been obsolete and will be removed from construction queue in [cityName]!

thus I used this wording in order to be more uniform. I would personally prefer to change the old and new notification to

[construction] has become obsolete and will be removed from construction queue in [cityName]!
[cityName] changed production from [oldUnit] to [newUnit]

Copy link
Collaborator

@SomeTroglodyte SomeTroglodyte left a comment

Choose a reason for hiding this comment

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

Sorry for accidentally hitting the green pill instead of the white one.

@Thyrum
Copy link
Contributor Author

Thyrum commented Jun 6, 2021

The notifications have now been shortened to what's below. Should I also just change the has been obsolete to has become obsolete in all .properties language files? Or do we maybe want to reword it entirely (because it is quite a long notification)?

[construction] has been obsolete and will be removed from construction queue in [cityName]! = 
[construction] has been obsolete and will be removed from construction queue in [amount] cities! = 
[cityName] changed production from [oldUnit] to [newUnit] = 
[amount] cities changed production from [oldUnit] to [newUnit] = 
Excess production for [wonder] converted to [goldAmount] gold = 

@yairm210
Copy link
Owner

yairm210 commented Jun 6, 2021

"has become obsolete"
Also if you want to make it shorter,

[construction] has become obsolete and was removed from the queue in [cityName] =

@ravignir
Copy link
Contributor

ravignir commented Jun 7, 2021

So if I understand it correctly, we have observed that in Civ 5:
(...)

  • all other 'lost' production is stored separately (as overflow) and added to the production of the next turn. The overflow stored can be at most the current production income or cost of the last item (the one that caused overflow), whichever is greater.

Minor note: I'm fairly sure that production put into a building that you then rush-buy is not refunded in any way.

yup, it is not.

@Thyrum
Copy link
Contributor Author

Thyrum commented Jun 7, 2021

Rewording of been obsolete -> become obsolete has been added. I think we are ready to merge.

@ajustsomebody
Copy link
Contributor

happy to see this resolved

@Thyrum
Copy link
Contributor Author

Thyrum commented Jun 7, 2021

For completeness sake, this is yet to be implemented and will require a different pull request:

all other 'overflow' production is stored separately (as overflow) and added to the production of the next turn. The overflow stored can be at most the current production income or cost of the last item (the one that caused overflow), whichever is greater.

@yairm210 yairm210 merged commit cd58f6a into yairm210:master Jun 7, 2021
Thyrum added a commit to Thyrum/Unciv that referenced this pull request Jun 8, 2021
As discussed on yairm210#4058, production (or hammer) overflow in Civ 5
is a thing and goes according to rules described on
https://forums.civfanatics.com/threads/hammer-overflow.419352/
This has been added to the game. There are no visual indicators for the
user yet. This will probably be added later.
yairm210 pushed a commit that referenced this pull request Jun 8, 2021
As discussed on #4058, production (or hammer) overflow in Civ 5
is a thing and goes according to rules described on
https://forums.civfanatics.com/threads/hammer-overflow.419352/
This has been added to the game. There are no visual indicators for the
user yet. This will probably be added later.
@Thyrum Thyrum deleted the refund branch June 8, 2021 18:47
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.

The game should compensate for the production wasted in certain situations
7 participants