From 1c9801e6b63b16ceccbc36ec391a2cbad8725a47 Mon Sep 17 00:00:00 2001 From: patch-import Date: Sat, 1 Aug 2015 23:56:50 +0100 Subject: [PATCH 1/2] Import town cargo generation factor patch Adjust whitespace http://www.tt-forums.net/viewtopic.php?f=33&t=46399&start=200#p1086221 --- src/lang/english.txt | 1 + src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/settings.ini | 12 ++++++++ src/town_cmd.cpp | 70 +++++++++++++++++++++++++++++++++++------- 5 files changed, 74 insertions(+), 11 deletions(-) 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); } } From 08dc95fea109b671ca5f2b96e3ca226c5cdd5b87 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 2 Aug 2015 00:59:40 +0100 Subject: [PATCH 2/2] Add town cargo patch SLXI/PATX code. Update setting string. --- src/lang/english.txt | 2 +- src/saveload/extended_ver_sl.cpp | 1 + src/saveload/extended_ver_sl.h | 1 + src/table/settings.ini | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index e21b832ad8..cf1dc292c1 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1561,7 +1561,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_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 7127faf7b6..54347a56e8 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -45,6 +45,7 @@ std::vector _sl_xv_discardable_chunk_ids; ///< list of chunks static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { + { 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 a7e9496944..7b26f2f377 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -21,6 +21,7 @@ */ enum SlXvFeatureIndex { XSLFI_NULL = 0, ///< Unused value, to indicate that no extended feature test is in use + XSLFI_TOWN_CARGO_ADJ, ///< Town cargo adjustment patch XSLFI_SIZE, ///< Total count of features, including null feature }; diff --git a/src/table/settings.ini b/src/table/settings.ini index 82f174f8f0..4986878959 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -766,6 +766,7 @@ max = +8 interval = 1 str = STR_CONFIG_SETTING_TOWN_CARGO_FACTOR strval = STR_JUST_INT +patxname = ""town_cargo_adj.economy.town_cargo_factor"" ; Vehicles