OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
16 #include "../string_func.h"
17 #include "../game/game.hpp"
18 #include "../game/game_config.hpp"
19 #include "../network/network.h"
20 #include "../game/game_instance.hpp"
21 #include "../game/game_text.hpp"
23 #include "../safeguards.h"
25 static std::string _game_saveload_name;
26 static int _game_saveload_version;
27 static std::string _game_saveload_settings;
29 static const SaveLoad _game_script_desc[] = {
30 SLEG_SSTR(
"name", _game_saveload_name, SLE_STR),
31 SLEG_SSTR(
"settings", _game_saveload_settings, SLE_STR),
32 SLEG_VAR(
"version", _game_saveload_version, SLE_UINT32),
35 static void SaveReal_GSDT(
int)
40 _game_saveload_name = config->
GetName();
44 _game_saveload_name.clear();
45 _game_saveload_version = -1;
50 SlObject(
nullptr, _game_script_desc);
66 _game_saveload_version = -1;
76 if (!_game_saveload_name.empty()) {
77 config->
Change(_game_saveload_name, _game_saveload_version,
false);
81 config->
Change(_game_saveload_name, -1,
false);
83 if (_game_saveload_name.compare(
"%_dummy") != 0) {
84 Debug(script, 0,
"The savegame has an GameScript by the name '{}', version {} which is no longer available.", _game_saveload_name, _game_saveload_version);
85 Debug(script, 0,
"This game will continue to run without GameScript.");
87 Debug(script, 0,
"The savegame had no GameScript available at the time of saving.");
88 Debug(script, 0,
"This game will continue to run without GameScript.");
91 Debug(script, 0,
"The savegame has an GameScript by the name '{}', version {} which is no longer available.", _game_saveload_name, _game_saveload_version);
92 Debug(script, 0,
"The latest version of that GameScript has been loaded instead, but it'll not get the savegame data as it's incompatible.");
96 _game_saveload_version = -1;
118 static std::string _game_saveload_string;
119 static uint32_t _game_saveload_strings;
123 inline static const SaveLoad description[] = {
132 for (
const auto &
string : ls->
lines) {
133 _game_saveload_string = string;
142 for (uint32_t i = 0; i < length; i++) {
144 ls->
lines.emplace_back(_game_saveload_string);
149 static const SaveLoad _game_language_desc[] = {
Default handler for saving/loading an object to/from disk.
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
@ SL_MIN_VERSION
First savegame version.
bool _network_server
network-server is active
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
void Load() const override
Load the chunk.
Handlers and description of chunk.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
void Change(std::optional< const std::string > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
static ScriptData * Load(int version)
Load data from a savegame.
#define SLEG_VAR(name, variable, type)
Storage of a global variable in every savegame version.
GameStrings * _current_data
The currently loaded game strings.
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
const SaveLoadCompat _game_language_string_sl_compat[]
Original field order for SlGameLanguageString.
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
void Save() const override
Save the chunk.
#define SLEG_SSTR(name, variable, type)
Storage of a global std::string in every savegame version.
bool _networking
are we in networking mode?
std::vector< LanguageStrings > raw_strings
The raw strings per language, first must be English/the master language!.
static void LoadEmpty()
Load and discard data from a savegame.
Container for the raw (unencoded) language strings of a language.
void SlAutolength(AutolengthProc *proc, int arg)
Do something of which I have no idea what it is :P.
int GetVersion() const
Get the version of the Script.
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
void Save() const override
Save the chunk.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
std::string SettingsToString() const
Convert the custom settings to a string that can be stored in the config file or savegames.
SaveLoadTable GetDescription() const override
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
const SaveLoadCompat _game_script_sl_compat[]
Original field order for _game_script_desc.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
void Load() const override
Load the chunk.
static void Save()
Save data from a GameScript to a savegame.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
StringList lines
The lines of the file to pass into the parser/encoder.
void Compile()
Compile the language.
const SaveLoadCompat _game_language_sl_compat[]
Original field order for _game_language_desc.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlSetStructListLength(size_t length)
Set the length of this list.
@ SSS_FORCE_GAME
Get the Script config from the current game.
Container for all the game strings.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
const std::string & GetName() const
Get the name of the Script.
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.