]> git.tdb.fi Git - r2c2.git/commitdiff
Support waypoints in Timetable
authorMikko Rasa <tdb@tdb.fi>
Wed, 26 Mar 2014 20:44:31 +0000 (22:44 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 26 Mar 2014 20:44:31 +0000 (22:44 +0200)
data/timetablepanel.ui
source/engineer/timetablepanel.cpp
source/libr2c2/timetable.cpp
source/libr2c2/timetable.h

index 3bd48da62ccfdd1088f88406b3ef7cd044f044be..5d9b16939aa8a9d74be20b7122648116adecb027 100644 (file)
@@ -24,6 +24,7 @@ column
                {
                        item "Arrive";
                        item "Depart";
+                       item "Through";
                };
 
                label "lbl_target"
index 878de865835aa8a44cf48b5619ad4354a3540675..12ae2a820c4a4affa50a925d9bf709a9a4f58c48 100644 (file)
@@ -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()));
                }
index ed7d01831445e3745a4e7a297d687e5f3c3d7e00..96081820a56a54f236ee88d40032354cded852b0 100644 (file)
@@ -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<const TrackChain *>();
+               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()));
 }
index 07250ca94a941376601ad0dafd4b7419c4daaba2..da16d3c0d488c23cffc7d3879fcf2c367e611141 100644 (file)
@@ -27,7 +27,8 @@ public:
        enum RowType
        {
                ARRIVE = 1,
-               DEPART
+               DEPART,
+               THROUGH
        };
 
        struct Row
@@ -83,6 +84,7 @@ private:
        void check_update(std::list<Row>::const_iterator);
        void update_route();
        void event(TrainAI &, const Message &);
+       void record_time();
 };
 
 } // namespace R2C2