OpenTTD Source
12.0-beta2
|
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;
28 static bool _game_saveload_is_random;
30 static const SaveLoad _game_script_desc[] = {
33 SLEG_VAR(
"version", _game_saveload_version, SLE_UINT32),
34 SLEG_VAR(
"is_random", _game_saveload_is_random, SLE_BOOL),
37 static void SaveReal_GSDT(
int *index_ptr)
42 _game_saveload_name = config->
GetName();
46 _game_saveload_name.clear();
47 _game_saveload_version = -1;
50 _game_saveload_is_random = config->
IsRandom();
53 SlObject(
nullptr, _game_script_desc);
69 _game_saveload_version = -1;
79 if (!_game_saveload_name.empty()) {
80 config->
Change(_game_saveload_name.c_str(), _game_saveload_version,
false, _game_saveload_is_random);
84 config->
Change(_game_saveload_name.c_str(), -1,
false, _game_saveload_is_random);
86 if (_game_saveload_name.compare(
"%_dummy") != 0) {
87 Debug(script, 0,
"The savegame has an GameScript by the name '{}', version {} which is no longer available.", _game_saveload_name, _game_saveload_version);
88 Debug(script, 0,
"This game will continue to run without GameScript.");
90 Debug(script, 0,
"The savegame had no GameScript available at the time of saving.");
91 Debug(script, 0,
"This game will continue to run without GameScript.");
94 Debug(script, 0,
"The savegame has an GameScript by the name '{}', version {} which is no longer available.", _game_saveload_name, _game_saveload_version);
95 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.");
99 _game_saveload_version = -1;
122 static std::string _game_saveload_string;
123 static uint32 _game_saveload_strings;
127 inline static const SaveLoad description[] = {
136 for (
const auto &
string : ls->
lines) {
137 _game_saveload_string = string;
146 for (uint32 i = 0; i < length; i++) {
148 ls->
lines.emplace_back(_game_saveload_string);
153 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.
@ SL_MIN_VERSION
First savegame version.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
bool _network_server
network-server is active
static void Load(int version)
Load data for a GameScript from a savegame.
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
void Load() const override
Load the chunk.
Handlers and description of chunk.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
A trimmed down version of what std::span will be in C++20.
const char * GetName() const
Get the name of the Script.
#define SLEG_VAR(name, variable, type)
Storage of a global variable in every savegame version.
bool IsRandom() const
Is the current Script a randomly chosen Script?
GameStrings * _current_data
The currently loaded game strings.
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.
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
#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.
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
Container for the raw (unencoded) language strings of a language.
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.
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
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.
#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.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
void Change(const char *name, int version=-1, bool force_exact_match=false, bool is_random=false)
Set another Script to be loaded in this slot.
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.
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.
static void StartNew()
Start up a new GameScript.
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.
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.