diff -r 44d201d223f9 src/lang/english.txt --- a/src/lang/english.txt Tue Nov 04 18:44:15 2008 +0000 +++ b/src/lang/english.txt Thu Nov 06 15:21:22 2008 +0100 @@ -2939,7 +2939,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 next journey (CTRL-click to try to keep waiting times) ##id 0x9000 STR_9000_ROAD_VEHICLE_IN_THE_WAY :{WHITE}Road vehicle in the way diff -r 44d201d223f9 src/timetable_cmd.cpp --- a/src/timetable_cmd.cpp Tue Nov 04 18:44:15 2008 +0000 +++ b/src/timetable_cmd.cpp Thu Nov 06 15:21:22 2008 +0100 @@ -133,7 +133,9 @@ 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 to preserve waiting times in non-destructive mode */ CommandCost CmdAutofillTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { @@ -146,21 +148,18 @@ 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; - } - - v->current_order.wait_time = 0; - v->current_order.travel_time = 0; + if (HasBit(p2, 1)) SetBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); + + v->lateness_counter = 0; } else { ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); + ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); } } @@ -179,33 +178,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 44d201d223f9 src/timetable_gui.cpp --- a/src/timetable_gui.cpp Tue Nov 04 18:44:15 2008 +0000 +++ b/src/timetable_gui.cpp Thu Nov 06 15:21:22 2008 +0100 @@ -301,9 +301,12 @@ 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); + DoCommandP(0, v->index, p2, NULL, CMD_AUTOFILL_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE)); + } break; } this->SetDirty(); diff -r 44d201d223f9 src/vehicle_base.h --- a/src/vehicle_base.h Tue Nov 04 18:44:15 2008 +0000 +++ b/src/vehicle_base.h Thu Nov 06 15:21:22 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 {