Commit Graph

172 Commits

Author SHA1 Message Date
glx22 6e627f35ac Cleanup: Remove now unneeded ChunkHandler members 2021-07-06 22:29:08 +02:00
glx22 c1a9fe6fbd Codechange: Use static array of references to ChunkHandler 2021-07-06 22:29:08 +02:00
glx22 f371a5ad70 Codechange: Preparation for ChunkHandler subclassing 2021-07-06 22:29:08 +02:00
Loïc Guilloux ddafc0de05
Fix 39e90ec: Integers for scripts are 64bit, but saved as 32bit (#9415) 2021-07-06 21:09:08 +02:00
Patric Stout 4e645ce749 Codechange: using "until" in function names can be confusing
IsSavegameVersionUntil() did a [0, N] check, not [0, N) as the
name suggests.

Until can be a confusing word, where people consider it to be
including the upperbound. Dictionary states it means "before",
excluding the upperbound. There are long debates about who is right.

So, simply remove away from this ambiguity, and call it "before"
and "before or at". This makes the world easier for everyone.
2021-07-02 22:21:58 +02:00
Patric Stout 1ed2405907 Cleanup: remove SLE_NULL and friends
We no longer need them. If you want to remove a field .. just
remove it! Because of the headers in the savegame, on loading,
it will do the right thing and skip the field.

Do remember to bump the savegame version, as otherwise older
clients can still load the game, but will reset the field you
have removed .. that might be unintentially.
2021-07-02 22:21:58 +02:00
Patric Stout 3826703bc3 Add: store headers for chunks with SL_STRUCTLIST 2021-07-02 22:21:58 +02:00
Patric Stout 7dd5fd6ed4 Feature: framework to make savegames self-descriptive
We won't be able to make it fully self-descriptive (looking at you
MAP-chunks), but anything else can. With this framework, we can
add headers for each chunk explaining how each chunk looks like
in detail.

They also will all be tables, making it a lot easier to read in
external tooling, and opening the way to consider a database
(like SQLite) to use as savegame format.

Lastly, with the headers in the savegame, you can freely add
fields without needing a savegame version bump; older versions
of OpenTTD will simply ignore the new field. This also means
we can remove all the SLE_CONDNULL, as they are irrelevant.

The next few commits will start using this framework.
2021-07-02 22:21:58 +02:00
rubidium42 f7f1d530b8 Codechange: instead of "naked" initializer lists, declare the type in the saveload macros
This to help variant's constructor to be able to resolve the constructor of the setting
2021-06-26 20:28:34 +02:00
Rubidium 281a65b3e1 Cleanup: simplify some boolean expressions 2021-06-17 16:18:30 +02:00
Patric Stout 8e91527251 Codechange: mark chunks that are not stored as CH_READONLY
This makes it easier to spot chunks that have a save_proc that
is a nullptr, but also prevents confusion, where it looks like
the CH_ type of a chunk has influence on how it is being read.
It is not, it is only used for saving.
2021-06-15 19:36:15 +02:00
Patric Stout 88edfd4ef1 Change: rework several CH_RIFF chunks to use CH_ARRAY instead
This adds two byte extra to those chunks, and might feel a bit
silly at first. But in later changes we will prefix CH_ARRAY with
a table header, and then this change shines.

Without this, we could still add headers to these chunks, but any
external reader wouldn't know if the CH_RIFF has them or not. This
way is much more practical, as they are now more like any other
chunk.
2021-06-15 19:36:15 +02:00
Patric Stout b9ab9e4d05 Codechange: add the ability to save/load a std::vector
std::vector<bool> is not possible, as .. that is a nice special
case in C++.

This new type will be used in next commit.
2021-06-15 19:36:15 +02:00
Patric Stout 97b94bdc9a Change: prefix SL_ARR with the length of the array
This means that during loading we can validate that what is saved
is also that what is expected. Additionally, this makes all list
types similar to how they are stored on disk:
First a gamma to indicate length, followed by the data.
The size still depends on the type.
2021-06-15 16:45:04 +02:00
Patric Stout d5cda58158 Codechange: use SL_NULL if you want to store null-bytes or load to nothing
Using SL_ARR for this gives us a bit of trouble later on, where we
add a length-field to SL_ARR. This of course is not the intention
of SLE_CONDNULL. So better seperate it.
2021-06-15 16:45:04 +02:00
Patric Stout a146bcfe93 Change: store length of SL_STRUCTLIST in the savegame
This wasn't consistently done, and often variables were used that
were read by an earlier blob. By moving it next to the struct
itself, the code becomes a bit more self-contained and easier to
read.

Additionally, this allows for external tooling to know how many
structs to expect, instead of having to know where to find the
length-field or a hard-coded value that can change at any moment.
2021-06-15 16:45:04 +02:00
Patric Stout 4e4720f217 Codechange: remove the special station/vehicle code from SaveLoad
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.
2021-06-14 21:58:05 +02:00
Patric Stout 4600d289b5 Codechange: ability to store structs and list of structs in savegames
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.
2021-06-14 21:58:05 +02:00
Tyler Trahan d09210e1c6 Feature: Configurable subsidy duration 2021-06-10 23:26:16 +02:00
Patric Stout 8f323855b1 Codechange: rename SL_LST to SL_REFLIST to highlight the "reference" part
You can easily mistake SlList / SL_LST to be a list of SL_VAR, but
it is a list of SL_REF. With this rename, it hopefully saves a few
people from "wtf?" moments.
2021-06-10 19:18:24 +02:00
Patric Stout fba86f711f Codechange: move GetVariableAddress inside SlObjectMember
Also move it to static, as nobody else is using it.
2021-06-10 19:18:24 +02:00
Patric Stout 1e564b333f
Codechange: make [Save|Load]Settings() behave more like other Save/Load code (#9335)
Prepare the full description and send it to SlObject. This does
require some code to be able to read to a SLE_VAR_NULL, like strings
etc, as there is no way to know their length beforehand.
2021-06-07 23:03:12 +02:00
Patric Stout 648ee88a02 Codechange: merge guiflags and flags in settings .ini files
It was rather confusing which one was for what, especially as some
SaveLoad flags were settings-only. Clean up this mess a bit by
having only Setting flags.
2021-06-06 21:45:01 +02:00
Patric Stout 264991dfa5 Codechange: move SLF_NO_NETWORK_SYNC into settings
It is a settings-only flag, so don't pollute SaveLoad code with it.
2021-06-06 21:45:01 +02:00
Patric Stout 7572603c9d Codechange: remove the unused SLF_HEX flag 2021-06-06 21:45:01 +02:00
glx22 c27afdf3f6 Codechange: Remove FOR_ALL_CHUNK_HANDLERS
Co-Authored-By: Patric Stout <truebrain@openttd.org>
2021-06-06 19:35:06 +02:00
Patric Stout 9fff00ba20
Codechange: C++-ify lists for SaveLoad (#9323)
Basically, this changes "SaveLoad *" to either:
1) "SaveLoadTable" if a list of SaveLoads was meant
2) "SaveLoad &" if a single entry was meant

As added bonus, this removes SL_END / SLE_END / SLEG_END. This
also adds core/span.hpp, a "std::span"-lite.
2021-05-31 22:26:44 +02:00
rubidium42 0f062b3882 Codechange: clean up C-string support from settings 2021-05-13 23:13:17 +02:00
rubidium42 95386dc2b8 Codechange: move misc settings to std::string 2021-05-13 23:13:17 +02:00
William Davis 881e1da51d
Change: Use gender-neutral pronouns in console command messages (and comments) (#9203) 2021-05-08 11:02:30 +01:00
peter1138 a05bc04b63 Feature: Per-group wagon removal flag. 2021-04-22 22:57:00 +02:00
Patric Stout 13a5264438 Fix: store the recent new game_creation settings in savegames
This allows us to later on see what someone did, and makes sure
that "restart" command still knows how the game was created.
2021-03-26 12:22:32 +01:00
Patric Stout 9bfa7198fd
Change: Heading for 1.12 now (#8862) 2021-03-14 20:47:31 +01:00
Michael Lutz 7845434270 Codechange: Don't use cpp_offsetof in the save/load code.
Many of the member variables that are used in save/load are inside types
that are not standard layout types. Using pointer arithmetics to determine
addresses of members inside types that are not standard layout is generally
undefined behaviour. If we'd use C++17, it is conditionally supported, which means
each compiler may or may not support it. And even then using it for individual
array elements is syntactically not supported the the standard offsetof function.

Unfortunately, the trickery employed for saving linkgraph settings causes quite some
clutter in the settings ini files.
2021-02-13 20:08:53 +01:00
dP bab7de6cf2 Feature: Allow GameScripts to add additional text to Industry view window 2021-01-22 09:50:53 +00:00
Michael Lutz 7da224d29d
Fix #8589, 653e7fa548: Motion counter is NewGRF-visible but not saved, leading to desyncs. (#8591) 2021-01-18 21:11:38 +01:00
Michael Lutz 5cbb2da794 Codechange: Even more std::string usage in file IO. 2020-12-27 13:19:25 +01:00
Michael Lutz 65f65ad2ad Codechange: Convert some more FIO functions to take std::string. 2020-12-27 13:19:25 +01:00
cirdan 395a5d9991 Cleanup: Remove unused ChunkType flag CH_AUTO_LENGTH
CH_AUTO_LENGTH is no longer used anywhere, so remove all code
that depends on it.
2020-12-27 10:30:55 +00:00
Pavel Stupnikov 9a45a0f535
Feature: Set exclusive access to industry from GS (#8115) 2020-12-22 14:29:48 +01:00
Niels Martin Hansen b7751c483e
Feature: Influence industry production changes from GS (#7912) 2020-12-22 14:21:31 +01:00
Patric Stout d8c8f4e72d
Fix: next 67 savegame versions are used in PatchPacks; skip them (#8411)
Various of PatchPacks (Spring 2013, Joker, ChillPP) used versions
slightly higher than ours. Of course, as time went by, this
caught up with us, and we are now almost pushing a new version
that would conflict with them. To avoid users creating unneeded
issues about "why can I not load my savegame", lets be ahead of
the curve and flat-out refuse to load them.

Version-wise, this is totally fine. We have ~32k versions to go
before we run out (0x8000 is masked by JGRPP; we should avoid
using that). At the rate we bump savegames, this is not going to
happen in any sane reality.
2020-12-22 10:44:07 +01:00
Patric Stout c98717cb45 Fix: do not add an offset to a nullptr
This is, by specs, undefined behaviour. See
https://reviews.llvm.org/D67122

In cases where this is done, optimizations done by LLVM can
generate code that causes crashes.

GetVariableAddress() had two (legit) ways this could happen:
- For SaveLoad set to global
- For SaveLoad set to SLE_VAR_NULL, where sld->address is always
  a nullptr, and object could or could not be a nullptr.
2020-12-06 16:10:58 +01:00
dP 452e1e3328 Codechange #8258: Remove unused town cargo caches from the savegame 2020-07-27 17:32:00 +01:00
dP ca2604c4e2 Revert #8157: Redundant change 2020-06-28 18:23:59 +02:00
Jonathan G Rennison 7a09413a1a Fix: Incorrect save/load array size of Town::cargo_accepted
In 11ab3c4e the number of cargo types was changed from 32 to 64.
The save/load of Town::cargo_accepted was not updated, such that
only half of the data structure is saved/loaded in savegame versions
199 to 218.
Discard and regenerate data from all savegame versions prior to 219.
2020-06-28 15:32:53 +02:00
Jonathan G Rennison 54237b0e98 Codechange: Move SlSkipBytes to saveload.h 2020-06-28 15:32:53 +02:00
Charles Pigott 64b1c70fdd Codechange: Add WARN_FORMAT to vseprintf and fix the cascade of warnings that followed 2020-06-27 14:51:14 +01:00
Michael Lutz 9b6f5e3bb8 Codechange: Store GS lang texts in std::strings. 2020-05-21 20:02:34 +02:00
Yexo 64278fd598 Fix: reset roadtype/streetcartype info for non-road bridges 2020-05-06 22:10:08 +02:00
glx 2f264f2c92 Change: Heading for 1.11 now 2020-02-08 23:38:49 +01:00
Johannes E. Krause 107283748a Feature: SLF_HEX to print hexadecimal numbers in the config file 2020-02-06 21:00:30 +00:00
Niels Martin Hansen 2fd871e2af Feature: Configurable game ending year
Functionally reverts 683b65ee1
2019-12-28 12:27:39 +01:00
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 2019-11-10 17:59:20 +00:00
Jack Baron e4f08f2880 Fix: Bump savegame version 2019-10-19 20:31:44 +01:00
JMcKiern 04f659e768 Fix: Some typos found using codespell 2019-09-29 21:27:32 +01:00
peter1138 f538179878 Feature: Multi-tile docks and docking points. 2019-06-30 16:46:32 +02:00
Niels Martin Hansen 140a96b3a0 Change: Limit memory allocations for each Squirrel instance
This can avoid out-of-memory situations due to single scripts using up the entire address space.
Instead, scripts that go above the maximum are killed.
The maximum is default 1 GB per script, but can be configured by a setting.
2019-05-11 15:34:33 +02:00
peter1138 c02ef3e456 Feature: Add NotRoadTypes (NRT) 2019-05-01 21:36:27 +02:00
Henry Wilson 7c8e7c6b6e Codechange: Use null pointer literal instead of the NULL macro 2019-04-10 23:22:20 +02:00
Peter Nelson f6264e5212 Change: Bump savegame version for tree tile water class conversion. 2019-03-24 15:16:54 +00:00
Charles Pigott fe448a2616 Remove: OPF 2019-03-16 22:30:11 +00:00
PeterN 6c6971fb43
Add: Road vehicle path cache. (#7261) 2019-03-08 23:52:45 +00:00
PeterN dd20ccee88
Feature: Industries with neutral stations (e.g. Oil Rig) only supply/accept cargo to/from their neutral station. (#7234)
This change is a controlled by a game setting, located under Environment ->
Industries which allows toggling the behaviour. It defaults to enabled.

"Company stations can serve industries with attached neutral stations"

When enabled, industries with attached neutral station (such as Oil Rigs) may
also be served by company-owned stations built nearby. This is the traditional
behaviour.

When disabled, these industries may only be served by their neutral station.
Any nearby company-owned stations won't be able to serve them, nor will the
neutral station serve anything else other than the industry.
2019-03-08 18:30:44 +00:00
Peter Nelson b8a0107ad1 Change: Add configurable curve penalty for ships. 2019-03-08 16:52:08 +01:00
Niels Martin Hansen 52572cafa6 Add: Option for population-linear town cargo generation
Introduce a new default algorithm for town cargo generation (passengers and mail), and a game setting to choose between the new and original algorithm.

The original town cargo generation algorithm has the property of the generated amount relating to the square of each building's population, meaning large towns easily produce more cargo than can realistically be transported. The problem is excessive cargo is amplified if playing with cargodist.

The new algorithm introduced instead has a linear relation to the population. The result is that smaller towns will produce slightly more cargo, while the largest towns will produce about a fourth of what they would with the original algorithm.

Existing savegames will use the original algorithm, while new games will default to the new algorithm.
2019-03-04 20:19:44 +01:00
frosch a67ee02529
Change: Heading for 1.10 now (#7319) 2019-03-03 20:51:57 +01:00
PeterN c0c8fb25fb
Change: Use SlErrorCorrupt() on pool index error when loading a savegame, instead of terminating. (#7219) 2019-02-13 09:01:49 +00:00
Peter Nelson 64878320cc Fix #6803: CargoMonitorID bit packing updated to handle 64 cargo types.
This requires a saveload bump to change the bitpacking on loading older saves.
2019-02-04 20:43:14 +00:00
Peter Nelson 0b10678050 Change: Make ships stop in locks to move up/down instead of following the slope. 2019-02-04 20:20:49 +00:00
Peter Nelson e21ade375e Codechange: Change from numeric to descriptive SLV enum labels for last entries. 2019-02-02 21:39:06 +00:00
Peter Nelson 0f37a683a2 Codechange: Additional type safety for saveload version variables. 2019-02-02 21:39:06 +00:00
Peter Nelson 9de12521ec Codechange: Convert saveload numbers to enum values.
(This was mostly achieved with a few in-place regexes)
2019-02-02 21:39:06 +00:00
Peter Nelson ea4ea62816 Codechange: Make saveload version upper bound exclusive, i.e. version object was removed instead of version object last appeared. 2019-02-02 21:39:06 +00:00
Peter Nelson 67633606b0 Codechange: Remove value mangling and field misuse in SLE_WRITEBYTE.
The original translation functionality hasn't been used since 2007.
2019-01-30 17:11:40 +00:00
Peter Nelson 1c725fce47 Change: Add ability to save/load std::deque<> containers. 2019-01-19 23:11:17 +00:00
Charles Pigott f5b1115039 Doc: Lots and lots of doxymentation fixes 2018-10-31 12:35:54 +01:00
Charles Pigott 2aacddd412 Codechange: lengthof is not defined for runtime-length strings, use sizeof instead 2018-06-27 22:54:46 +02:00
frosch fc4c4d080c (svn r27757) -Change: Make StringID 32bit. 2017-02-26 19:41:14 +00:00
alberth 0adfb1ac6f (svn r27653) -Fix(r27647): Rename FileOperation enum and values to SaveLoadOperation to avoid nameclash with windows compiler toolkit. 2016-09-04 16:06:50 +00:00
alberth 6f201ce4a8 (svn r27651) -Codechange: Introduce methods for setting the name and title of _file_to_saveload. 2016-09-04 12:58:04 +00:00
alberth 597380e099 (svn r27650) -Codechange: Replace SaveOrLoadMode by FileOperation and DetailedFileType. 2016-09-04 12:57:43 +00:00
alberth 2fa0fdb176 (svn r27638) -Codechange: Move FiosType enum, move and rename SetFiosType function. 2016-09-04 12:47:07 +00:00
alberth 087ed1e999 (svn r27636) -Codechange: Rename FileType to AbstractFileType. 2016-09-04 12:46:07 +00:00
alberth 9135f7130e (svn r27635) -Codechange: Move FileType and FileToSaveLoad structure definitions. 2016-09-04 12:45:40 +00:00
rubidium 46792e58dd (svn r26591) -Add: some instrumentation to catch most cases where the wrong number of bytes would be written into variables during loading (or read during saving) 2014-05-16 17:41:55 +00:00
frosch b0a063ed77 (svn r25702) -Add: about 3000 years of savegame compatibility. 2013-08-08 19:01:02 +00:00
rubidium 0cc3d8df4b (svn r25258) -Codechange: save linkgraph (fonsinchen) 2013-05-19 14:17:02 +00:00
truebrain 5cda1d7c90 (svn r23603) -Add: support for control commands in strings, in both network and safe/load (Rubidium) 2011-12-19 20:50:44 +00:00
rubidium df16ebd730 (svn r23595) -Codechange: add comma after last enum to get a more uniform coding style 2011-12-19 17:48:04 +00:00
rubidium c9a7f572ec (svn r23195) -Codechange: if we really need to cast away constness, use const_cast 2011-11-12 08:37:12 +00:00
frosch 275a394bc1 (svn r22880) -Cleanup: SIZE_MAX is now defined in stdafx.h 2011-09-03 12:17:36 +00:00
terkhen 00e5c1df18 (svn r22567) -Codechange: Store persistent storages inside a pool. 2011-06-12 20:47:45 +00:00
rubidium e48967541a (svn r22198) -Codechange: make some constants name more explicit 2011-03-05 11:16:44 +00:00
rubidium befa79ba4a (svn r22070) -Fix [FS#4503] (r21399): crashes when disconnecting after requesting the map 2011-02-12 21:30:57 +00:00
smatz 887a7724dc (svn r22025) -Fix: verify there is enough space in the pool when creating new pool items while loading old savegames 2011-02-08 18:34:13 +00:00
rubidium 085c693289 (svn r21395) -Codechange: move the save and load filter's interface to a header 2010-12-05 14:41:34 +00:00
alberth 3e27739287 (svn r21284) -Codechange: Rename CheckSavegameVersion() to IsSavegameVersionBefore(). 2010-11-21 12:47:04 +00:00
alberth 5f8afaadb7 (svn r21283) -Codechange: Allow minor argument IsSavegameVersionBefore() to be optional. 2010-11-21 12:38:16 +00:00
alberth edef25d30c (svn r21282) -Codechange: Rename CheckSavegameVersionOldStyle() to IsSavegameVersionBefore(). 2010-11-21 12:31:16 +00:00