From: Mikko Rasa Date: Fri, 6 Feb 2015 14:45:54 +0000 (+0200) Subject: Sync timetable to clock on first tick X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b652dfb998dd416d26f909798e58964ef84eda11;p=r2c2.git Sync timetable to clock on first tick This is not perfect, but it allows some flexibility in restarting the program. --- diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index 93f61c5..7ce8127 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); @@ -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) { diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h index f3d6239..3385a8e 100644 --- a/source/libr2c2/timetable.h +++ b/source/libr2c2/timetable.h @@ -73,6 +73,7 @@ private: std::list rows; std::list::iterator current_row; bool update_pending; + bool sync_to_clock; public: Timetable(Train &);