Departures: Enable smart terminus detection for scheduled dispatch source mode

This commit is contained in:
Jonathan G Rennison 2024-09-08 19:33:01 +01:00
parent 0d8f9d7630
commit de972cd48f

View File

@ -301,15 +301,19 @@ static void ScheduledDispatchDepartureLocalFix(DepartureList &departure_list)
}); });
} }
static void ScheduledDispatchSmartTerminusDetection(DepartureList &departure_list) static void ScheduledDispatchSmartTerminusDetection(DepartureList &departure_list, Ticks loop_duration = 0)
{ {
btree::btree_map<StationID, StateTicks> earliest_seen; btree::btree_map<StationID, StateTicks> earliest_seen;
for (auto iter = departure_list.rbegin(); iter != departure_list.rend(); ++iter) { auto check_departure = [&](Departure *d) {
Departure *d = iter->get();
if (d->show_as_via) continue;
size_t calling_at_size = d->calling_at.size(); size_t calling_at_size = d->calling_at.size();
/* If the terminus has already been moved back, find the right starting offset */
while (calling_at_size >= 2) {
if (d->terminus == d->calling_at[calling_at_size - 1]) break;
calling_at_size--;
}
while (calling_at_size >= 2) { while (calling_at_size >= 2) {
if (d->terminus.scheduled_tick != 0) { if (d->terminus.scheduled_tick != 0) {
auto iter = earliest_seen.find(d->terminus.station); auto iter = earliest_seen.find(d->terminus.station);
@ -344,6 +348,28 @@ static void ScheduledDispatchSmartTerminusDetection(DepartureList &departure_lis
if (seen == 0 || c.scheduled_tick < seen) seen = c.scheduled_tick; if (seen == 0 || c.scheduled_tick < seen) seen = c.scheduled_tick;
} }
} }
};
for (auto iter = departure_list.rbegin(); iter != departure_list.rend(); ++iter) {
Departure *d = iter->get();
if (d->show_as_via) continue;
check_departure(d);
}
if (loop_duration > 0) {
/* Second pass: offset all earliest seen by the loop duration, and run through again.
* This is so that departures at the end can be compared with departures at the start of the next schedule period/day. */
for (auto &it : earliest_seen) {
it.second += loop_duration;
}
for (auto iter = departure_list.rbegin(); iter != departure_list.rend(); ++iter) {
Departure *d = iter->get();
if (d->show_as_via) continue;
check_departure(d);
}
} }
} }
@ -1485,6 +1511,10 @@ static DepartureList MakeDepartureListScheduleMode(DepartureOrderDestinationDete
return a->scheduled_tick < b->scheduled_tick; return a->scheduled_tick < b->scheduled_tick;
}); });
if (type == D_DEPARTURE && _settings_client.gui.departure_smart_terminus) {
ScheduledDispatchSmartTerminusDetection(result, tick_duration);
}
return result; return result;
} }