diff --git a/src/economy.cpp b/src/economy.cpp index af6c4f49cb..30ee49e678 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1071,13 +1071,18 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16 transit_days, static const int TIME_FACTOR_FRAC_BITS = 4; static const int TIME_FACTOR_FRAC = 1 << TIME_FACTOR_FRAC_BITS; + if (_settings_game.economy.payment_algorithm == CPA_TRADITIONAL) transit_days = std::min(transit_days, 0xFFu); + const int days1 = cs->transit_days[0]; const int days2 = cs->transit_days[1]; const int days_over_days1 = std::max( transit_days - days1, 0); const int days_over_days2 = std::max(days_over_days1 - days2, 0); - int days_over_max = MIN_TIME_FACTOR - MAX_TIME_FACTOR; - if (days2 > -days_over_max) days_over_max += transit_days - days1; - else days_over_max += 2 * (transit_days - days1) - days2; + int days_over_max = 0; + if (_settings_game.economy.payment_algorithm == CPA_MODERN) { + days_over_max = MIN_TIME_FACTOR - MAX_TIME_FACTOR; + if (days2 > -days_over_max) days_over_max += transit_days - days1; + else days_over_max += 2 * (transit_days - days1) - days2; + } /* * The time factor is calculated based on the time it took diff --git a/src/economy_type.h b/src/economy_type.h index e7705fc028..7cbeb72d2f 100644 --- a/src/economy_type.h +++ b/src/economy_type.h @@ -234,4 +234,11 @@ static const uint LOCK_DEPOT_TILE_FACTOR = 2; struct CargoPayment; typedef uint32 CargoPaymentID; +enum CargoPaymentAlgorithm : byte { + CPA_BEGIN = 0, ///< Used for iterations and limit testing + CPA_TRADITIONAL = 0, ///< Traditional algorithm + CPA_MODERN, ///< Modern algorithm + CPA_END, ///< Used for iterations and limit testing +}; + #endif /* ECONOMY_TYPE_H */ diff --git a/src/lang/extra/english.txt b/src/lang/extra/english.txt index fc80d530e4..7c37edac1a 100644 --- a/src/lang/extra/english.txt +++ b/src/lang/extra/english.txt @@ -606,6 +606,11 @@ STR_CONFIG_SETTING_TOWN_GROWTH_CARGO_TRANSPORTED_HELPTEXT :Percentage of t STR_CONFIG_SETTING_RANDOM_ROAD_RECONSTRUCTION :Probability of random town road re-construction: {STRING2} STR_CONFIG_SETTING_RANDOM_ROAD_RECONSTRUCTION_HELPTEXT :The probability of town roads randomly being re-constructed (0 = off, 1000 = max) +STR_CONFIG_SETTING_CARGO_PAYMENT_ALGORITHM :Cargo payment algorithm: {STRING2} +STR_CONFIG_SETTING_CARGO_PAYMENT_ALGORITHM_HELPTEXT :The algorithm to use to calculate how much money to pay for delivering cargo to its destination. +STR_CONFIG_SETTING_CARGO_PAYMENT_ALGORITHM_TRADITIONAL :Traditional +STR_CONFIG_SETTING_CARGO_PAYMENT_ALGORITHM_MODERN :Modern + STR_CONFIG_SETTING_TOWN_MIN_DISTANCE :Minimum distance between towns: {STRING2} STR_CONFIG_SETTING_TOWN_MIN_DISTANCE_HELPTEXT :Set the minimum distance in tiles between towns for map generation and random founding diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index cf750cd6ab..1916c5198d 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -4187,6 +4187,10 @@ bool AfterLoadGame() } } + if (SlXvIsFeatureMissing(XSLFI_MORE_CARGO_AGE) && IsSavegameVersionBefore(SLV_MORE_CARGO_AGE)) { + _settings_game.economy.payment_algorithm = CPA_TRADITIONAL; + } + InitializeRoadGUI(); /* This needs to be done after conversion. */ diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 55724ff9c0..8287f3acc7 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2061,6 +2061,7 @@ static SettingsContainer &GetSettingsTree() accounting->Add(new SettingEntry("difficulty.vehicle_costs_in_depot")); accounting->Add(new SettingEntry("difficulty.vehicle_costs_when_stopped")); accounting->Add(new SettingEntry("difficulty.construction_cost")); + accounting->Add(new SettingEntry("economy.payment_algorithm")); } SettingsPage *vehicles = main->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES)); diff --git a/src/settings_type.h b/src/settings_type.h index 01b1fa0a76..fa020d33cd 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -705,6 +705,7 @@ struct EconomySettings { uint8 day_length_factor; ///< factor which the length of day is multiplied uint16 random_road_reconstruction; ///< chance out of 1000 per tile loop for towns to start random road re-construction bool disable_inflation_newgrf_flag; ///< Disable NewGRF inflation flag + CargoPaymentAlgorithm payment_algorithm; ///< Cargo payment algorithm }; struct LinkGraphSettings { diff --git a/src/table/settings/settings.ini b/src/table/settings/settings.ini index 5dcd0136fa..5770c065c5 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -3237,6 +3237,20 @@ def = false cat = SC_EXPERT patxname = ""economy.disable_inflation_newgrf_flag"" +[SDT_VAR] +var = economy.payment_algorithm +type = SLE_UINT8 +flags = SF_GUI_DROPDOWN +def = CPA_MODERN +min = CPA_BEGIN +max = CPA_END - 1 +interval = 1 +str = STR_CONFIG_SETTING_CARGO_PAYMENT_ALGORITHM +strhelp = STR_CONFIG_SETTING_CARGO_PAYMENT_ALGORITHM_HELPTEXT +strval = STR_CONFIG_SETTING_CARGO_PAYMENT_ALGORITHM_TRADITIONAL +cat = SC_BASIC +patxname = ""economy.payment_algorithm"" + ## [SDT_VAR] var = pf.wait_for_pbs_path