From: Mikko Rasa Date: Wed, 26 Mar 2014 20:44:31 +0000 (+0200) Subject: Support waypoints in Timetable X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a34347c6642d89a44960aeddc372891744cded15;p=r2c2.git Support waypoints in Timetable --- diff --git a/data/timetablepanel.ui b/data/timetablepanel.ui index 3bd48da..5d9b169 100644 --- a/data/timetablepanel.ui +++ b/data/timetablepanel.ui @@ -24,6 +24,7 @@ column { item "Arrive"; item "Depart"; + item "Through"; }; label "lbl_target" diff --git a/source/engineer/timetablepanel.cpp b/source/engineer/timetablepanel.cpp index 878de86..12ae2a8 100644 --- a/source/engineer/timetablepanel.cpp +++ b/source/engineer/timetablepanel.cpp @@ -230,6 +230,7 @@ TimetableRowItem::TimetableRowItem(ValueType row) { case Timetable::ARRIVE: type = "Arrive at "; break; case Timetable::DEPART: type = "Depart from "; break; + case Timetable::THROUGH: type = "Go through "; break; } add(*new GLtk::Label(type+row->target->get_name())); } diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index ed7d018..9608182 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -162,6 +162,8 @@ void Timetable::update_route() dt /= clock.get_rate(); train.ai_message(Message("set-departure-delay", dt)); } + else if(i->type==THROUGH) + train.ai_message(Message("add-waypoint", i->target)); } } @@ -170,15 +172,27 @@ void Timetable::event(TrainAI &, const Message &msg) if(msg.type=="arrived") { if(current_row->type==ARRIVE) + record_time(); + update_pending = true; + } + else if(msg.type=="waypoint-reached") + { + const TrackChain *wp = msg.value.value(); + if(current_row->type==THROUGH && current_row->target==wp) { - current_row->time = train.get_layout().get_clock().get_current_time(); - unsigned i = distance(rows.begin(), current_row); - signal_row_modified.emit(i, *current_row); + record_time(); + ++current_row; } - update_pending = true; } } +void Timetable::record_time() +{ + current_row->time = train.get_layout().get_clock().get_current_time(); + unsigned i = distance(rows.begin(), current_row); + signal_row_modified.emit(i, *current_row); +} + Timetable::Row::Row(): type(ARRIVE), @@ -241,6 +255,7 @@ void operator<<(LexicalConverter &conv, Timetable::RowType rt) { case Timetable::ARRIVE: conv.result("ARRIVE"); return; case Timetable::DEPART: conv.result("DEPART"); return; + case Timetable::THROUGH: conv.result("THROUGH"); return; default: throw lexical_error(format("conversion of RowType(%d) to string", rt)); } } @@ -251,6 +266,8 @@ void operator>>(const LexicalConverter &conv, Timetable::RowType &rt) rt = Timetable::ARRIVE; else if(conv.get()=="DEPART") rt = Timetable::DEPART; + else if(conv.get()=="THROUGH") + rt = Timetable::THROUGH; else throw lexical_error(format("conversion of '%s' to RowType", conv.get())); } diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h index 07250ca..da16d3c 100644 --- a/source/libr2c2/timetable.h +++ b/source/libr2c2/timetable.h @@ -27,7 +27,8 @@ public: enum RowType { ARRIVE = 1, - DEPART + DEPART, + THROUGH }; struct Row @@ -83,6 +84,7 @@ private: void check_update(std::list::const_iterator); void update_route(); void event(TrainAI &, const Message &); + void record_time(); }; } // namespace R2C2