Codechange: add and use the ability to store (lists of) structs in savegames #9339
Motivation / Problem
In a few places (stations, vehicles, towns, companies, ..) the SaveLoad code needs to handle either structs in structs, or lists of structs in structs.
This is all done manually, and not only hard to read, also easy to mess up.
For example, for Vehicles it used to have a special
Now, the common vehicle sub-struct is called
This works with structs in structs in structs in structs in structs in ... just fine too.
NOTE: I made several commits to introduce
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.
The text was updated successfully, but these errors were encountered:
The commits following this will use this new functionality. Currently, a few places do this manually. This has as drawback that the Save() and Load() code need to be in sync, and that any change can result in (old) savegames no longer loading. In general, it is annoying code to maintain. By putting everything in a description table, and use that for both Save() and Load(), it becomes easier to see what is going on, and hopefully less likely for people to make mistakes.
With the new SLEG_STRUCT it is much easier to embed a struct in a struct, where the sub-struct has limitations on when it is being used. This makes both the code easier to read (less magic) and avoids the SaveLoad needing to know all these things about Stations and Vehicles.
There was a lot of code duplication for no real reason. Now with SLEG_STRUCT support, we can just re-use the code, hopefully making it easier for future-us to make changes to this, without breaking everything for old games.