Fix #10334: Store separate newgrf-safe version of date_of_last_service #11124
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
When a player uses the date cheat, it shifts the
date_of_last_service
for all vehicles. This variable is exposed to NewGRF authors, who can cause crashes by doing creative things with said variable, like changing #10334.Also, my ongoing NotDayLength work (#10700) will require NewGRFs to read the calendar date while servicing is based on the economy date.
Description
If we provide a separate
date_of_last_service_newgrf
to the NewGRF API, we can solve both needs. This was started by @PeterN in #10721 — thanks for that! 😄 I rebased, made a few small changes, and (unlike #10721) actually tested to make sure it works! It does indeed fix #10334. 😉I don't know if this is the right approach, but it's time to figure it out so I can move forward with #10700.
Note: NotDayLength will need a similar split with the
build_year
property of vehicles, since aging and renewal is based on economy time while NewGRFs need a stable calendar year for their mischef. That would be orphaned now, so I'll save it for when we actually split off economy time.Closes #10334.
Supersedes and closes #10721.
Limitations
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.