OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
15 #include "../settings_type.h"
16 #include "../settings_table.h"
17 #include "../network/network.h"
20 #include "../safeguards.h"
27 memset(_old_diff_custom, 0,
sizeof(_old_diff_custom));
40 uint options_to_load = GAME_DIFFICULTY_NUM - (has_no_town_council_tolerance ? 1 : 0);
44 bool old_diff_custom_used =
false;
45 for (uint i = 0; i < options_to_load && !old_diff_custom_used; i++) {
46 old_diff_custom_used = (_old_diff_custom[i] != 0);
49 if (!old_diff_custom_used)
return;
54 for (
const auto &name : _old_diff_settings) {
55 if (has_no_town_council_tolerance && name ==
"town_council_tolerance")
continue;
57 std::string fullname =
"difficulty." + name;
66 int32 value = (int32)((name ==
"max_loan" ? 1000 : 1) * _old_diff_custom[i++]);
79 std::vector<SaveLoad> saveloads;
92 saveloads.push_back(sd->
save);
165 static const SettingTable saveload_settings_tables[] = {
166 _difficulty_settings,
171 _pathfinding_settings,
175 static std::vector<SettingVariant> settings_table;
177 if (settings_table.empty()) {
178 for (
auto &saveload_settings_table : saveload_settings_tables) {
179 for (
auto &saveload_setting : saveload_settings_table) {
180 settings_table.push_back(saveload_setting);
185 return settings_table;
SaveLoadVersion version_to
Save/load the variable before this savegame version.
@ SF_NOT_IN_SAVE
Do not save with savegame, basically client-based.
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
static VarType GetVarFileType(VarType type)
Get the FileType of a setting.
static const SettingDesc * GetSettingFromName(const std::string_view name, const SettingTable &settings)
Given a name of setting, return a setting description from the table.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
bool _network_server
network-server is active
void MakeValueValidAndWrite(const void *object, int32 value) const
Make the value valid and then write it to the setting.
SaveLoad save
Internal structure (going to savegame, parts to config).
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
static std::vector< SaveLoad > GetSettingsDesc(const SettingTable &settings, bool is_loading)
Get the SaveLoad description for the SettingTable.
@ SLE_VAR_NULL
useful to write zeros in savegame.
@ SF_NO_NETWORK_SYNC
Do not synchronize over network (but it is saved if SF_NOT_IN_SAVE is not set).
uint16 length
(Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
SettingFlag flags
Handles how a setting would show up in the GUI (text/currency, etc.).
Handlers and description of chunk.
VarType conv
Type of the variable to be saved; this field combines both FileVarType and MemVarType.
void Save() const override
Save the chunk.
A trimmed down version of what std::span will be in C++20.
@ CH_READONLY
Chunk is never saved.
@ SLV_TABLE_CHUNKS
295 PR#9322 Introduction of CH_TABLE and CH_SPARSE_TABLE.
Base integer type, including boolean, settings.
constexpr const std::string & GetName() const
Get the name of this setting.
SaveLoadType cmd
The action to take with the saved/loaded type, All types need different action.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
fluid_settings_t * settings
FluidSynth settings handle.
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
bool _networking
are we in networking mode?
static constexpr const SettingDesc * GetSettingDesc(const SettingVariant &desc)
Helper to convert the type of the iterated settings description to a pointer to it.
void Load() const override
Load the chunk.
void Load() const override
Load the chunk.
const SaveLoadCompat _settings_sl_compat[]
Original field order for _settings.
static bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
Checks if some version from/to combination falls within the range of the active savegame version.
void LoadCheck(size_t) const override
Load the chunk for game preview.
Properties of config file settings.
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
int32 Read(const void *object) const
Read the integer from the the actual setting.
SettingTable GetSettingTable() const
Create a single table with all settings that should be stored/loaded in the savegame.
void HandleOldDiffCustom(bool savegame)
Reading of the old diff_custom array and transforming it to the new format.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
static void SaveSettings(const SettingTable &settings, void *object)
Save and load handler for settings.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
virtual bool IsIntSetting() const
Check whether this setting is an integer type setting.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
const SaveLoadCompat _gameopt_sl_compat[]
Original field order for _gameopt.
@ SLV_4
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
static void LoadSettings(const SettingTable &settings, void *object, const SaveLoadCompatTable &slct)
Save and load handler for settings.
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.