From ff5ee52b945064911b1e6d1368c30c3d110ce379 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 6 May 2016 23:16:17 +0100 Subject: [PATCH] Add a company setting to control auto-fill timetable rounding. --- src/lang/english.txt | 2 ++ src/settings_gui.cpp | 1 + src/settings_type.h | 1 + src/table/company_settings.ini | 15 +++++++++++++++ src/timetable_cmd.cpp | 10 ++++++---- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 270bbca68a..8393dcc773 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -1404,6 +1404,8 @@ STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE :Auto timetable STR_CONFIG_SETTING_TIMETABLE_SEPARATION_RATE_HELPTEXT :How much of the vehicle separation auto 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_TIMETABLE_AUTOFILL_ROUNDING_TICKS :Round up auto-filled timetable times to multiples of this many ticks: {STRING2} +STR_CONFIG_SETTING_TIMETABLE_AUTOFILL_ROUNDING_TICKS_HELPTEXT :Timetable times adjusted by timetable automation are not rounded. A day at a a day length of 1 is 74 ticks. STR_CONFIG_SETTING_QUICKGOTO :Quick creation of vehicle orders: {STRING2} STR_CONFIG_SETTING_QUICKGOTO_HELPTEXT :Pre-select the 'goto cursor' when opening the orders window STR_CONFIG_SETTING_DEFAULT_RAIL_TYPE :Default rail type (after new game/game load): {STRING2} diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 44fbda382b..cedf4fc66e 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1588,6 +1588,7 @@ static SettingsContainer &GetSettingsTree() company->Add(new SettingEntry("vehicle.servint_aircraft")); company->Add(new SettingEntry("vehicle.auto_timetable_by_default")); company->Add(new SettingEntry("auto_timetable_separation_rate")); + company->Add(new SettingEntry("timetable_autofill_rounding")); } SettingsPage *accounting = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCOUNTING)); diff --git a/src/settings_type.h b/src/settings_type.h index cc55dcf6c9..6a3c1717ba 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -541,6 +541,7 @@ struct CompanySettings { bool renew_keep_length; ///< sell some wagons if after autoreplace the train is longer than before VehicleDefaultSettings vehicle; ///< default settings for vehicles uint8 auto_timetable_separation_rate; ///< percentage of auto timetable separation change to apply + uint16 timetable_autofill_rounding; ///< round up timetable times to be a multiple of this number of ticks }; /** All settings together for the game. */ diff --git a/src/table/company_settings.ini b/src/table/company_settings.ini index 524252432d..08d9373cfd 100644 --- a/src/table/company_settings.ini +++ b/src/table/company_settings.ini @@ -159,6 +159,21 @@ strval = STR_CONFIG_SETTING_PERCENTAGE cat = SC_EXPERT patxname = ""auto_timetable_separation_rate"" +[SDT_VAR] +base = CompanySettings +var = timetable_autofill_rounding +type = SLE_UINT16 +guiflags = SGF_PER_COMPANY +def = 74 +min = 1 +max = 1000 +interval = 10 +str = STR_CONFIG_SETTING_TIMETABLE_AUTOFILL_ROUNDING_TICKS +strhelp = STR_CONFIG_SETTING_TIMETABLE_AUTOFILL_ROUNDING_TICKS_HELPTEXT +strval = STR_JUST_INT +cat = SC_EXPERT +patxname = ""timetable_autofill_rounding"" + [SDT_END] diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index 3de728f9bc..b1a537238c 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -637,16 +637,18 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) /* Before modifying waiting times, check whether we want to preserve bigger ones. */ if (!real_current_order->IsType(OT_CONDITIONAL) && (travelling || time_taken > real_current_order->GetWaitTime() || remeasure_wait_time)) { - /* Round the time taken up to the nearest day, as this will avoid - * confusion for people who are timetabling in days, and can be - * adjusted later by people who aren't. + /* Round the time taken up to the nearest timetable rounding factor + * (default: day), as this will avoid confusion for people who are + * timetabling in days, and can be adjusted later by people who aren't. * For trains/aircraft multiple movement cycles are done in one * tick. This makes it possible to leave the station and process * e.g. a depot order in the same tick, causing it to not fill * the timetable entry like is done for road vehicles/ships. * Thus always make sure at least one tick is used between the * processing of different orders when filling the timetable. */ - uint time_to_set = CeilDiv(max(time_taken, 1U), DAY_TICKS) * DAY_TICKS; + Company *owner = Company::GetIfValid(v->owner); + uint rounding_factor = owner ? owner->settings.timetable_autofill_rounding : DAY_TICKS; + uint time_to_set = CeilDiv(max(time_taken, 1U), rounding_factor) * rounding_factor; if (travelling && (autofilling || !real_current_order->IsTravelTimetabled())) { ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_TRAVEL_TIME, autofilling);