12 #include "../stdafx.h" 15 #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 char _game_saveload_name[64];
26 static int _game_saveload_version;
27 static char _game_saveload_settings[1024];
28 static bool _game_saveload_is_random;
30 static const SaveLoad _game_script[] = {
31 SLEG_STR(_game_saveload_name, SLE_STRB),
32 SLEG_STR(_game_saveload_settings, SLE_STRB),
33 SLEG_VAR(_game_saveload_version, SLE_UINT32),
34 SLEG_VAR(_game_saveload_is_random, SLE_BOOL),
38 static void SaveReal_GSDT(
int *index_ptr)
47 _game_saveload_name[0] =
'\0';
48 _game_saveload_version = -1;
51 _game_saveload_is_random = config->
IsRandom();
52 _game_saveload_settings[0] =
'\0';
59 static void Load_GSDT()
66 _game_saveload_version = -1;
78 config->
Change(_game_saveload_name, _game_saveload_version,
false, _game_saveload_is_random);
82 config->
Change(_game_saveload_name, -1,
false, _game_saveload_is_random);
84 if (strcmp(_game_saveload_name,
"%_dummy") != 0) {
85 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);
86 DEBUG(script, 0,
"This game will continue to run without GameScript.");
88 DEBUG(script, 0,
"The savegame had no GameScript available at the time of saving.");
89 DEBUG(script, 0,
"This game will continue to run without GameScript.");
92 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);
93 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.");
97 _game_saveload_version = -1;
110 static void Save_GSDT()
118 static const char *_game_saveload_string;
119 static uint _game_saveload_strings;
121 static const SaveLoad _game_language_header[] = {
123 SLEG_VAR(_game_saveload_strings, SLE_UINT32),
127 static const SaveLoad _game_language_string[] = {
134 _game_saveload_string = ls->
language;
137 SlObject(NULL, _game_language_header);
138 for (uint i = 0; i < _game_saveload_strings; i++) {
139 _game_saveload_string = ls->
lines[i];
140 SlObject(NULL, _game_language_string);
144 static void Load_GSTR()
150 _game_saveload_string = NULL;
151 SlObject(NULL, _game_language_header);
154 for (uint i = 0; i < _game_saveload_strings; i++) {
155 SlObject(NULL, _game_language_string);
156 *ls->
lines.
Append() =
stredup(_game_saveload_string != NULL ? _game_saveload_string :
"");
165 _current_data = NULL;
173 static void Save_GSTR()
175 if (_current_data == NULL)
return;
184 {
'GSTR', Save_GSTR, Load_GSTR, NULL, NULL, CH_ARRAY },
185 {
'GSDT', Save_GSDT, Load_GSDT, NULL, NULL, CH_ARRAY |
CH_LAST},
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.
AutoDeleteSmallVector< LanguageStrings *, 4 > raw_strings
The raw strings per language, first must be English/the master language!.
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.
T * Append(uint to_add=1)
Append an item and return it.
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.
uint Length() const
Get the number of items in the list.
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.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
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.
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
const char * language
Name of the language (base filename).
Owner
Enum for all companies/owners.
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.