10 #include "../stdafx.h" 13 #include "../string_func.h" 15 #include "../game/game.hpp" 16 #include "../game/game_config.hpp" 17 #include "../network/network.h" 18 #include "../game/game_instance.hpp" 19 #include "../game/game_text.hpp" 21 #include "../safeguards.h" 23 static char _game_saveload_name[64];
24 static int _game_saveload_version;
25 static char _game_saveload_settings[1024];
26 static bool _game_saveload_is_random;
28 static const SaveLoad _game_script[] = {
29 SLEG_STR(_game_saveload_name, SLE_STRB),
30 SLEG_STR(_game_saveload_settings, SLE_STRB),
31 SLEG_VAR(_game_saveload_version, SLE_UINT32),
32 SLEG_VAR(_game_saveload_is_random, SLE_BOOL),
36 static void SaveReal_GSDT(
int *index_ptr)
45 _game_saveload_name[0] =
'\0';
46 _game_saveload_version = -1;
49 _game_saveload_is_random = config->
IsRandom();
50 _game_saveload_settings[0] =
'\0';
57 static void Load_GSDT()
64 _game_saveload_version = -1;
76 config->
Change(_game_saveload_name, _game_saveload_version,
false, _game_saveload_is_random);
80 config->
Change(_game_saveload_name, -1,
false, _game_saveload_is_random);
82 if (strcmp(_game_saveload_name,
"%_dummy") != 0) {
83 DEBUG(script, 0,
"The savegame has an GameScript by the name '%s', version %d which is no longer available.", _game_saveload_name, _game_saveload_version);
84 DEBUG(script, 0,
"This game will continue to run without GameScript.");
86 DEBUG(script, 0,
"The savegame had no GameScript available at the time of saving.");
87 DEBUG(script, 0,
"This game will continue to run without GameScript.");
90 DEBUG(script, 0,
"The savegame has an GameScript by the name '%s', version %d which is no longer available.", _game_saveload_name, _game_saveload_version);
91 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.");
95 _game_saveload_version = -1;
108 static void Save_GSDT()
116 static const char *_game_saveload_string;
117 static uint _game_saveload_strings;
119 static const SaveLoad _game_language_header[] = {
121 SLEG_VAR(_game_saveload_strings, SLE_UINT32),
125 static const SaveLoad _game_language_string[] = {
132 _game_saveload_string = ls->
language;
133 _game_saveload_strings = (uint)ls->
lines.size();
135 SlObject(
nullptr, _game_language_header);
136 for (
const auto &i : ls->
lines) {
137 _game_saveload_string = i.c_str();
138 SlObject(
nullptr, _game_language_string);
142 static void Load_GSTR()
148 _game_saveload_string =
nullptr;
149 SlObject(
nullptr, _game_language_header);
151 std::unique_ptr<LanguageStrings> ls(
new LanguageStrings(_game_saveload_string !=
nullptr ? _game_saveload_string :
""));
152 for (uint i = 0; i < _game_saveload_strings; i++) {
153 SlObject(
nullptr, _game_language_string);
154 ls->
lines.emplace_back(_game_saveload_string !=
nullptr ? _game_saveload_string :
"");
157 _current_data->
raw_strings.push_back(std::move(ls));
163 _current_data =
nullptr;
171 static void Save_GSTR()
173 if (_current_data ==
nullptr)
return;
175 for (uint i = 0; i < _current_data->
raw_strings.size(); i++) {
182 {
'GSTR', Save_GSTR, Load_GSTR,
nullptr,
nullptr, CH_ARRAY },
183 {
'GSDT', Save_GSDT, Load_GSDT,
nullptr,
nullptr, CH_ARRAY |
CH_LAST},
Owner
Enum for all companies/owners.
bool _networking
are we in networking mode?
#define SLEG_STR(variable, type)
Storage of a global string in every savegame version.
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
Container for all the game strings.
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.
#define lastof(x)
Get the last element of an fixed size array.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
#define SLEG_VAR(variable, type)
Storage of a global variable in every savegame version.
const char * GetName() const
Get the name of the Script.
static void Save()
Save data from a GameScript to a savegame.
bool IsRandom() const
Is the current Script a randomly chosen Script?
Functions/types related to saving and loading games.
allow control codes in the strings
bool HasScript() const
Is this config attached to an Script? In other words, is there a Script that is assigned to this slot...
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
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.
static void StartNew()
Start up a new GameScript.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Handlers and description of chunk.
#define DEBUG(name, level,...)
Output a line of debugging information.
#define SLE_END()
End marker of a struct/class save or load.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
bool _network_server
network-server is active
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
static void Load(int version)
Load data for a GameScript from a savegame.
std::vector< std::unique_ptr< LanguageStrings > > raw_strings
The raw strings per language, first must be English/the master language!.
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
const char * language
Name of the language (base filename).
static void LoadEmpty()
Load and discard data from a savegame.
void StringToSettings(const char *value)
Convert a string which is stored in the config file or savegames to custom settings of this Script...
void SettingsToString(char *string, const char *last) const
Convert the custom settings to a string that can be stored in the config file or savegames.
Get the Script config from the current game.
Last chunk in this array.
GameStrings * _current_data
The currently loaded game strings.
int GetVersion() const
Get the version of the Script.