diff --git a/src/lang/english.txt b/src/lang/english.txt index 3b19e46629..95cb477ba4 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1578,6 +1578,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 :Town cargo generation factor (less < 0 < more): {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/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index 38745a3ffb..1a5575fb6b 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -51,6 +51,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_ADJACENT_CROSSINGS, XSCF_NULL, 1, 1, "adjacent_crossings", NULL, NULL, NULL }, { XSLFI_DEPARTURE_BOARDS, XSCF_IGNORABLE_UNKNOWN, 1, 1, "departure_boards", NULL, NULL, NULL }, { XSLFI_TIMETABLES_START_TICKS, XSCF_NULL, WALLCLOCK_NETWORK_COMPATIBLE ? 0 : 1, 1, "timetable_start_ticks", NULL, NULL, NULL }, + { XSLFI_TOWN_CARGO_ADJ, XSCF_IGNORABLE_UNKNOWN, 1, 1, "town_cargo_adj", NULL, NULL, NULL }, { XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker }; diff --git a/src/saveload/extended_ver_sl.h b/src/saveload/extended_ver_sl.h index d932e32f41..a4cfb0b3e3 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -26,6 +26,7 @@ enum SlXvFeatureIndex { XSLFI_ADJACENT_CROSSINGS, ///< Adjacent level crossings closure patch XSLFI_DEPARTURE_BOARDS, ///< Departure boards patch, in ticks mode XSLFI_TIMETABLES_START_TICKS, ///< Timetable start time is in ticks, instead of days (from departure boards patch) + XSLFI_TOWN_CARGO_ADJ, ///< Town cargo adjustment patch XSLFI_SIZE, ///< Total count of features, including null feature }; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 71413f886a..481bbf5444 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1726,6 +1726,7 @@ static SettingsContainer &GetSettingsTree() towns->Add(new SettingEntry("economy.allow_town_roads")); towns->Add(new SettingEntry("economy.allow_town_level_crossings")); towns->Add(new SettingEntry("economy.found_town")); + towns->Add(new SettingEntry("economy.town_cargo_factor")); } SettingsPage *industries = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_INDUSTRIES)); diff --git a/src/settings_type.h b/src/settings_type.h index 95226819d4..1a2c8b899e 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -510,6 +510,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 e2f51d301c..2e35e2e244 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -755,6 +755,19 @@ 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 +patxname = ""town_cargo_adj.economy.town_cargo_factor"" + ; Vehicles [SDT_VAR] diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index ea44603b0c..64384c6241 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -457,6 +457,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. * @@ -504,27 +559,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); } }