OpenTTD Source
20240917-master-g9ab0a47812
|
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_t value = (int32_t)((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;
195 for (
auto &desc : settings_table) {
SaveLoadVersion version_to
Save/load the variable before this savegame version.
void PrepareOldDiffCustom()
Prepare for reading and old diff_custom by zero-ing the memory.
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
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.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
@ SLE_VAR_NULL
useful to write zeros in savegame.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
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.
void MakeValueValidAndWrite(const void *object, int32_t value) const
Make the value valid and then write it to the setting.
@ CH_READONLY
Chunk is never saved.
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.
@ SF_NO_NETWORK_SYNC
Do not synchronize over network (but it is saved if SF_NOT_IN_SAVE is not set).
fluid_settings_t * settings
FluidSynth settings handle.
bool _networking
are we in networking mode?
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
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.
@ 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
virtual void ResetToDefault(void *object) const =0
Reset the setting to its default value.
const SaveLoadCompat _settings_sl_compat[]
Original field order for _settings.
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.
int32_t Read(const void *object) const
Read the integer from the the actual setting.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
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.
@ SF_NOT_IN_SAVE
Do not save with savegame, basically client-based.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
uint16_t length
(Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
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.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
const SaveLoadCompat _gameopt_sl_compat[]
Original field order for _gameopt.
@ SLV_TABLE_CHUNKS
295 PR#9322 Introduction of CH_TABLE and CH_SPARSE_TABLE.
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.
constexpr VarType GetVarFileType(VarType type)
Get the FileType of a setting.