; 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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
;

; Economy settings as stored in the main configuration file ("openttd.cfg")
; and in the savegame PATS chunk.

[pre-amble]
static void TownFoundingChanged(int32_t new_value);
static void ChangeTimekeepingUnits(int32_t new_value);
static void ChangeMinutesPerYear(int32_t new_value);
static std::tuple<int32_t, uint32_t> GetMinutesPerYearRange(const IntSettingDesc &sd);

static constexpr std::initializer_list<std::string_view> _place_houses{"forbidden"sv, "allowed"sv, "fully constructed"sv};

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

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

[defaults]
flags    =
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
def_cb   = nullptr
range_cb = nullptr
load     = nullptr
from     = SL_MIN_VERSION
to       = SL_MAX_VERSION
cat      = SC_ADVANCED
extra    = 0
startup  = false


[SDT_VAR]
var      = economy.town_layout
type     = SLE_UINT8
from     = SLV_59
flags    = SettingFlag::GuiDropdown
def      = TL_ORIGINAL
min      = TL_BEGIN
max      = NUM_TLS - 1
interval = 1
str      = STR_CONFIG_SETTING_TOWN_LAYOUT
strhelp  = STR_CONFIG_SETTING_TOWN_LAYOUT_HELPTEXT
strval   = STR_CONFIG_SETTING_TOWN_LAYOUT_DEFAULT
post_cb  = TownFoundingChanged

[SDT_BOOL]
var      = economy.allow_town_roads
from     = SLV_113
flags    = SettingFlag::NoNetwork
def      = true
str      = STR_CONFIG_SETTING_ALLOW_TOWN_ROADS
strhelp  = STR_CONFIG_SETTING_ALLOW_TOWN_ROADS_HELPTEXT

[SDT_VAR]
var      = economy.found_town
type     = SLE_UINT8
from     = SLV_128
flags    = SettingFlag::GuiDropdown
def      = TF_FORBIDDEN
min      = TF_BEGIN
max      = TF_END - 1
interval = 1
str      = STR_CONFIG_SETTING_TOWN_FOUNDING
strhelp  = STR_CONFIG_SETTING_TOWN_FOUNDING_HELPTEXT
strval   = STR_CONFIG_SETTING_TOWN_FOUNDING_FORBIDDEN
post_cb  = TownFoundingChanged
cat      = SC_BASIC

[SDT_VAR]
var      = economy.place_houses
type     = SLE_UINT8
flags    = SettingFlag::GuiDropdown
def      = PH_FORBIDDEN
min      = PH_FORBIDDEN
max      = PH_ALLOWED_CONSTRUCTED
full     = _place_houses
str      = STR_CONFIG_SETTING_HOUSE_PLACER
strhelp  = STR_CONFIG_SETTING_HOUSE_PLACER_HELPTEXT
strval   = STR_CONFIG_SETTING_HOUSE_PLACER_FORBIDDEN
cat      = SC_ADVANCED

[SDT_BOOL]
var      = economy.allow_town_level_crossings
from     = SLV_143
flags    = SettingFlag::NoNetwork
def      = true
str      = STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS
strhelp  = STR_CONFIG_SETTING_ALLOW_TOWN_LEVEL_CROSSINGS_HELPTEXT

[SDT_VAR]
var      = economy.town_cargogen_mode
type     = SLE_UINT8
from     = SLV_TOWN_CARGOGEN
flags    = SettingFlag::GuiDropdown
def      = TCGM_BITCOUNT
min      = TCGM_BEGIN
max      = TCGM_END - 1
interval = 1
str      = STR_CONFIG_SETTING_TOWN_CARGOGENMODE
strhelp  = STR_CONFIG_SETTING_TOWN_CARGOGENMODE_HELPTEXT
strval   = STR_CONFIG_SETTING_TOWN_CARGOGENMODE_ORIGINAL
cat      = SC_ADVANCED

[SDT_BOOL]
var      = economy.station_noise_level
from     = SLV_96
flags    = SettingFlag::NoNetwork
def      = false
str      = STR_CONFIG_SETTING_NOISE_LEVEL
strhelp  = STR_CONFIG_SETTING_NOISE_LEVEL_HELPTEXT
post_cb  = [](auto new_value) { InvalidateWindowClassesData(WC_TOWN_VIEW, new_value); }

[SDT_BOOL]
var      = economy.inflation
flags    = SettingFlag::NoNetwork
def      = false
str      = STR_CONFIG_SETTING_INFLATION
strhelp  = STR_CONFIG_SETTING_INFLATION_HELPTEXT
cat      = SC_BASIC

[SDT_BOOL]
var      = economy.multiple_industry_per_town
def      = false
str      = STR_CONFIG_SETTING_MULTIPINDTOWN
strhelp  = STR_CONFIG_SETTING_MULTIPINDTOWN_HELPTEXT

[SDT_BOOL]
var      = economy.bribe
def      = true
str      = STR_CONFIG_SETTING_BRIBE
strhelp  = STR_CONFIG_SETTING_BRIBE_HELPTEXT
help_cb  = SettingHelpWallclock
post_cb  = [](auto) { InvalidateWindowClassesData(WC_TOWN_AUTHORITY); }
cat      = SC_BASIC

[SDT_BOOL]
var      = economy.exclusive_rights
from     = SLV_79
def      = true
str      = STR_CONFIG_SETTING_ALLOW_EXCLUSIVE
strhelp  = STR_CONFIG_SETTING_ALLOW_EXCLUSIVE_HELPTEXT
help_cb  = SettingHelpWallclock
post_cb  = [](auto) { InvalidateWindowClassesData(WC_TOWN_AUTHORITY); }
cat      = SC_BASIC

[SDT_BOOL]
var      = economy.fund_buildings
from     = SLV_165
def      = true
str      = STR_CONFIG_SETTING_ALLOW_FUND_BUILDINGS
strhelp  = STR_CONFIG_SETTING_ALLOW_FUND_BUILDINGS_HELPTEXT
post_cb  = [](auto) { InvalidateWindowClassesData(WC_TOWN_AUTHORITY); }
cat      = SC_BASIC

[SDT_BOOL]
var      = economy.fund_roads
from     = SLV_160
def      = true
str      = STR_CONFIG_SETTING_ALLOW_FUND_ROAD
strhelp  = STR_CONFIG_SETTING_ALLOW_FUND_ROAD_HELPTEXT
post_cb  = [](auto) { InvalidateWindowClassesData(WC_TOWN_AUTHORITY); }
cat      = SC_BASIC

[SDT_BOOL]
var      = economy.give_money
from     = SLV_79
def      = true
str      = STR_CONFIG_SETTING_ALLOW_GIVE_MONEY
strhelp  = STR_CONFIG_SETTING_ALLOW_GIVE_MONEY_HELPTEXT
cat      = SC_BASIC

[SDT_VAR]
var      = economy.type
type     = SLE_UINT8
flags    = SettingFlag::GuiDropdown
def      = ET_SMOOTH
min      = ET_BEGIN
max      = ET_END - 1
str      = STR_CONFIG_SETTING_ECONOMY_TYPE
strhelp  = STR_CONFIG_SETTING_ECONOMY_TYPE_HELPTEXT
help_cb  = SettingHelpWallclock
strval   = STR_CONFIG_SETTING_ECONOMY_TYPE_ORIGINAL
post_cb  = [](auto) { InvalidateWindowClassesData(WC_INDUSTRY_VIEW); }
cat      = SC_BASIC

[SDT_VAR]
var      = economy.feeder_payment_share
type     = SLE_UINT8
from     = SLV_134
def      = 75
min      = 0
max      = 100
str      = STR_CONFIG_SETTING_FEEDER_PAYMENT_SHARE
strhelp  = STR_CONFIG_SETTING_FEEDER_PAYMENT_SHARE_HELPTEXT
strval   = STR_CONFIG_SETTING_PERCENTAGE
cat      = SC_EXPERT

[SDT_VAR]
var      = economy.town_growth_rate
type     = SLE_UINT8
from     = SLV_54
flags    = SettingFlag::GuiDropdown
def      = 2
min      = 0
max      = 4
str      = STR_CONFIG_SETTING_TOWN_GROWTH
strhelp  = STR_CONFIG_SETTING_TOWN_GROWTH_HELPTEXT
strval   = STR_CONFIG_SETTING_TOWN_GROWTH_NONE

[SDT_VAR]
var      = economy.larger_towns
type     = SLE_UINT8
from     = SLV_54
flags    = SettingFlag::GuiZeroIsSpecial
def      = 4
min      = 0
max      = 255
interval = 1
str      = STR_CONFIG_SETTING_LARGER_TOWNS
strhelp  = STR_CONFIG_SETTING_LARGER_TOWNS_HELPTEXT
strval   = STR_CONFIG_SETTING_LARGER_TOWNS_VALUE

[SDT_VAR]
var      = economy.initial_city_size
type     = SLE_UINT8
from     = SLV_56
def      = 2
min      = 1
max      = 10
interval = 1
str      = STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER
strhelp  = STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER_HELPTEXT
strval   = STR_JUST_COMMA

[SDT_BOOL]
var      = economy.mod_road_rebuild
from     = SLV_77
def      = true
cat      = SC_EXPERT

[SDT_VAR]
var      = economy.dist_local_authority
type     = SLE_UINT8
def      = 20
min      = 5
max      = 60
cat      = SC_EXPERT

[SDT_VAR]
var      = economy.town_noise_population[0]
type     = SLE_UINT16
from     = SLV_96
def      = 800
min      = 200
max      = 65535
cat      = SC_EXPERT

[SDT_VAR]
var      = economy.town_noise_population[1]
type     = SLE_UINT16
from     = SLV_96
def      = 2000
min      = 400
max      = 65535
cat      = SC_EXPERT

[SDT_VAR]
var      = economy.town_noise_population[2]
type     = SLE_UINT16
from     = SLV_96
def      = 4000
min      = 800
max      = 65535
cat      = SC_EXPERT

[SDT_VAR]
var      = economy.town_noise_population[3]
type     = SLE_UINT16
def      = 400
min      = 100
max      = 65535
cat      = SC_EXPERT

[SDT_BOOL]
var      = economy.infrastructure_maintenance
from     = SLV_166
def      = false
str      = STR_CONFIG_SETTING_INFRASTRUCTURE_MAINTENANCE
strhelp  = STR_CONFIG_SETTING_INFRASTRUCTURE_MAINTENANCE_HELPTEXT
post_cb  = [](auto) { InvalidateWindowClassesData(WC_COMPANY_INFRASTRUCTURE); }
cat      = SC_BASIC

[SDT_VAR]
var      = economy.timekeeping_units
type     = SLE_UINT8
flags    = SettingFlag::GuiDropdown, SettingFlag::NewgameOnly, SettingFlag::SceneditToo
def      = TKU_CALENDAR
min      = TKU_CALENDAR
max      = TKU_WALLCLOCK
str      = STR_CONFIG_SETTING_TIMEKEEPING_UNITS
strval   = STR_CONFIG_SETTING_TIMEKEEPING_UNITS_CALENDAR
strhelp  = STR_CONFIG_SETTING_TIMEKEEPING_UNITS_HELPTEXT
post_cb  = ChangeTimekeepingUnits
cat      = SC_BASIC

[SDT_VAR]
var      = economy.minutes_per_calendar_year
type     = SLE_UINT16
flags    = SettingFlag::GuiZeroIsSpecial, SettingFlag::NoNetwork
def      = CalendarTime::DEF_MINUTES_PER_YEAR
min      = CalendarTime::FROZEN_MINUTES_PER_YEAR
max      = CalendarTime::MAX_MINUTES_PER_YEAR
interval = 1
str      = STR_CONFIG_SETTING_MINUTES_PER_YEAR
strhelp  = STR_CONFIG_SETTING_MINUTES_PER_YEAR_HELPTEXT
strval   = STR_CONFIG_SETTING_MINUTES_PER_YEAR_VALUE
pre_cb   = [](auto) { return _game_mode == GM_MENU || _settings_game.economy.timekeeping_units == 1; }
post_cb  = ChangeMinutesPerYear
range_cb = GetMinutesPerYearRange
cat      = SC_BASIC

[SDT_VAR]
var      = economy.town_cargo_scale
type     = SLE_UINT16
flags    = SettingFlag::NoNetwork
def      = DEF_CARGO_SCALE
min      = MIN_CARGO_SCALE
max      = MAX_CARGO_SCALE
interval = 1
str      = STR_CONFIG_SETTING_TOWN_CARGO_SCALE
strhelp  = STR_CONFIG_SETTING_TOWN_CARGO_SCALE_HELPTEXT
strval   = STR_CONFIG_SETTING_CARGO_SCALE_VALUE
cat      = SC_BASIC

[SDT_VAR]
var      = economy.industry_cargo_scale
type     = SLE_UINT16
flags    = SettingFlag::NoNetwork
def      = DEF_CARGO_SCALE
min      = MIN_CARGO_SCALE
max      = MAX_CARGO_SCALE
interval = 1
str      = STR_CONFIG_SETTING_INDUSTRY_CARGO_SCALE
strhelp  = STR_CONFIG_SETTING_INDUSTRY_CARGO_SCALE_HELPTEXT
strval   = STR_CONFIG_SETTING_CARGO_SCALE_VALUE
cat      = SC_BASIC
