]> git.tdb.fi Git - r2c2.git/commitdiff
Sync timetable to clock on first tick
authorMikko Rasa <tdb@tdb.fi>
Fri, 6 Feb 2015 14:45:54 +0000 (16:45 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 6 Feb 2015 21:58:54 +0000 (23:58 +0200)
This is not perfect, but it allows some flexibility in restarting the
program.

source/libr2c2/timetable.cpp
source/libr2c2/timetable.h

index 93f61c50608d0b56839bf6ba59af8ba6b4410c47..7ce8127d433b7995a6b9ff91aa9f1f0f53909f60 100644 (file)
@@ -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<AIControl>())
                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<Row>::iterator i=rows.begin(); i!=rows.end(); ++i)
+                       if(i->type==DEPART && i->time>=clock.get_current_time())
+                       {
+                               current_row = i;
+                               break;
+                       }
+       }
+
        list<Row>::iterator arrive;
        list<Row>::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<Row>::const_iterator i=depart; i!=rows.end(); ++i)
        {
index f3d62399e09b11a1e3d03843470229e957bb1e6b..3385a8eeaf97de6a3142d868a436d01d0125f22e 100644 (file)
@@ -73,6 +73,7 @@ private:
        std::list<Row> rows;
        std::list<Row>::iterator current_row;
        bool update_pending;
+       bool sync_to_clock;
 
 public:
        Timetable(Train &);