OpenTTD Source  20241108-master-g80f628063a
settings_internal.h File Reference

Functions and types used internally for the settings configurations. More...

#include <variant>
#include "saveload/saveload.h"

Go to the source code of this file.

Data Structures

struct  SettingDesc
 Properties of config file settings. More...
 
struct  IntSettingDesc
 Base integer type, including boolean, settings. More...
 
struct  BoolSettingDesc
 Boolean setting. More...
 
struct  OneOfManySettingDesc
 One of many setting. More...
 
struct  ManyOfManySettingDesc
 Many of many setting. More...
 
struct  StringSettingDesc
 String settings. More...
 
struct  ListSettingDesc
 List/array settings. More...
 
struct  NullSettingDesc
 Placeholder for settings that have been removed, but might still linger in the savegame. More...
 

Typedefs

typedef std::variant< IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDescSettingVariant
 
typedef std::span< const SettingVariant > SettingTable
 

Enumerations

enum  SettingFlag : uint16_t {
  SF_NONE = 0 , SF_GUI_0_IS_SPECIAL = 1 << 0 , SF_GUI_DROPDOWN = 1 << 2 , SF_GUI_CURRENCY = 1 << 3 ,
  SF_NETWORK_ONLY = 1 << 4 , SF_NO_NETWORK = 1 << 5 , SF_NEWGAME_ONLY = 1 << 6 , SF_SCENEDIT_TOO = 1 << 7 ,
  SF_SCENEDIT_ONLY = 1 << 8 , SF_PER_COMPANY = 1 << 9 , SF_NOT_IN_SAVE = 1 << 10 , SF_NOT_IN_CONFIG = 1 << 11 ,
  SF_NO_NETWORK_SYNC = 1 << 12
}
 
enum  SettingCategory {
  SC_NONE = 0 , SC_BASIC_LIST = 1 << 0 , SC_ADVANCED_LIST = 1 << 1 , SC_EXPERT_LIST = 1 << 2 ,
  SC_BASIC = SC_BASIC_LIST | SC_ADVANCED_LIST | SC_EXPERT_LIST , SC_ADVANCED = SC_ADVANCED_LIST | SC_EXPERT_LIST , SC_EXPERT = SC_EXPERT_LIST , SC_END
}
 A SettingCategory defines a grouping of the settings. More...
 
enum  SettingType { ST_GAME , ST_COMPANY , ST_CLIENT , ST_ALL }
 Type of settings for filtering. More...
 

Functions

static constexpr const SettingDescGetSettingDesc (const SettingVariant &desc)
 Helper to convert the type of the iterated settings description to a pointer to it. More...
 
const SettingDescGetSettingFromName (const std::string_view name)
 Given a name of any setting, return any setting description of it. More...
 
void GetSaveLoadFromSettingTable (SettingTable settings, std::vector< SaveLoad > &saveloads)
 Get the SaveLoad for all settings in the settings table. More...
 
bool SetSettingValue (const IntSettingDesc *sd, int32_t value, bool force_newgame=false)
 Top function to save the new value of an element of the Settings struct. More...
 
bool SetSettingValue (const StringSettingDesc *sd, const std::string value, bool force_newgame=false)
 Set a setting value with a string. More...
 

Detailed Description

Functions and types used internally for the settings configurations.

Definition in file settings_internal.h.

Enumeration Type Documentation

◆ SettingCategory

A SettingCategory defines a grouping of the settings.

The group SC_BASIC is intended for settings which also a novice player would like to change and is able to understand. The group SC_ADVANCED is intended for settings which an experienced player would like to use. This is the case for most settings. Finally SC_EXPERT settings only few people want to see in rare cases. The grouping is meant to be inclusive, i.e. all settings in SC_BASIC also will be included in the set of settings in SC_ADVANCED. The group SC_EXPERT contains all settings.

Enumerator
SC_BASIC_LIST 

Settings displayed in the list of basic settings.

SC_ADVANCED_LIST 

Settings displayed in the list of advanced settings.

SC_EXPERT_LIST 

Settings displayed in the list of expert settings.

SC_BASIC 

Basic settings are part of all lists.

SC_ADVANCED 

Advanced settings are part of advanced and expert list.

SC_EXPERT 

Expert settings can only be seen in the expert list.

Definition at line 41 of file settings_internal.h.

◆ SettingFlag

enum SettingFlag : uint16_t
Enumerator
SF_GUI_0_IS_SPECIAL 

A value of zero is possible and has a custom string (the one after "strval").

SF_GUI_DROPDOWN 

The value represents a limited number of string-options (internally integer) presented as dropdown.

SF_GUI_CURRENCY 

The number represents money, so when reading value multiply by exchange rate.

SF_NETWORK_ONLY 

This setting only applies to network games.

SF_NO_NETWORK 

This setting does not apply to network games; it may not be changed during the game.

SF_NEWGAME_ONLY 

This setting cannot be changed in a game.

SF_SCENEDIT_TOO 

This setting can be changed in the scenario editor (only makes sense when SF_NEWGAME_ONLY is set).

SF_SCENEDIT_ONLY 

This setting can only be changed in the scenario editor.

SF_PER_COMPANY 

This setting can be different for each company (saved in company struct).

SF_NOT_IN_SAVE 

Do not save with savegame, basically client-based.

SF_NOT_IN_CONFIG 

Do not save to config file.

SF_NO_NETWORK_SYNC 

Do not synchronize over network (but it is saved if SF_NOT_IN_SAVE is not set).

Definition at line 16 of file settings_internal.h.

◆ SettingType

Type of settings for filtering.

Enumerator
ST_GAME 

Game setting.

ST_COMPANY 

Company setting.

ST_CLIENT 

Client setting.

ST_ALL 

Used in setting filter to match all types.

Definition at line 60 of file settings_internal.h.

Function Documentation

◆ GetSaveLoadFromSettingTable()

void GetSaveLoadFromSettingTable ( SettingTable  settings,
std::vector< SaveLoad > &  saveloads 
)

Get the SaveLoad for all settings in the settings table.

Parameters
settingsThe settings table to get the SaveLoad objects from.
saveloadsA vector to store the result in.

Definition at line 1641 of file settings.cpp.

References GetSettingDesc(), SettingDesc::save, settings, SlIsObjectCurrentlyValid(), SaveLoad::version_from, and SaveLoad::version_to.

◆ GetSettingDesc()

static constexpr const SettingDesc* GetSettingDesc ( const SettingVariant &  desc)
staticconstexpr

Helper to convert the type of the iterated settings description to a pointer to it.

Parameters
descThe type of the iterator of the value in SettingTable.
Returns
The actual pointer to SettingDesc.

Definition at line 392 of file settings_internal.h.

Referenced by GetSaveLoadFromSettingTable(), GetSettingFromName(), GetSettingsDesc(), IniLoadSettings(), IniSaveSettings(), PATSChunkHandler::Load(), LoadSettings(), RemoveEntriesFromIni(), and SurveySettingsTable().

◆ GetSettingFromName()

const SettingDesc* GetSettingFromName ( const std::string_view  name)

Given a name of any setting, return any setting description of it.

Parameters
nameName of the setting to return a setting description of.
Returns
Pointer to the setting description of setting name if it can be found, nullptr indicates failure to obtain the description.

Definition at line 1669 of file settings.cpp.

References GenericSettingTables(), GetCompanySettingFromName(), GetSettingFromName(), PrivateSettingTables(), and SecretSettingTables().

◆ SetSettingValue() [1/2]

bool SetSettingValue ( const IntSettingDesc sd,
int32_t  value,
bool  force_newgame 
)

Top function to save the new value of an element of the Settings struct.

Parameters
indexoffset in the SettingDesc array of the Settings struct which identifies the setting member we want to change
valuenew value of the setting
force_newgameforce the newgame settings

Definition at line 1744 of file settings.cpp.

References _local_company, SettingDesc::AsIntSetting(), SettingDesc::flags, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), and SF_PER_COMPANY.

◆ SetSettingValue() [2/2]

bool SetSettingValue ( const StringSettingDesc sd,
std::string  value,
bool  force_newgame 
)

Set a setting value with a string.

Parameters
sdthe setting to change.
valuethe value to write
force_newgameforce the newgame settings
Note
Strings WILL NOT be synced over the network

Definition at line 1819 of file settings.cpp.

References SaveLoad::conv, SettingDesc::flags, GetVarMemType(), SettingDesc::save, SF_NO_NETWORK_SYNC, and SLE_VAR_STRQ.