@@ -381,12 +381,15 @@ void UpdateVehicleTimetable(Vehicle *v,
uint time_taken = v->current_order_time;
v->current_order_time = 0;
if (v->current_order.IsType(OT_IMPLICIT)) return; // no timetabling of auto orders
if (v->cur_real_order_index >= v->GetNumOrders()) return;
Order *real_current_order = v->GetOrder(v->cur_real_order_index);
VehicleOrderID first_manual_order = 0;
for (Order *o = v->GetFirstOrder(); o != NULL && o->IsType(OT_IMPLICIT); o = o->next) {
++first_manual_order;
}
bool just_started = false;
@@ -408,37 +411,40 @@ void UpdateVehicleTimetable(Vehicle *v,
SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
bool autofilling = HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
if (travelling && (!v->current_order.IsWaitTimetabled() ||
(autofilling && !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 */
bool remeasure_wait_time = !real_current_order->IsWaitTimetabled() ||
(autofilling && !HasBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME));
if (travelling && remeasure_wait_time) {
/* We just finished travelling and want to remeasure the loading time,
* so do not apply any restrictions for the loading to finish. */
v->current_order.SetWaitTime(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.GetWaitTime())) {
/* 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.
* 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;
if (travelling && (autofilling || !v->current_order.IsTravelTimetabled())) {
if (travelling && (autofilling || !real_current_order->IsTravelTimetabled())) {
ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_TRAVEL_TIME, autofilling);
} else if (!travelling && (autofilling || !v->current_order.IsWaitTimetabled())) {
} else if (!travelling && (autofilling || !real_current_order->IsWaitTimetabled())) {
ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_WAIT_TIME, autofilling);
if (v->cur_real_order_index == first_manual_order && travelling) {
/* If we just started we would have returned earlier and have not reached
@@ -447,14 +453,14 @@ void UpdateVehicleTimetable(Vehicle *v,
ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
if (autofilling) return;
uint timetabled = travelling ? v->current_order.GetTimetabledTravel() :
v->current_order.GetTimetabledWait();
uint timetabled = travelling ? real_current_order->GetTimetabledTravel() :
real_current_order->GetTimetabledWait();
/* 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
* when this happens. */
if (timetabled == 0 && (travelling || v->lateness_counter >= 0)) return;
Status change: