Scheduled dispatch: Fix handling of missing last/next dispatch times
In some cases
This commit is contained in:
@@ -804,6 +804,12 @@ void UpdateSeparationOrder(Vehicle *v_start)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next scheduled dispatch time
|
||||
* @param ds Dispatch schedule.
|
||||
* @param leave_time Leave time.
|
||||
* @return Dispatch time, or INVALID_STATE_TICKS
|
||||
*/
|
||||
StateTicks GetScheduledDispatchTime(const DispatchSchedule &ds, StateTicks leave_time)
|
||||
{
|
||||
const uint32_t dispatch_duration = ds.GetScheduledDispatchDuration();
|
||||
@@ -821,7 +827,7 @@ StateTicks GetScheduledDispatchTime(const DispatchSchedule &ds, StateTicks leave
|
||||
last_dispatched_offset = ds.GetScheduledDispatchLastDispatch();
|
||||
}
|
||||
|
||||
StateTicks first_slot = -1;
|
||||
StateTicks first_slot = INVALID_STATE_TICKS;
|
||||
|
||||
/* Find next available slots */
|
||||
for (const DispatchSlot &slot : ds.GetScheduledDispatch()) {
|
||||
@@ -839,7 +845,7 @@ StateTicks GetScheduledDispatchTime(const DispatchSchedule &ds, StateTicks leave
|
||||
current_departure += dispatch_duration * ((minimum + dispatch_duration - current_departure - 1) / dispatch_duration);
|
||||
}
|
||||
|
||||
if (first_slot == -1 || first_slot > current_departure) {
|
||||
if (first_slot == INVALID_STATE_TICKS || first_slot > current_departure) {
|
||||
first_slot = current_departure;
|
||||
}
|
||||
}
|
||||
@@ -891,7 +897,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
|
||||
|
||||
const int wait_offset = real_current_order->GetTimetabledWait();
|
||||
StateTicks slot = GetScheduledDispatchTime(ds, _state_ticks + wait_offset);
|
||||
if (slot > -1) {
|
||||
if (slot != INVALID_STATE_TICKS) {
|
||||
just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
|
||||
SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
|
||||
v->lateness_counter = (_state_ticks - slot + wait_offset).AsTicks();
|
||||
|
Reference in New Issue
Block a user