X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftimetable.cpp;h=2fadcd54b4f55d210b7c3bee6eab58a382f2f4e0;hb=8a2b5c1ac2fc07e280dc678165d2ca58f7d07e32;hp=93f61c50608d0b56839bf6ba59af8ba6b4410c47;hpb=e8d2abb48b5236cc3455a035628292ae7908240e;p=r2c2.git diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index 93f61c5..2fadcd5 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -16,7 +16,8 @@ namespace R2C2 { 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()) new AIControl(train); @@ -115,7 +116,7 @@ void Timetable::save(list &st) const } } -void Timetable::check_update(list::const_iterator i) +void Timetable::check_update(const list::const_iterator &i) { for(list::const_iterator j=current_row; (j!=rows.end() && j!=i); ++j) if(j->type==ARRIVE) @@ -144,6 +145,20 @@ void Timetable::update_route() 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::iterator i=rows.begin(); i!=rows.end(); ++i) + if(i->type==DEPART && i->time>=clock.get_current_time()) + { + current_row = i; + break; + } + } + list::iterator arrive; list::iterator depart = find_trip(current_row, &arrive); if(depart==rows.end()) @@ -158,8 +173,6 @@ void Timetable::update_route() train.ai_message(Message("clear-route")); - const Clock &clock = train.get_layout().get_clock(); - current_row = depart; for(list::const_iterator i=depart; i!=rows.end(); ++i) { @@ -173,8 +186,7 @@ void Timetable::update_route() Time::TimeDelta dt = i->time-clock.get_current_time(); while(dttype==THROUGH) train.ai_message(Message("add-waypoint", i->target));