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

inaccurate _cur_month and _cur_year in daily / monthly loops #5241

Closed
DorpsGek opened this issue Jul 10, 2012 · 4 comments
Closed

inaccurate _cur_month and _cur_year in daily / monthly loops #5241

DorpsGek opened this issue Jul 10, 2012 · 4 comments
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay

Comments

@DorpsGek
Copy link
Member

dihedral opened the ticket and wrote:

IncreaseDate() has the little downside of setting _cur_month and _cur_year only if a new month / new year respectively has been detected.
These checks are done after OnNewDay() is called, in order to run the various DailyLoop() functions.

This means that on the first of every month the variables _cur_month and (on the 1st Jan.) _cur_year have not yet been updated and cause incorrect calculations (e.g. DoDisaster() run from the DisasterDailyLoop() makes use of _cur_year).

Find attached a Patch which addresses this minor bug and provides a fix, making sure _cur_month and _cur_year are set before any of the OnNew(Day|Month|Year)() are called.

Attachments

Reported version: trunk
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/5241
@DorpsGek
Copy link
Member Author

frosch wrote:

This patch breaks a lot.

About 50% of the usages of _cur_month are in the OnNewMonth() call, and they all assume that it refers to the previous month.
_cur_year is a little less transparent since it is used a lot.


This comment was imported from FlySpray: https://bugs.openttd.org/task/5241#comment11477

@DorpsGek
Copy link
Member Author

dihedral wrote:

Could you point me to some parts of the code, because I did look at every method called (recursively) starting at the OnNew<Day|Month|Year>() looking for every use of _cur_month and _cur_year.

using _cur_month in OnNewMonth() is no problem - the problem exists when using _cur_month in OnNewDay() and using _cur_year in OnNewMonth().
further more, _cur_month ranges form 0 (January) to 11 (December).

So the problem that actually rises is only on the first of a new month and the first of a new year - resulting in 'quarterly run' code to be executed on the second of a month and not on the first.


This comment was imported from FlySpray: https://bugs.openttd.org/task/5241#comment11479

@DorpsGek
Copy link
Member Author

frosch wrote:

Sorry, I thought the patch did more changes than it actually did.

It only affects a few corner cases where the daily loops check the current year to stop certain things, like inflation or engine aging.


This comment was imported from FlySpray: https://bugs.openttd.org/task/5241#comment11589

@DorpsGek
Copy link
Member Author

frosch closed the ticket.

Reason for closing: Implemented

in r24592


This comment was imported from FlySpray: https://bugs.openttd.org/task/5241

@DorpsGek DorpsGek added Core flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay labels Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay
Projects
None yet
Development

No branches or pull requests

1 participant