Timetable::Timetable(Train &t):
TrainAI(t),
current_row(rows.end()),
- update_pending(false)
+ update_pending(false),
+ sync_to_clock(true)
{
if(!train.get_ai_of_type<AIControl>())
new AIControl(train);
}
}
-void Timetable::check_update(list<Row>::const_iterator i)
+void Timetable::check_update(const list<Row>::const_iterator &i)
{
for(list<Row>::const_iterator j=current_row; (j!=rows.end() && j!=i); ++j)
if(j->type==ARRIVE)
if(rows.empty())
return;
+ const Clock &clock = train.get_layout().get_clock();
+
+ if(sync_to_clock)
+ {
+ sync_to_clock = false;
+ current_row = rows.begin();
+ for(list<Row>::iterator i=rows.begin(); i!=rows.end(); ++i)
+ if(i->type==DEPART && i->time>=clock.get_current_time())
+ {
+ current_row = i;
+ break;
+ }
+ }
+
list<Row>::iterator arrive;
list<Row>::iterator depart = find_trip(current_row, &arrive);
if(depart==rows.end())
train.ai_message(Message("clear-route"));
- const Clock &clock = train.get_layout().get_clock();
-
current_row = depart;
for(list<Row>::const_iterator i=depart; i!=rows.end(); ++i)
{
if(i->type==ARRIVE)
{
- train.ai_message(Message("set-destination", i->target));
+ train.ai_message(Message("add-waypoint", i->target));
break;
}
else if(i->type==DEPART)
Time::TimeDelta dt = i->time-clock.get_current_time();
while(dt<Time::zero)
dt += Time::day;
- dt /= clock.get_rate();
- train.ai_message(Message("set-departure-delay", dt));
+ train.ai_message(Message("set-departure-delay", dt/clock.get_rate()));
}
else if(i->type==THROUGH)
train.ai_message(Message("add-waypoint", i->target));