From c877e1027296c1b02a99a7e2d95e666afb4e9983 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 30 Jan 2016 15:16:35 +0000 Subject: [PATCH] Avoid set distributed timetable start setting start dates in the past. Adjust start dates for vehicles before the base one forward by one timetable duration if they would start before the present date. Whitespace/format fixes. --- src/timetable_cmd.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index 5c2849bc24..7e35a71455 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -314,6 +314,9 @@ CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, ClrBit(w->vehicle_flags, VF_TIMETABLE_STARTED); /* Do multiplication, then division to reduce rounding errors. */ w->timetable_start = start_date + idx * total_duration / num_vehs / DAY_TICKS; + if (w->timetable_start < _date && idx < 0) { + w->timetable_start += (total_duration / DAY_TICKS); + } SetWindowDirty(WC_VEHICLE_TIMETABLE, w->index); } @@ -693,14 +696,16 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling) } if (new_time < 1) new_time = 1; - if (new_time != (int32)timetabled) + if (new_time != (int32)timetabled) { ChangeTimetable(v, v->cur_real_order_index, new_time, travelling ? MTF_TRAVEL_TIME : MTF_WAIT_TIME, true); + } } else if (timetabled == 0 && HasBit(v->vehicle_flags, VF_AUTOMATE_TIMETABLE)) { /* Add times for orders that are not yet timetabled, even while not autofilling */ - if (travelling) - ChangeTimetable(v, v->cur_real_order_index, time_taken, travelling ? MTF_TRAVEL_TIME : MTF_WAIT_TIME, true); - else - ChangeTimetable(v, v->cur_real_order_index, time_loading, travelling ? MTF_TRAVEL_TIME : MTF_WAIT_TIME, true); + if (travelling) { + ChangeTimetable(v, v->cur_real_order_index, time_taken, MTF_TRAVEL_TIME, true); + } else { + ChangeTimetable(v, v->cur_real_order_index, time_loading, MTF_WAIT_TIME, true); + } } /* Vehicles will wait at stations if they arrive early even if they are not