OpenTTD Source 20250205-master-gfd85ab1e2c
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

using SettingFlags = EnumBitSet< SettingFlag, uint16_t >
 
typedef std::variant< IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDescSettingVariant
 
typedef std::span< const SettingVariant > SettingTable
 

Enumerations

enum class  SettingFlag : uint8_t {
  GuiZeroIsSpecial , GuiDropdown , GuiCurrency , NetworkOnly ,
  NoNetwork , NewgameOnly , SceneditToo , SceneditOnly ,
  PerCompany , NotInSave , NotInConfig , NoNetworkSync ,
  Sandbox
}
 
enum  SettingCategory : uint8_t {
  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 : uint8_t { 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.
 
const SettingDescGetSettingFromName (const std::string_view name)
 Given a name of any setting, return any setting description of it.
 
void GetSaveLoadFromSettingTable (SettingTable settings, std::vector< SaveLoad > &saveloads)
 Get the SaveLoad for all settings in the settings table.
 
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.
 
bool SetSettingValue (const StringSettingDesc *sd, const std::string value, bool force_newgame=false)
 Set a setting value with a string.
 
std::vector< const SettingDesc * > GetFilteredSettingCollection (std::function< bool(const SettingDesc &desc)> func)
 Get a collection of settings matching a custom filter.
 

Detailed Description

Functions and types used internally for the settings configurations.

Definition in file settings_internal.h.

Typedef Documentation

◆ SettingFlags

using SettingFlags = EnumBitSet<SettingFlag, uint16_t>

Definition at line 31 of file settings_internal.h.

◆ SettingTable

typedef std::span<const SettingVariant> SettingTable

Definition at line 387 of file settings_internal.h.

◆ SettingVariant

Enumeration Type Documentation

◆ SettingCategory

enum SettingCategory : uint8_t

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 class SettingFlag : uint8_t
strong
Enumerator
GuiZeroIsSpecial 

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

GuiDropdown 

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

GuiCurrency 

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

NetworkOnly 

This setting only applies to network games.

NoNetwork 

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

NewgameOnly 

This setting cannot be changed in a game.

SceneditToo 

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

SceneditOnly 

This setting can only be changed in the scenario editor.

PerCompany 

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

NotInSave 

Do not save with savegame, basically client-based.

NotInConfig 

Do not save to config file.

NoNetworkSync 

Do not synchronize over network (but it is saved if SettingFlag::NotInSave is not set).

Sandbox 

This setting is a sandbox setting.

Definition at line 16 of file settings_internal.h.

◆ SettingType

enum SettingType : uint8_t

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

◆ GetFilteredSettingCollection()

std::vector< const SettingDesc * > GetFilteredSettingCollection ( std::function< bool(const SettingDesc &desc)>  func)

Get a collection of settings matching a custom filter.

Parameters
funcFunction to filter each setting.
Returns
Vector containing the list of collections.

Definition at line 1702 of file settings.cpp.

References GenericSettingTables(), and GetSettingDesc().

◆ 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 1651 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 382 of file settings_internal.h.

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

◆ 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 1679 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 
)

◆ 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 1851 of file settings.cpp.

References _settings_game, _settings_newgame, SettingDesc::AsStringSetting(), StringSettingDesc::ChangeValue(), SaveLoad::conv, SettingDesc::flags, GetVarMemType(), NoNetworkSync, SettingDesc::save, SLE_VAR_STRQ, and EnumBitSet< Tenum, Tstorage >::Test().