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

Several mistakes with ending-year and extreme values #8512

Merged
merged 3 commits into from Jan 8, 2021

Conversation

TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Jan 7, 2021

Fixes #8050.

Motivation / Problem

While 2fd871e tried to re-add a removed feature, it was not sufficiently tested in edge-cases, causing some weird problems if people tried to push their luck:

  • Old (pre 0.7) savegames got their ending-year set to -1
  • Setting ending-year to MAX_YEAR made sure you could play on for-ever (well, till the uint32 wraps)
  • Setting ending-year to Never and starting in year 0 caused a nice "highscore" screen to be shown at the end of year 0

Description

Most of these problems were created because the code originally showed the high-score when you started the ending-year (2051); the new code makes this when you end the ending-year (2050), which, from a user perspective, makes much more sense. Sadly, this means there needs to be done + 1 and - 1 in some places, causing these weird quirks.

For the ending-year is MAX_YEAR problem, I decided to simply not allow ending-year to become MAX_YEAR, but at most MAX_YEAR - 1. Alternatively, we could record a variable that states if highscore has been done. But this would have to be stored in the savegame too. And as this is such an edge-case, that is troubling 99.999999% of our players with 4 more bytes in the savegame, for having a silly number line up. Alternatively, I considered bumping MAX_YEAR by 1 year, realising it was equally silly.

Regarding the pre 0.7 savegames, this was simply misunderstood in 2fd871e. The reason 683b65e removes ending-year, is because it was impossible to configure it to anything else than 2051. When opening the game, the ending-year was always reset to this value. Basically, it was a fixed value. In the savegames, it always stored 0.
My suspicion is that the code was written, but never really tested. At least, I do not see a way this could ever work, or someone happened to have a savegame where ending-year was written to the savegame (but I do not see how). I used the title-screen of pre 0.7 as example, where the value is 0.
Edit: seems I am not completely correct; there are even older savegames that did have this variable written correctly, as in, pre-0.5. It is difficult to confirm exactly when it broke. Either way, the code, from the moment of introduction of ending-year, was always resetting the setting to 2051 every time you started the game; I believe this was because the newspaper always showed 2050, and we didn't know how to fix this :D. Either way, I would consider it highly unlikely anyone managed to get a savegame with any other value anyway. Given this is also over 10 years ago, I still think this solution is more robust.

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

…00001 and beyond

MAX_YEAR is set to 5000000, but having an ending-year set to the
same meant you could bypass this, and play till the uint32 wrapped.

The game can either show highscore or wrap year, not both. When
you would do both, every year you get the highscore dialog.

By changing the maximum value of ending-year to 4999999 we prevent
this issue.
… you start in year zero

Using zero as "never" value can have its drawbacks ;)
Despite what it looked like, you could never really change the
ending-year (it was always reset to 2050 on start-up). See commit
683b65e for details. As a side-effect, the variable that was
suppose to store the ending-year was just zero, never containing
a real ending-year.
Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

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

I was never very happy with _old_ending_year_slv_105 anyway

@TrueBrain TrueBrain merged commit ef6b17b into OpenTTD:master Jan 8, 2021
@TrueBrain TrueBrain deleted the end-year-mixup branch January 8, 2021 10:17
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.

Scoring year is -1 when loading old savegame
2 participants