diff --git a/src/lang/english.txt b/src/lang/english.txt index 3a4de4156c..04181e382c 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1400,6 +1400,8 @@ STR_CONFIG_SETTING_TIMETABLE_IN_TICKS :Show timetable STR_CONFIG_SETTING_TIMETABLE_IN_TICKS_HELPTEXT :Show travel times in time tables in game ticks instead of days STR_CONFIG_SETTING_TIMETABLE_SEPARATION :Use timetable to ensure vehicle separation: {STRING2} STR_CONFIG_SETTING_TIMETABLE_SEPARATION_HELPTEXT :Select whether to ensure separation of vehicles when using automatic timetables +STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE :Vehicle separation factor: {STRING2} +STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE_HELPTEXT :How much of the vehicle separation timetable change to apply at each step STR_CONFIG_SETTING_TIMETABLE_SHOW_ARRIVAL_DEPARTURE :Show arrival and departure in timetables: {STRING2} STR_CONFIG_SETTING_TIMETABLE_SHOW_ARRIVAL_DEPARTURE_HELPTEXT :Display anticipated arrival and departure times in timetables STR_CONFIG_SETTING_QUICKGOTO :Quick creation of vehicle orders: {STRING2} diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 452f6b6fd2..1c3da570a7 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1628,6 +1628,7 @@ static SettingsContainer &GetSettingsTree() vehicles->Add(new SettingEntry("order.serviceathelipad")); vehicles->Add(new SettingEntry("order.timetable_automated")); vehicles->Add(new SettingEntry("order.timetable_separation")); + vehicles->Add(new SettingEntry("order.timetable_separation_rate")); } SettingsPage *limitations = main->Add(new SettingsPage(STR_CONFIG_SETTING_LIMITATIONS)); diff --git a/src/settings_type.h b/src/settings_type.h index b3eeae407f..7c3b34478d 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -440,6 +440,7 @@ struct OrderSettings { bool no_servicing_if_no_breakdowns; ///< don't send vehicles to depot when breakdowns are disabled bool timetable_automated; ///< whether to automatically manage timetables bool timetable_separation; ///< whether to perform automatic separation based on timetable + uint8 timetable_separation_rate; ///< percentage of timetable separation change to apply bool serviceathelipad; ///< service helicopters at helipads automatically (no need to send to depot) }; diff --git a/src/table/settings.ini b/src/table/settings.ini index fd3e10eadd..345c575a31 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -351,6 +351,20 @@ cat = SC_EXPERT extver = SlXvFeatureTest(XSLFTO_AND, XSLFI_AUTO_TIMETABLE) patxname = ""auto_timetables.order.timetable_separation"" +[SDT_VAR] +base = GameSettings +var = order.timetable_separation_rate +type = SLE_UINT8 +from = TIMESEP_SV +def = 100 +min = 0 +max = 100 +interval = 10 +str = STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE +strhelp = STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE_HELPTEXT +strval = STR_CONFIG_SETTING_PERCENTAGE +cat = SC_EXPERT + ; There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow ; these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. [SDT_OMANY] diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index c26b4e73b2..3fddfbe6ac 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -548,8 +548,11 @@ void UpdateSeparationOrder(Vehicle *v_start) } int separation_ahead = SeparationBetween(v, v->AheadSeparation()); int separation_behind = SeparationBetween(v->BehindSeparation(), v); - v->lateness_counter = (separation_ahead - separation_behind) / 2; - if (separation_ahead == -1 || separation_behind == -1) v->lateness_counter = 0; + if (separation_ahead != -1 && separation_behind != -1) { + int new_lateness = (separation_ahead - separation_behind) / 2; + v->lateness_counter = (new_lateness * _settings_game.order.timetable_separation_rate + + v->lateness_counter * (100 - _settings_game.order.timetable_separation_rate)) / 100; + } v = v->AheadSeparation(); } while (v != v_start); } @@ -668,15 +671,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) new_time = time_loading; } - /* Check for too large a difference from expected time, and if so don't average. */ - if (!(new_time > (int32)timetabled * 2 || new_time < (int32)timetabled / 2)) { - int arrival_error = timetabled - new_time; - /* Compute running average, with sign conversion to avoid negative overflow. */ - new_time = ((int32)timetabled * 4 + new_time + 2) / 5; - /* Use arrival_error to finetune order ticks. */ - if (arrival_error < 0) new_time++; - if (arrival_error > 0) new_time--; - } else if (new_time > (int32)timetabled * 10 && travelling) { + if (new_time > (int32)timetabled * 4 && travelling) { /* Possible jam, clear time and restart timetable for all vehicles. * Otherwise we risk trains blocking 1-lane stations for long times. */ ChangeTimetable(v, v->cur_real_order_index, 0, travelling ? MTF_TRAVEL_TIME : MTF_WAIT_TIME, true); @@ -686,6 +681,15 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) SetWindowDirty(WC_VEHICLE_TIMETABLE, v2->index); } return; + } else if (new_time >= (int32)timetabled / 2) { + /* Compute running average, with sign conversion to avoid negative overflow. */ + if (new_time < (int32)timetabled) { + new_time = ((int32)timetabled * 3 + new_time * 2 + 2) / 5; + } else { + new_time = ((int32)timetabled * 9 + new_time + 5) / 10; + } + } else { + /* new time is less than hald old time, set value directly */ } if (new_time < 1) new_time = 1;