]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/timetable.cpp
Move the responsibility of starting the train to TrainRouter
[r2c2.git] / source / libr2c2 / timetable.cpp
index b94cbf08fcfc37ad9d3485aeaf78f1ffe76ec615..da01b599876d03c7f18d0e1bae05eb2951e9bff5 100644 (file)
@@ -25,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)
@@ -88,22 +89,6 @@ void Timetable::tick(const Time::TimeDelta &dt)
 {
        if(update_pending && !train.get_block_allocator().is_active())
                update_route();
-
-       if(current_row->type==DEPART)
-       {
-               const Clock &clock = train.get_layout().get_clock();
-
-               Time::TimeDelta t = clock.get_current_time();
-               if(t<current_row->time)
-                       t += Time::day;
-
-               Time::TimeDelta b = t-dt*clock.get_rate();
-               if(b<current_row->time)
-               {
-                       train.ai_message(Message("set-target-speed", train.get_maximum_speed()));
-                       ++current_row;
-               }
-       }
 }
 
 void Timetable::save(list<DataFile::Statement> &st) const
@@ -201,11 +186,18 @@ void Timetable::update_route()
                        dt += Time::day;
                train.ai_message(Message("set-trip-duration", dt/clock.get_rate()));
        }
+
+       late_arrival = false;
 }
 
 void Timetable::event(TrainAI &, const Message &msg)
 {
-       if(msg.type=="arrived")
+       if(msg.type=="departed")
+       {
+               if(current_row->type==DEPART)
+                       ++current_row;
+       }
+       else if(msg.type=="arrived")
        {
                if(current_row->type==ARRIVE)
                        record_time();
@@ -229,6 +221,12 @@ 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),
@@ -271,6 +269,7 @@ Timetable::Row::Loader::Loader(Row &r, Layout &l):
        add("time", &Loader::time);
        add("type", &Row::type);
        add("zone", &Loader::zone);
+       add("zone", &Loader::zone_numbered);
 }
 
 void Timetable::Row::Loader::block(unsigned id)
@@ -283,7 +282,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);
 }