FS#2944 - Timetable: auto-reset delay counter

Attached to Project: OpenTTD
Opened by John Doe (kvtb) - Monday, 01 June 2009, 15:00 GMT
Last edited by andythenorth (andythenorth) - Thursday, 31 August 2017, 21:43 GMT
Type Feature Request
Category Core
Status With patch
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


if time tables are enabled, and if there is a valid time table set for a certain orderlist (where for each order a duration is known), I would like to have to possibility to ensure that if there is a delay, the delay does not 'explode'.

let's assume the total time table (the cycle time) is 80 days
then the delay of a vehicle in this schedule, can never be larger than 80 days, because as soon as the delay is 80 days, it is back in its original time table cyle.

in fact, what I try to explain, is really easy using some pseudocode :-)

if delay >= timetable cycle time then
delay := 0 // reset delay counter

This task depends upon

Comment by John Doe (kvtb) - Saturday, 20 June 2009, 18:20 GMT
I just checked the source to see if I could do this myself in 5 minutes

the total time table duration (in the first message referred to as timetable cycle time) is not stored in some structure, it is calculated when the timetable dialog is opened.
it is the total_time variable on line 220 in timetable_gui.cpp

a prerequesit for this is that total_time is moved to OrderList.
Once the vehicle's order list has the total timetable time field, it is possible to simple add a few lines to UpdateVehicleTimetable in timetable_cmd.cpp

basically, something like this:

/* Reset vehicle delay if is becomes larger than the duration of the timetable,
* because we are back in the normal timetable loop.
if( v->lateness_counter >= v->orders.list->timetable_duration ) {
v->lateness_counter = 0;
Comment by frosch (frosch) - Saturday, 20 June 2009, 20:22 GMT
You should better use a modulo operator "%" to keep multiple vehicles in sync. But be careful with negative lateness.

Good luck implementing your patch though :)
Comment by John Doe (kvtb) - Sunday, 21 June 2009, 13:17 GMT
okay, yesterday I did not look correctly, the contents of timetable_gui.cpp looked as if there was no total time table duration stored somewhere.
Fortunately, there was already a function GetTimetableTotalDuration somewhere, that I could use.

Using the module operator as suggested by frosch, the code to be added is simply this:

/* Reset vehicle delay if it becomes larger than the duration of the timetable,
* because then we are back in the normal timetable loop. */
v->lateness_counter %= v->orders.list->GetTimetableTotalDuration();

this code has no influence on negative delays

Please apply the attached patch to trunk, thank you in advance!
Comment by John Doe (kvtb) - Sunday, 21 June 2009, 13:22 GMT
if the timetable was not complete, the delay counter would always be reset.
I think that's not needed, so this updated patch uses GetTimetableDurationIncomplete instead of GetTimetableTotalDuration