OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
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 std::string _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.c_str();
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.clear();
149 SlObject(
nullptr, _game_language_header);
152 for (uint i = 0; i < _game_saveload_strings; i++) {
153 SlObject(
nullptr, _game_language_string);
154 ls.
lines.emplace_back(_game_saveload_string);
171 static void Save_GSTR()
182 {
'GSTR', Save_GSTR, Load_GSTR,
nullptr,
nullptr, CH_ARRAY },
183 {
'GSDT', Save_GSDT, Load_GSDT,
nullptr,
nullptr, CH_ARRAY |
CH_LAST},
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.
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
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.
@ CH_LAST
Last chunk in this array.
#define SLEG_SSTR(variable, type)
Storage of a global std::string in every savegame version.
Handlers and description of chunk.
Owner
Enum for all companies/owners.
@ SLF_ALLOW_CONTROL
allow control codes in the strings
#define DEBUG(name, level,...)
Output a line of debugging information.
const char * GetName() const
Get the name of the Script.
#define SLE_END()
End marker of a struct/class save or load.
bool IsRandom() const
Is the current Script a randomly chosen Script?
GameStrings * _current_data
The currently loaded game strings.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
bool _networking
are we in networking mode?
std::vector< LanguageStrings > raw_strings
The raw strings per language, first must be English/the master language!.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
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.
std::string language
Name of the language (base filename). Empty string if invalid.
#define SLEG_VAR(variable, type)
Storage of a global variable in every savegame version.
#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.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
static void Save()
Save data from a GameScript to a savegame.
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.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
@ SSS_FORCE_GAME
Get the Script config from the current game.
#define lastof(x)
Get the last element of an fixed size array.
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.