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"
25static std::string _game_saveload_name;
26static int _game_saveload_version;
27static std::string _game_saveload_settings;
29static 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),
35static 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;
118static std::string _game_saveload_string;
119static 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);
149static const SaveLoad _game_language_desc[] = {
Default handler for saving/loading an object to/from disk.
SaveLoadTable GetDescription() const override
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
static void Save()
Save data from a GameScript to a savegame.
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
@ SSS_FORCE_GAME
Get the Script config from the current game.
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
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.
const std::string & GetName() const
Get the name of the Script.
int GetVersion() const
Get the version of the Script.
void StringToSettings(const std::string &value)
Convert a string which is stored in the config file or savegames to custom settings of this Script.
std::string SettingsToString() const
Convert the custom settings to a string that can be stored in the config file or savegames.
static ScriptData * Load(int version)
Load data from a savegame.
static void LoadEmpty()
Load and discard data from a savegame.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
GameStrings * _current_data
The currently loaded game strings.
Loading for game chunks before table headers were added.
const SaveLoadCompat _game_language_string_sl_compat[]
Original field order for SlGameLanguageString.
const SaveLoadCompat _game_language_sl_compat[]
Original field order for _game_language_desc.
const SaveLoadCompat _game_script_sl_compat[]
Original field order for _game_script_desc.
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlAutolength(AutolengthProc *proc, int arg)
Do something of which I have no idea what it is :P.
void SlSetStructListLength(size_t length)
Set the length of this list.
Functions/types related to saving and loading games.
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
#define SLEG_SSTR(name, variable, type)
Storage of a global std::string in every savegame version.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
#define SLEG_VAR(name, variable, type)
Storage of a global variable in every savegame version.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
@ SL_MIN_VERSION
First savegame version.
Handlers and description of chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
Container for all the game strings.
std::vector< LanguageStrings > raw_strings
The raw strings per language, first must be English/the master language!.
void Compile()
Compile the language.
Container for the raw (unencoded) language strings of a language.
StringList lines
The lines of the file to pass into the parser/encoder.