diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 9690481154..64c86f568f 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2975,6 +2975,14 @@ bool AfterLoadGame() FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false); } + // setting moved from game settings to company settings + if (SlXvIsFeaturePresent(XSLFI_ORDER_OCCUPANCY, 1, 1)) { + Company *c; + FOR_ALL_COMPANIES(c) { + c->settings.order_occupancy_smoothness = _settings_game.order.old_occupancy_smoothness; + } + } + /* Road stops is 'only' updating some caches */ AfterLoadRoadStops(); AfterLoadLabelMaps(); diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index d7d980aa8d..85eedddd78 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -45,7 +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_ORDER_OCCUPANCY, XSCF_NULL, 1, 1, "order_occupancy", NULL, NULL, NULL }, + { XSLFI_ORDER_OCCUPANCY, XSCF_NULL, 2, 2, "order_occupancy", NULL, NULL, NULL }, { XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker }; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index b7f6263977..8a613b0f2f 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1586,6 +1586,7 @@ static SettingsContainer &GetSettingsTree() company->Add(new SettingEntry("vehicle.servint_roadveh")); company->Add(new SettingEntry("vehicle.servint_ships")); company->Add(new SettingEntry("vehicle.servint_aircraft")); + company->Add(new SettingEntry("order_occupancy_smoothness")); } SettingsPage *accounting = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCOUNTING)); @@ -1626,7 +1627,6 @@ static SettingsContainer &GetSettingsTree() vehicles->Add(new SettingEntry("order.no_servicing_if_no_breakdowns")); vehicles->Add(new SettingEntry("order.serviceathelipad")); - vehicles->Add(new SettingEntry("order.occupancy_smoothness")); } SettingsPage *limitations = main->Add(new SettingsPage(STR_CONFIG_SETTING_LIMITATIONS)); diff --git a/src/settings_type.h b/src/settings_type.h index 1b2c3c05d8..e1c93efd56 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -439,7 +439,8 @@ struct OrderSettings { bool selectgoods; ///< only send the goods to station if a train has been there bool no_servicing_if_no_breakdowns; ///< don't send vehicles to depot when breakdowns are disabled bool serviceathelipad; ///< service helicopters at helipads automatically (no need to send to depot) - uint8 occupancy_smoothness; ///< percentage smoothness of occupancy measurement changes + + uint8 old_occupancy_smoothness; ///< moved to company settings: percentage smoothness of occupancy measurement changes }; /** Settings related to vehicles. */ @@ -536,6 +537,7 @@ struct CompanySettings { uint32 engine_renew_money; ///< minimum amount of money before autorenew is used bool renew_keep_length; ///< sell some wagons if after autoreplace the train is longer than before VehicleDefaultSettings vehicle; ///< default settings for vehicles + uint8 order_occupancy_smoothness; ///< percentage smoothness of occupancy measurement changes }; /** All settings together for the game. */ diff --git a/src/table/company_settings.ini b/src/table/company_settings.ini index 8296890a74..24bf501077 100644 --- a/src/table/company_settings.ini +++ b/src/table/company_settings.ini @@ -135,6 +135,22 @@ strhelp = STR_CONFIG_SETTING_SERVINT_AIRCRAFT_HELPTEXT strval = STR_CONFIG_SETTING_SERVINT_VALUE proc = UpdateIntervalAircraft + +[SDT_VAR] +base = CompanySettings +var = order_occupancy_smoothness +type = SLE_UINT8 +guiflags = SGF_PER_COMPANY +def = 75 +min = 0 +max = 100 +interval = 10 +str = STR_CONFIG_OCCUPANCY_SMOOTHNESS +strhelp = STR_CONFIG_OCCUPANCY_SMOOTHNESS_HELPTEXT +strval = STR_CONFIG_SETTING_PERCENTAGE +cat = SC_EXPERT +patxname = ""order_occupancy_smoothness"" + [SDT_END] diff --git a/src/table/settings.ini b/src/table/settings.ini index 3e56066eb1..408e537a6b 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -2149,7 +2149,7 @@ cat = SC_EXPERT [SDT_VAR] base = GameSettings -var = order.occupancy_smoothness +var = order.old_occupancy_smoothness type = SLE_UINT8 def = 75 min = 0 @@ -2159,7 +2159,7 @@ str = STR_CONFIG_OCCUPANCY_SMOOTHNESS strhelp = STR_CONFIG_OCCUPANCY_SMOOTHNESS_HELPTEXT strval = STR_CONFIG_SETTING_PERCENTAGE cat = SC_EXPERT -extver = SlXvFeatureTest(XSLFTO_AND, XSLFI_ORDER_OCCUPANCY) +extver = SlXvFeatureTest(XSLFTO_AND, XSLFI_ORDER_OCCUPANCY, 1, 1) patxname = ""order_occupancy.order.occupancy_smoothness"" ## diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 5f079afb88..7400ec8089 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2123,9 +2123,11 @@ void Vehicle::LeaveStation() if (old_occupancy == 0) { new_occupancy = current_occupancy; } else { + Company *owner = Company::GetIfValid(this->owner); + uint8 occupancy_smoothness = owner ? owner->settings.order_occupancy_smoothness : 0; // Exponential weighted moving average using occupancy_smoothness - new_occupancy = (old_occupancy - 1) * _settings_game.order.occupancy_smoothness; - new_occupancy += current_occupancy * (100 - _settings_game.order.occupancy_smoothness); + new_occupancy = (old_occupancy - 1) * occupancy_smoothness; + new_occupancy += current_occupancy * (100 - occupancy_smoothness); new_occupancy += 50; // round to nearest integer percent, rather than just floor new_occupancy /= 100; }