; This file is part of OpenTTD.
; OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
; OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
; See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
;

; World settings as stored in the main configuration file ("openttd.cfg")
; and in the savegame PATS chunk.
; World settings are everything related to how the world came to be, so
; basically construction and game_creation settings.

[pre-amble]
static bool CheckMaxHeightLevel(int32_t &new_value);
static bool CheckFreeformEdges(int32_t &new_value);
static void UpdateFreeformEdges(int32_t new_value);

static const SettingVariant _world_settings_table[] = {
[post-amble]
};
[templates]
SDT_BOOL   =   SDT_BOOL(GameSettings, $var,        $flags, $def,                              $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $from, $to,        $cat, $extra, $startup),
SDT_OMANY  =  SDT_OMANY(GameSettings, $var, $type, $flags, $def,             $max, $full,     $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $from, $to, $load, $cat, $extra, $startup),
SDT_VAR    =    SDT_VAR(GameSettings, $var, $type, $flags, $def,       $min, $max, $interval, $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $from, $to,        $cat, $extra, $startup),

[validation]
SDT_OMANY = static_assert($max <= MAX_$type, "Maximum value for GameSettings.$var exceeds storage size");
SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for GameSettings.$var exceeds storage size");

[defaults]
flags    = SF_NONE
interval = 0
str      = STR_NULL
strhelp  = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT
strval   = STR_NULL
pre_cb   = nullptr
post_cb  = nullptr
str_cb   = nullptr
help_cb  = nullptr
val_cb   = nullptr
load     = nullptr
from     = SL_MIN_VERSION
to       = SL_MAX_VERSION
cat      = SC_ADVANCED
extra    = 0
startup  = false


; There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow
; these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI.
[SDT_OMANY]
var      = game_creation.town_name
type     = SLE_UINT8
from     = SLV_97
flags    = SF_NO_NETWORK
def      = 0
max      = 255
full     = _town_names
cat      = SC_BASIC

[SDT_OMANY]
var      = game_creation.landscape
type     = SLE_UINT8
from     = SLV_97
flags    = SF_GUI_DROPDOWN | SF_NEWGAME_ONLY
def      = 0
max      = 3
full     = _climates
load     = ConvertLandscape
str      = STR_CONFIG_SETTING_LANDSCAPE
strhelp  = STR_CONFIG_SETTING_LANDSCAPE_HELPTEXT
strval   = STR_CLIMATE_TEMPERATE_LANDSCAPE
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.heightmap_height
type     = SLE_UINT8
from     = SLV_MAPGEN_SETTINGS_REVAMP
flags    = SF_NEWGAME_ONLY
def      = MAP_HEIGHT_LIMIT_AUTO_MINIMUM
min      = MIN_HEIGHTMAP_HEIGHT
max      = MAX_MAP_HEIGHT_LIMIT
interval = 1

[SDT_VAR]
var      = game_creation.snow_line_height
type     = SLE_UINT8
flags    = SF_SCENEDIT_ONLY
def      = DEF_SNOWLINE_HEIGHT
min      = MIN_SNOWLINE_HEIGHT
max      = MAX_SNOWLINE_HEIGHT
interval = 1
str      = STR_CONFIG_SETTING_SNOWLINE_HEIGHT
strhelp  = STR_CONFIG_SETTING_SNOWLINE_HEIGHT_HELPTEXT
strval   = STR_JUST_COMMA
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.snow_coverage
type     = SLE_UINT8
from     = SLV_MAPGEN_SETTINGS_REVAMP
flags    = SF_NEWGAME_ONLY
def      = DEF_SNOW_COVERAGE
min      = 0
max      = 100
interval = 10
str      = STR_CONFIG_SETTING_SNOW_COVERAGE
strhelp  = STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT
strval   = STR_CONFIG_SETTING_SNOW_COVERAGE_VALUE
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.desert_coverage
type     = SLE_UINT8
from     = SLV_MAPGEN_SETTINGS_REVAMP
flags    = SF_NEWGAME_ONLY
def      = DEF_DESERT_COVERAGE
min      = 0
max      = 100
interval = 10
str      = STR_CONFIG_SETTING_DESERT_COVERAGE
strhelp  = STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT
strval   = STR_CONFIG_SETTING_DESERT_COVERAGE_VALUE
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.starting_year
type     = SLE_INT32
def      = CalendarTime::DEF_START_YEAR
min      = CalendarTime::MIN_YEAR
max      = CalendarTime::MAX_YEAR
interval = 1
str      = STR_CONFIG_SETTING_STARTING_YEAR
strval   = STR_JUST_INT
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.ending_year
type     = SLE_INT32
from     = SLV_ENDING_YEAR
flags    = SF_GUI_0_IS_SPECIAL
def      = CalendarTime::DEF_END_YEAR
min      = CalendarTime::MIN_YEAR
max      = CalendarTime::MAX_YEAR - 1
interval = 1
str      = STR_CONFIG_SETTING_ENDING_YEAR
strhelp  = STR_CONFIG_SETTING_ENDING_YEAR_HELPTEXT
strval   = STR_CONFIG_SETTING_ENDING_YEAR_VALUE
cat      = SC_ADVANCED

[SDT_VAR]
var      = game_creation.land_generator
type     = SLE_UINT8
from     = SLV_30
flags    = SF_GUI_DROPDOWN | SF_NEWGAME_ONLY
def      = 1
min      = 0
max      = 1
str      = STR_CONFIG_SETTING_LAND_GENERATOR
strhelp  = STR_CONFIG_SETTING_LAND_GENERATOR_HELPTEXT
strval   = STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL

[SDT_VAR]
var      = game_creation.oil_refinery_limit
type     = SLE_UINT8
from     = SLV_30
def      = 32
min      = 12
max      = 128
str      = STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE
strval   = STR_CONFIG_SETTING_TILE_LENGTH
strhelp  = STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE_HELPTEXT

[SDT_VAR]
var      = game_creation.tgen_smoothness
type     = SLE_UINT8
from     = SLV_30
flags    = SF_GUI_DROPDOWN | SF_NEWGAME_ONLY
def      = 1
min      = TGEN_SMOOTHNESS_BEGIN
max      = TGEN_SMOOTHNESS_END - 1
str      = STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN
strhelp  = STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_HELPTEXT
strval   = STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.variety
type     = SLE_UINT8
from     = SLV_197
flags    = SF_GUI_DROPDOWN | SF_NEWGAME_ONLY
def      = 0
min      = 0
max      = 5
str      = STR_CONFIG_SETTING_VARIETY
strhelp  = STR_CONFIG_SETTING_VARIETY_HELPTEXT
strval   = STR_VARIETY_NONE

[SDT_VAR]
var      = game_creation.generation_seed
type     = SLE_UINT32
from     = SLV_30
flags    = SF_NOT_IN_CONFIG
def      = GENERATE_NEW_SEED
min      = 0
max      = UINT32_MAX
cat      = SC_EXPERT

[SDT_VAR]
var      = game_creation.tree_placer
type     = SLE_UINT8
from     = SLV_30
flags    = SF_GUI_DROPDOWN | SF_NEWGAME_ONLY | SF_SCENEDIT_TOO
def      = 2
min      = 0
max      = 2
str      = STR_CONFIG_SETTING_TREE_PLACER
strhelp  = STR_CONFIG_SETTING_TREE_PLACER_HELPTEXT
strval   = STR_CONFIG_SETTING_TREE_PLACER_NONE
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.heightmap_rotation
type     = SLE_UINT8
flags    = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
def      = 0
min      = 0
max      = 1
str      = STR_CONFIG_SETTING_HEIGHTMAP_ROTATION
strval   = STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.se_flat_world_height
type     = SLE_UINT8
flags    = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def      = 1
min      = 0
max      = 15
str      = STR_CONFIG_SETTING_SE_FLAT_WORLD_HEIGHT
strval   = STR_JUST_COMMA
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.map_x
type     = SLE_UINT8
flags    = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def      = 8
min      = MIN_MAP_SIZE_BITS
max      = MAX_MAP_SIZE_BITS
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.map_y
type     = SLE_UINT8
flags    = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC
def      = 8
min      = MIN_MAP_SIZE_BITS
max      = MAX_MAP_SIZE_BITS
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.water_borders
type     = SLE_UINT8
from     = SLV_111
def      = 15
min      = 0
max      = 16

[SDT_VAR]
var      = game_creation.custom_town_number
type     = SLE_UINT16
from     = SLV_115
def      = 1
min      = 1
max      = 5000
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.custom_industry_number
type     = SLE_UINT16
def      = 1
min      = 1
max      = 64000

[SDT_VAR]
var      = game_creation.custom_terrain_type
type     = SLE_UINT8
from     = SLV_MAPGEN_SETTINGS_REVAMP
flags    = SF_NEWGAME_ONLY
def      = MAP_HEIGHT_LIMIT_AUTO_MINIMUM
min      = MIN_CUSTOM_TERRAIN_TYPE
max      = MAX_MAP_HEIGHT_LIMIT
interval = 1

[SDT_VAR]
var      = game_creation.custom_sea_level
type     = SLE_UINT8
from     = SLV_149
def      = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
min      = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
max      = CUSTOM_SEA_LEVEL_MAX_PERCENTAGE
cat      = SC_BASIC

[SDT_VAR]
var      = game_creation.min_river_length
type     = SLE_UINT8
from     = SLV_163
def      = 16
min      = 2
max      = 255
cat      = SC_EXPERT

[SDT_VAR]
var      = game_creation.river_route_random
type     = SLE_UINT8
from     = SLV_163
def      = 5
min      = 1
max      = 255
cat      = SC_EXPERT

[SDT_VAR]
var      = game_creation.amount_of_rivers
type     = SLE_UINT8
from     = SLV_163
flags    = SF_GUI_DROPDOWN | SF_NEWGAME_ONLY
def      = 2
min      = 0
max      = 3
str      = STR_CONFIG_SETTING_RIVER_AMOUNT
strhelp  = STR_CONFIG_SETTING_RIVER_AMOUNT_HELPTEXT
strval   = STR_RIVERS_NONE

[SDT_VAR]
var      = construction.map_height_limit
type     = SLE_UINT8
from     = SLV_194
flags    = SF_NEWGAME_ONLY | SF_SCENEDIT_TOO | SF_GUI_0_IS_SPECIAL
def      = 0
min      = MIN_MAP_HEIGHT_LIMIT
max      = MAX_MAP_HEIGHT_LIMIT
interval = 1
str      = STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT
strhelp  = STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT_HELPTEXT
strval   = STR_CONFIG_SETTING_MAP_HEIGHT_LIMIT_VALUE
pre_cb   = CheckMaxHeightLevel
post_cb  = [](auto) { InvalidateWindowClassesData(WC_SMALLMAP, 2); }
cat      = SC_ADVANCED

[SDT_BOOL]
var      = construction.build_on_slopes
flags    = SF_NO_NETWORK
def      = true
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.command_pause_level
type     = SLE_UINT8
from     = SLV_154
flags    = SF_GUI_DROPDOWN | SF_NO_NETWORK
def      = 1
min      = 0
max      = 3
interval = 1
str      = STR_CONFIG_SETTING_COMMAND_PAUSE_LEVEL
strhelp  = STR_CONFIG_SETTING_COMMAND_PAUSE_LEVEL_HELPTEXT
strval   = STR_CONFIG_SETTING_COMMAND_PAUSE_LEVEL_NO_ACTIONS

[SDT_VAR]
var      = construction.terraform_per_64k_frames
type     = SLE_UINT32
from     = SLV_156
def      = 64 << 16
min      = 0
max      = 1 << 30
interval = 1
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.terraform_frame_burst
type     = SLE_UINT16
from     = SLV_156
def      = 4096
min      = 0
max      = 1 << 15
interval = 1
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.clear_per_64k_frames
type     = SLE_UINT32
from     = SLV_156
def      = 64 << 16
min      = 0
max      = 1 << 30
interval = 1
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.clear_frame_burst
type     = SLE_UINT16
from     = SLV_156
def      = 4096
min      = 0
max      = 1 << 15
interval = 1
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.tree_per_64k_frames
type     = SLE_UINT32
from     = SLV_175
def      = 64 << 16
min      = 0
max      = 1 << 30
interval = 1
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.tree_frame_burst
type     = SLE_UINT16
from     = SLV_175
def      = 4096
min      = 0
max      = 1 << 15
interval = 1
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.build_object_per_64k_frames
type     = SLE_UINT32
def      = 32 << 16
min      = 0
max      = 1 << 30
interval = 1
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.build_object_frame_burst
type     = SLE_UINT16
def      = 2048
min      = 0
max      = 1 << 15
interval = 1
cat      = SC_EXPERT

[SDT_BOOL]
var      = construction.autoslope
from     = SLV_75
def      = true
str      = STR_CONFIG_SETTING_AUTOSLOPE
strhelp  = STR_CONFIG_SETTING_AUTOSLOPE_HELPTEXT
cat      = SC_EXPERT

[SDT_BOOL]
var      = construction.extra_dynamite
def      = true
str      = STR_CONFIG_SETTING_EXTRADYNAMITE
strhelp  = STR_CONFIG_SETTING_EXTRADYNAMITE_HELPTEXT

[SDT_VAR]
var      = construction.max_bridge_length
type     = SLE_UINT16
from     = SLV_159
flags    = SF_NO_NETWORK
def      = 64
min      = 1
max      = MAX_MAP_SIZE
interval = 1
str      = STR_CONFIG_SETTING_MAX_BRIDGE_LENGTH
strhelp  = STR_CONFIG_SETTING_MAX_BRIDGE_LENGTH_HELPTEXT
strval   = STR_CONFIG_SETTING_TILE_LENGTH

[SDT_VAR]
var      = construction.max_bridge_height
type     = SLE_UINT8
from     = SLV_194
flags    = SF_NO_NETWORK
def      = 12
min      = 1
max      = MAX_TILE_HEIGHT
interval = 1
str      = STR_CONFIG_SETTING_MAX_BRIDGE_HEIGHT
strhelp  = STR_CONFIG_SETTING_MAX_BRIDGE_HEIGHT_HELPTEXT
strval   = STR_JUST_COMMA
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.max_tunnel_length
type     = SLE_UINT16
from     = SLV_159
flags    = SF_NO_NETWORK
def      = 64
min      = 1
max      = MAX_MAP_SIZE
interval = 1
str      = STR_CONFIG_SETTING_MAX_TUNNEL_LENGTH
strhelp  = STR_CONFIG_SETTING_MAX_TUNNEL_LENGTH_HELPTEXT
strval   = STR_CONFIG_SETTING_TILE_LENGTH

[SDT_VAR]
var      = construction.train_signal_side
type     = SLE_UINT8
flags    = SF_GUI_DROPDOWN | SF_NO_NETWORK
def      = 1
min      = 0
max      = 2
str      = STR_CONFIG_SETTING_SIGNALSIDE
strhelp  = STR_CONFIG_SETTING_SIGNALSIDE_HELPTEXT
strval   = STR_CONFIG_SETTING_SIGNALSIDE_LEFT
post_cb  = [](auto) { MarkWholeScreenDirty(); }
cat      = SC_BASIC

[SDT_BOOL]
var      = construction.road_stop_on_town_road
from     = SLV_47
def      = true
str      = STR_CONFIG_SETTING_STOP_ON_TOWN_ROAD
strhelp  = STR_CONFIG_SETTING_STOP_ON_TOWN_ROAD_HELPTEXT
cat      = SC_BASIC

[SDT_BOOL]
var      = construction.road_stop_on_competitor_road
from     = SLV_114
def      = true
str      = STR_CONFIG_SETTING_STOP_ON_COMPETITOR_ROAD
strhelp  = STR_CONFIG_SETTING_STOP_ON_COMPETITOR_ROAD_HELPTEXT
cat      = SC_BASIC

[SDT_BOOL]
var      = construction.crossing_with_competitor
def      = true
str      = STR_CONFIG_SETTING_CROSSING_WITH_COMPETITOR
strhelp  = STR_CONFIG_SETTING_CROSSING_WITH_COMPETITOR_HELPTEXT
cat      = SC_BASIC

[SDT_VAR]
var      = construction.raw_industry_construction
type     = SLE_UINT8
flags    = SF_GUI_DROPDOWN
def      = 0
min      = 0
max      = 2
str      = STR_CONFIG_SETTING_RAW_INDUSTRY_CONSTRUCTION_METHOD
strhelp  = STR_CONFIG_SETTING_RAW_INDUSTRY_CONSTRUCTION_METHOD_HELPTEXT
strval   = STR_CONFIG_SETTING_RAW_INDUSTRY_CONSTRUCTION_METHOD_NONE
post_cb  = [](auto) { InvalidateWindowData(WC_BUILD_INDUSTRY, 0); }
cat      = SC_BASIC

[SDT_VAR]
var      = construction.industry_platform
type     = SLE_UINT8
from     = SLV_148
def      = 1
min      = 0
max      = 4
str      = STR_CONFIG_SETTING_INDUSTRY_PLATFORM
strhelp  = STR_CONFIG_SETTING_INDUSTRY_PLATFORM_HELPTEXT
strval   = STR_CONFIG_SETTING_TILE_LENGTH
cat      = SC_EXPERT

[SDT_BOOL]
var      = construction.freeform_edges
from     = SLV_111
def      = true
pre_cb   = CheckFreeformEdges
post_cb  = UpdateFreeformEdges
cat      = SC_EXPERT

[SDT_VAR]
var      = construction.extra_tree_placement
type     = SLE_UINT8
from     = SLV_132
flags    = SF_GUI_DROPDOWN
def      = 2
min      = 0
max      = 3
str      = STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT
strhelp  = STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_HELPTEXT
strval   = STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_NO_SPREAD
cat      = SC_BASIC
