X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftimetable.cpp;h=41cbbf00ab834350714025c865853d54462c4796;hb=d6516b0d9faa26fe6c64000c34f8d820f91ac479;hp=93f61c50608d0b56839bf6ba59af8ba6b4410c47;hpb=e8d2abb48b5236cc3455a035628292ae7908240e;p=r2c2.git diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index 93f61c5..41cbbf0 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); @@ -24,6 +25,7 @@ Timetable::Timetable(Train &t): new TrainRouter(train); train.signal_ai_event.connect(sigc::mem_fun(this, &Timetable::event)); + train.get_layout().get_clock().signal_discontinuity.connect(sigc::mem_fun(this, &Timetable::clock_discontinuity)); } void Timetable::append_row(const Row &r) @@ -115,7 +117,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 +146,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,26 +174,22 @@ 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) { - if(i->type==ARRIVE) - { - train.ai_message(Message("set-destination", i->target)); - break; - } - else if(i->type==DEPART) + if(i->type==DEPART) { Time::TimeDelta dt = i->time-clock.get_current_time(); while(dttarget, i->direction))); + if(i->type==ARRIVE) + break; } - else if(i->type==THROUGH) - train.ai_message(Message("add-waypoint", i->target)); } list::iterator next_depart = find_trip(arrive, 0); @@ -218,10 +230,17 @@ void Timetable::record_time() signal_row_modified.emit(i, *current_row); } +void Timetable::clock_discontinuity() +{ + update_pending = true; + sync_to_clock = true; +} + Timetable::Row::Row(): type(ARRIVE), - target(0) + target(0), + direction(TrackChain::UNSPECIFIED) { } void Timetable::Row::save(list &st) const @@ -229,6 +248,8 @@ void Timetable::Row::save(list &st) const st.push_back((DataFile::Statement("type"), type)); st.push_back((DataFile::Statement("time"), time.raw())); st.push_back(target->save_reference()); + if(direction) + st.push_back((DataFile::Statement("direction"), direction)); } @@ -253,9 +274,11 @@ Timetable::Row::Loader::Loader(Row &r, Layout &l): layout(l) { add("block", &Loader::block); + add("direction", &Row::direction); add("time", &Loader::time); add("type", &Row::type); add("zone", &Loader::zone); + add("zone", &Loader::zone_numbered); } void Timetable::Row::Loader::block(unsigned id) @@ -268,7 +291,12 @@ void Timetable::Row::Loader::time(Time::RawTime t) obj.time = Time::TimeDelta(t); } -void Timetable::Row::Loader::zone(const string &name, unsigned number) +void Timetable::Row::Loader::zone(const string &name) +{ + zone_numbered(name, 0); +} + +void Timetable::Row::Loader::zone_numbered(const string &name, unsigned number) { obj.target = &layout.get_zone(name, number); }