Departure boards: Fix handling of invalid/empty dispatch schedules
This commit is contained in:
@@ -114,13 +114,18 @@ static bool VehicleSetNextDepartureTime(Ticks *previous_departure, Ticks *waitin
|
||||
if (order->IsScheduledDispatchOrder(true) && !(arrived_at_timing_point && is_current_implicit_order(order))) {
|
||||
const DispatchSchedule &ds = v->orders->GetDispatchScheduleByIndex(order->GetDispatchScheduleIndex());
|
||||
|
||||
StateTicks actual_departure = -1;
|
||||
StateTicks actual_departure = INT64_MAX;
|
||||
const StateTicks begin_time = ds.GetScheduledDispatchStartTick();
|
||||
const uint32_t dispatch_duration = ds.GetScheduledDispatchDuration();
|
||||
const int32_t max_delay = ds.GetScheduledDispatchDelay();
|
||||
|
||||
/* Earliest possible departure according to schedue */
|
||||
StateTicks earliest_departure = begin_time + ds.GetScheduledDispatchLastDispatch();
|
||||
/* Earliest possible departure according to the schedule */
|
||||
StateTicks earliest_departure = begin_time;
|
||||
if (ds.GetScheduledDispatchLastDispatch() != INVALID_SCHEDULED_DISPATCH_OFFSET) {
|
||||
earliest_departure += ds.GetScheduledDispatchLastDispatch();
|
||||
} else {
|
||||
earliest_departure--;
|
||||
}
|
||||
|
||||
/* Earliest possible departure according to vehicle current timetable */
|
||||
const StateTicks ready_to_depart_time = state_ticks_base + *previous_departure + order->GetTravelTime() + order->GetTimetabledWait();
|
||||
@@ -148,11 +153,19 @@ static bool VehicleSetNextDepartureTime(Ticks *previous_departure, Ticks *waitin
|
||||
current_departure += dispatch_duration;
|
||||
}
|
||||
|
||||
if (actual_departure == -1 || actual_departure > current_departure) {
|
||||
if (actual_departure > current_departure) {
|
||||
actual_departure = current_departure;
|
||||
}
|
||||
}
|
||||
|
||||
if (actual_departure == INT64_MAX) {
|
||||
/* Failed to find a dispatch slot for this departure at all, the schedule is invalid/empty.
|
||||
* Just treat it as a non-dispatch order. */
|
||||
*previous_departure += order->GetTravelTime() + order->GetWaitTime();
|
||||
*waiting_time = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
*waiting_time = (actual_departure - state_ticks_base).AsTicks() - *previous_departure - order->GetTravelTime();
|
||||
*previous_departure = (actual_departure - state_ticks_base).AsTicks();
|
||||
if (!ds.GetScheduledDispatchReuseSlots()) {
|
||||
|
@@ -748,7 +748,6 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
|
||||
uint arrival = 0;
|
||||
|
||||
StateTicks now_date = _state_ticks;
|
||||
StateTicks max_date = now_date + GetDeparturesMaxTicksAhead();
|
||||
|
||||
/* Draw each departure. */
|
||||
for (uint i = 0; i < max_departures; ++i) {
|
||||
@@ -774,11 +773,6 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If for some reason the departure is too far in the future or is at a negative time, skip it. */
|
||||
if (d->scheduled_tick > max_date || d->scheduled_tick < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (d->terminus == INVALID_STATION) continue;
|
||||
|
||||
StringID time_str;
|
||||
|
Reference in New Issue
Block a user