diff -r e336f1784ba4 src/lang/english.txt --- a/src/lang/english.txt Tue Oct 28 15:47:42 2008 +0000 +++ b/src/lang/english.txt Tue Oct 28 17:36:14 2008 +0100 @@ -1133,6 +1133,7 @@ STR_CONFIG_PATCHES_LOADING_INDICATORS_AL STR_CONFIG_PATCHES_LOADING_INDICATORS_ALL :All companies STR_CONFIG_PATCHES_TIMETABLE_ALLOW :{LTBLUE}Enable timetabling for vehicles: {ORANGE}{STRING1} STR_CONFIG_PATCHES_TIMETABLE_IN_TICKS :{LTBLUE}Show timetable in ticks rather than days: {ORANGE}{STRING1} +STR_CONFIG_PATCHES_AUTOFILL_PRESERVE_WAIT_TIME :{LTBLUE}Preserve waiting times when doing non-destructive autofill: {ORANGE}{STRING1} STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE :{LTBLUE}Default rail type (after new game/game load): {ORANGE}{STRING1} STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_RAIL :Normal Rail STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE_ELRAIL :Electrified Rail @@ -2939,7 +2940,7 @@ STR_TIMETABLE_TOTAL_TIME STR_TIMETABLE_TOTAL_TIME :This timetable will take {STRING1} to complete STR_TIMETABLE_TOTAL_TIME_INCOMPLETE :This timetable will take at least {STRING1} to complete (not all timetabled) STR_TIMETABLE_AUTOFILL :{BLACK}Autofill -STR_TIMETABLE_AUTOFILL_TOOLTIP :{BLACK}Fill the timetable automatically with the values from the first journey +STR_TIMETABLE_AUTOFILL_TOOLTIP :{BLACK}Fill the timetable automatically with the values from the first journey (CTRL-click to avoid clearing the timetable) ##id 0x9000 STR_9000_ROAD_VEHICLE_IN_THE_WAY :{WHITE}Road vehicle in the way diff -r e336f1784ba4 src/settings.cpp --- a/src/settings.cpp Tue Oct 28 15:47:42 2008 +0000 +++ b/src/settings.cpp Tue Oct 28 17:36:14 2008 +0100 @@ -1436,6 +1436,7 @@ const SettingDesc _patch_settings[] = { SDTC_BOOL(gui.pause_on_newgame, S, 0, false, STR_CONFIG_PATCHES_PAUSE_ON_NEW_GAME, NULL), SDTC_VAR(gui.advanced_vehicle_list, SLE_UINT8, S, MS, 1, 0, 2, 0, STR_CONFIG_PATCHES_ADVANCED_VEHICLE_LISTS, NULL), SDTC_BOOL(gui.timetable_in_ticks, S, 0, false, STR_CONFIG_PATCHES_TIMETABLE_IN_TICKS, NULL), + SDTC_BOOL(gui.autofill_preserve_wait_time, S, 0, false, STR_CONFIG_PATCHES_AUTOFILL_PRESERVE_WAIT_TIME, NULL), SDTC_VAR(gui.loading_indicators, SLE_UINT8, S, MS, 1, 0, 2, 0, STR_CONFIG_PATCHES_LOADING_INDICATORS, RedrawScreen), SDTC_VAR(gui.default_rail_type, SLE_UINT8, S, MS, 4, 0, 6, 0, STR_CONFIG_PATCHES_DEFAULT_RAIL_TYPE, NULL), SDTC_BOOL(gui.enable_signal_gui, S, 0, false, STR_CONFIG_PATCHES_ENABLE_SIGNAL_GUI, CloseSignalGUI), diff -r e336f1784ba4 src/settings_gui.cpp --- a/src/settings_gui.cpp Tue Oct 28 15:47:42 2008 +0000 +++ b/src/settings_gui.cpp Tue Oct 28 17:36:14 2008 +0100 @@ -705,6 +705,7 @@ static const char *_patches_vehicles[] = "vehicle.freight_trains", "vehicle.plane_speed", "order.timetabling", + "gui.autofill_preserve_wait_time", "vehicle.dynamic_engines", }; diff -r e336f1784ba4 src/settings_type.h --- a/src/settings_type.h Tue Oct 28 15:47:42 2008 +0000 +++ b/src/settings_type.h Tue Oct 28 17:36:14 2008 +0100 @@ -71,6 +71,7 @@ struct GUISettings { Year ending_year; ///< end of the game (just show highscore) Year colored_news_year; ///< when does newspaper become colored? bool timetable_in_ticks; ///< whether to show the timetable in ticks rather than days + bool autofill_preserve_wait_time; ///< whether non-destructive autofill should preserve wait times bool bridge_pillars; ///< show bridge pillars for high bridges bool auto_euro; ///< automatically switch to euro in 2002 byte drag_signals_density; ///< many signals density diff -r e336f1784ba4 src/timetable_cmd.cpp --- a/src/timetable_cmd.cpp Tue Oct 28 15:47:42 2008 +0000 +++ b/src/timetable_cmd.cpp Tue Oct 28 17:36:14 2008 +0100 @@ -133,7 +133,10 @@ CommandCost CmdSetVehicleOnTime(TileInde * @param tile Not used. * @param flags Operation to perform. * @param p1 Vehicle index. - * @param p2 Set to 1 to enable, 0 to disable. + * @param p2 Various bitstuffed elements + * - p2 = (bit 0) - Set to 1 to enable, 0 to disable autofill. + * - p2 = (bit 1) - Set to 1 for non-destructive mode (do not clear timetable) + * - p2 = (bit 2) - Set to 1 to preserve waiting times in non-destructive mode */ CommandCost CmdAutofillTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { @@ -146,21 +149,28 @@ CommandCost CmdAutofillTimetable(TileInd if (!CheckOwnership(v->owner)) return CMD_ERROR; if (flags & DC_EXEC) { - if (p2 == 1) { + if (HasBit(p2, 0)) { /* Start autofilling the timetable, which clears all the current * timings and clears the "timetable has started" bit. */ SetBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED); - for (Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) { - order->wait_time = 0; - order->travel_time = 0; + if (HasBit(p2, 1) && HasBit(p2, 2)) SetBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); + + if (!HasBit(p2, 1)) { + for (Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) { + order->wait_time = 0; + order->travel_time = 0; + } + + v->current_order.wait_time = 0; + v->current_order.travel_time = 0; } - v->current_order.wait_time = 0; - v->current_order.travel_time = 0; + v->lateness_counter = 0; } else { ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); + ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); } } @@ -179,33 +189,48 @@ void UpdateVehicleTimetable(Vehicle *v, v->current_order_time = 0; if (!_settings_game.order.timetabling) return; + + bool just_started = false; /* Make sure the timetable only starts when the vehicle reaches the first * order, not when travelling from the depot to the first station. */ if (v->cur_order_index == 0 && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) { SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED); - return; + just_started = true; } if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return; if (HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) { - if (timetabled == 0) { + if (travelling && !HasBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME)) { + /* Need to clear that now as otherwise we are not able to reduce the wait time */ + v->current_order.wait_time = 0; + } + + if (just_started) return; + + /* Modify station waiting time only if our new value is larger (this is + * always the case when we cleared the timetable). */ + if (!v->current_order.IsType(OT_CONDITIONAL) && (travelling || time_taken > v->current_order.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. */ time_taken = (((time_taken - 1) / DAY_TICKS) + 1) * DAY_TICKS; - if (!v->current_order.IsType(OT_CONDITIONAL)) { - ChangeTimetable(v, v->cur_order_index, time_taken, travelling); - } - return; - } else if (v->cur_order_index == 0) { - /* Otherwise if we're at the beginning and it already has a value, - * assume that autofill is finished and turn it off again. */ + ChangeTimetable(v, v->cur_order_index, time_taken, travelling); + } + + if (v->cur_order_index == 0 && travelling) { + /* If we just started we would have returned earlier and have not reached + * this code. So obviously, we have completed our round: So turn autofill + * off again. */ ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); - } - } + ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); + } + return; + } + + if (just_started) return; /* Vehicles will wait at stations if they arrive early even if they are not * timetabled to wait there, so make sure the lateness counter is updated diff -r e336f1784ba4 src/timetable_gui.cpp --- a/src/timetable_gui.cpp Tue Oct 28 15:47:42 2008 +0000 +++ b/src/timetable_gui.cpp Tue Oct 28 17:36:14 2008 +0100 @@ -301,9 +301,13 @@ struct TimetableWindow : Window { DoCommandP(0, v->index, 0, NULL, CMD_SET_VEHICLE_ON_TIME | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE)); break; - case TTV_AUTOFILL: /* Autofill the timetable. */ - DoCommandP(0, v->index, HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE) ? 0 : 1, NULL, CMD_AUTOFILL_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE)); - break; + case TTV_AUTOFILL: { /* Autofill the timetable. */ + uint32 p2 = 0; + if (!HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(p2, 0); + if (_ctrl_pressed) SetBit(p2, 1); + if (_settings_client.gui.autofill_preserve_wait_time) SetBit(p2, 2); + DoCommandP(0, v->index, p2, NULL, CMD_AUTOFILL_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE)); + } break; } this->SetDirty(); diff -r e336f1784ba4 src/vehicle_base.h --- a/src/vehicle_base.h Tue Oct 28 15:47:42 2008 +0000 +++ b/src/vehicle_base.h Tue Oct 28 17:36:14 2008 +0100 @@ -75,8 +75,9 @@ enum VehicleFlags { VF_LOADING_FINISHED, VF_CARGO_UNLOADING, VF_BUILT_AS_PROTOTYPE, - VF_TIMETABLE_STARTED, ///< Whether the vehicle has started running on the timetable yet. - VF_AUTOFILL_TIMETABLE, ///< Whether the vehicle should fill in the timetable automatically. + VF_TIMETABLE_STARTED, ///< Whether the vehicle has started running on the timetable yet. + VF_AUTOFILL_TIMETABLE, ///< Whether the vehicle should fill in the timetable automatically. + VF_AUTOFILL_PRES_WAIT_TIME, ///< Whether non-destructive auto-fill should preserve waiting times }; struct VehicleRail {