]> git.tdb.fi Git - r2c2.git/commitdiff
Ensure that Timetable has necessary helper AIs
authorMikko Rasa <tdb@tdb.fi>
Thu, 29 Jan 2015 16:50:52 +0000 (18:50 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 29 Jan 2015 16:50:52 +0000 (18:50 +0200)
Since AIControl and TrainRouter don't emit statements to the state file,
they are not created automatically when loading the state.  If they are
missing, the timetable won't be able to operate.

source/libr2c2/timetable.cpp

index 96081820a56a54f236ee88d40032354cded852b0..42414f63d0baf3ecfe14fcbda9afb4de8c3669e3 100644 (file)
@@ -1,8 +1,10 @@
 #include <msp/strings/format.h>
+#include "aicontrol.h"
 #include "clock.h"
 #include "layout.h"
 #include "timetable.h"
 #include "train.h"
+#include "trainrouter.h"
 #include "zone.h"
 
 using namespace std;
@@ -15,6 +17,11 @@ Timetable::Timetable(Train &t):
        current_row(rows.end()),
        update_pending(false)
 {
+       if(!train.get_ai_of_type<AIControl>())
+               new AIControl(train);
+       if(!train.get_ai_of_type<TrainRouter>())
+               new TrainRouter(train);
+
        train.signal_ai_event.connect(sigc::mem_fun(this, &Timetable::event));
 }