diff --git a/src/lang/english.txt b/src/lang/english.txt index 85011e4e64..e82aa7960b 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1521,6 +1521,7 @@ STR_CONFIG_SETTING_TOWN_FOUNDING_HELPTEXT :Enabling this s STR_CONFIG_SETTING_TOWN_FOUNDING_FORBIDDEN :Forbidden STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED :Allowed STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED_CUSTOM_LAYOUT :Allowed, custom town layout +STR_CONFIG_SETTING_TOWN_CARGO_FACTOR :{LTBLUE}Town cargo generation factor (less < 0 < more): {ORANGE}{STRING2} STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT :In game placement of trees: {STRING2} STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_HELPTEXT :Control random appearance of trees during the game. This might affect industries which rely on tree growth, for example lumber mills diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index efd9580952..a55a390fde 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1556,6 +1556,7 @@ static SettingEntry _settings_economy_towns[] = { SettingEntry("economy.town_growth_rate"), SettingEntry("economy.larger_towns"), SettingEntry("economy.initial_city_size"), + SettingEntry("economy.town_cargo_factor"), }; /** Towns sub-page */ static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)}; diff --git a/src/settings_type.h b/src/settings_type.h index 7731e40c9c..36ddddb800 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -485,6 +485,7 @@ struct EconomySettings { bool station_noise_level; ///< build new airports when the town noise level is still within accepted limits uint16 town_noise_population[3]; ///< population to base decision on noise evaluation (@see town_council_tolerance) bool allow_town_level_crossings; ///< towns are allowed to build level crossings + int8 town_cargo_factor; ///< power-of-two multiplier for town (passenger, mail) generation. May be negative. bool infrastructure_maintenance; ///< enable monthly maintenance fee for owner infrastructure }; diff --git a/src/table/settings.ini b/src/table/settings.ini index 0b723a0ae0..4a1339b3db 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -712,6 +712,18 @@ str = STR_CONFIG_SETTING_SHORT_PATH_SATURATION strval = STR_CONFIG_SETTING_PERCENTAGE strhelp = STR_CONFIG_SETTING_SHORT_PATH_SATURATION_HELPTEXT +[SDT_VAR] +base = GameSettings +var = economy.town_cargo_factor +type = SLE_INT8 +from = 160 +def = 0 +min = -16 +max = +8 +interval = 1 +str = STR_CONFIG_SETTING_TOWN_CARGO_FACTOR +strval = STR_JUST_INT + ; Vehicles [SDT_VAR] diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 7297692129..26f9abdb85 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -436,6 +436,61 @@ static void MakeTownHouseBigger(TileIndex tile) if (flags & BUILDING_HAS_4_TILES) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1)); } +/** + * Generate cargo for a town (house). + * + * The amount of cargo should be and will be greater than zero. + * + * @param t current town + * @param ct type of cargo to generate, usually CT_PASSENGERS or CT_MAIL + * @param amount how many units of cargo + * @param stations available stations for this house + */ +static void TownGenerateCargo (Town *t, CargoID ct, uint amount, StationFinder &stations) +{ + // custom cargo generation factor + int cf = _settings_game.economy.town_cargo_factor; + + // when the economy flunctuates, everyone wants to stay at home + if (EconomyIsInRecession()) { + amount = (amount + 1) >> 1; + } + + // apply custom factor? + if (cf < 0) { + // approx (amount / 2^cf) + // adjust with a constant offset of {(2 ^ cf) - 1} (i.e. add cf * 1-bits) before dividing to ensure that it doesn't become zero + // this skews the curve a little so that isn't entirely exponential, but will still decrease + amount = (amount + ((1 << -cf) - 1)) >> -cf; + } + + else if (cf > 0) { + // approx (amount * 2^cf) + // XXX: overflow? + amount = amount << cf; + } + + // with the adjustments above, this should never happen + assert(amount > 0); + + // calculate for town stats + const CargoSpec *cs = CargoSpec::Get(ct); + switch (cs->town_effect) { + case TE_PASSENGERS: + t->supplied[CT_PASSENGERS].new_max += amount; + t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amount, ST_TOWN, t->index, stations.GetStations()); + break; + + case TE_MAIL: + t->supplied[CT_MAIL].new_max += amount; + t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amount, ST_TOWN, t->index, stations.GetStations()); + break; + + default: + break; + } +} + /** * Tile callback function. * @@ -483,27 +538,20 @@ static void TileLoop_Town(TileIndex tile) uint amt = GB(callback, 0, 8); if (amt == 0) continue; - uint moved = MoveGoodsToStation(cargo, amt, ST_TOWN, t->index, stations.GetStations()); - - const CargoSpec *cs = CargoSpec::Get(cargo); - t->supplied[cs->Index()].new_max += amt; - t->supplied[cs->Index()].new_act += moved; + // XXX: no economy flunctuation for GRF cargos? + TownGenerateCargo(t, cargo, amt, stations); } } else { if (GB(r, 0, 8) < hs->population) { uint amt = GB(r, 0, 8) / 8 + 1; - if (EconomyIsInRecession()) amt = (amt + 1) >> 1; - t->supplied[CT_PASSENGERS].new_max += amt; - t->supplied[CT_PASSENGERS].new_act += MoveGoodsToStation(CT_PASSENGERS, amt, ST_TOWN, t->index, stations.GetStations()); + TownGenerateCargo(t, CT_PASSENGERS, amt, stations); } if (GB(r, 8, 8) < hs->mail_generation) { uint amt = GB(r, 8, 8) / 8 + 1; - if (EconomyIsInRecession()) amt = (amt + 1) >> 1; - t->supplied[CT_MAIL].new_max += amt; - t->supplied[CT_MAIL].new_act += MoveGoodsToStation(CT_MAIL, amt, ST_TOWN, t->index, stations.GetStations()); + TownGenerateCargo(t, CT_MAIL, amt, stations); } }