]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/layout.cpp
Set correct Z coordinate to vehicle position
[r2c2.git] / source / libmarklin / layout.cpp
index af88d7d8fd2e35f3a44af86ff24640c85c003d1d..1448a1d76eef08085e76f4604c29fc2586b43e04 100644 (file)
@@ -9,16 +9,17 @@ Distributed under the GPL
 #include <msp/core/refptr.h>
 #include <msp/datafile/parser.h>
 #include <msp/datafile/writer.h>
+#include <msp/io/print.h>
 #include <msp/time/utils.h>
 #include "block.h"
 #include "catalogue.h"
 #include "driver.h"
 #include "layout.h"
-#include "locotype.h"
 #include "route.h"
 #include "track.h"
 #include "tracktype.h"
 #include "train.h"
+#include "vehicletype.h"
 
 using namespace std;
 using namespace Msp;
@@ -216,6 +217,7 @@ void Layout::emergency(const string &msg)
 {
        if(driver)
                driver->halt(true);
+       IO::print("Emergency: %s\n", msg);
        signal_emergency.emit(msg);
 }
 
@@ -237,6 +239,9 @@ void Layout::save(const string &fn)
 
        for(map<string, Route *>::iterator i=routes.begin(); i!=routes.end(); ++i)
        {
+               if(i->second->is_temporary())
+                       continue;
+
                DataFile::Statement st("route");
                st.append(i->first);
                i->second->save(st.sub);
@@ -287,6 +292,9 @@ void Layout::check_routes()
 {
        for(map<string, Route *>::iterator i=routes.begin(); i!=routes.end(); ++i)
        {
+               if(i->second->is_temporary())
+                       continue;
+
                /* We must copy the turnout map, since adding tracks to the route will
                (temporarily) mess it up */
                const map<unsigned, int> turnouts = i->second->get_turnouts();
@@ -322,6 +330,8 @@ void Layout::check_routes()
                while(1)
                {
                        // Traverse the track and get the next one
+                       if(track->get_type().get_endpoints().size()<2)
+                               break;
                        unsigned out_ep = track->traverse(ep, trk_path);
                        Track *next = track->get_links()[out_ep];
                        if(!next || next == start)
@@ -362,7 +372,7 @@ void Layout::sensor_event(unsigned addr, bool state)
                        if((*i)->get_sensor_id()==addr)
                        {
                                if(!(*i)->get_train())
-                                       emergency("Unreserved sensor triggered");
+                                       emergency(format("Unreserved sensor %d triggered", addr));
                                break;
                        }
        }
@@ -404,7 +414,7 @@ void Layout::Loader::track(unsigned art_nr)
 
 void Layout::Loader::train(unsigned art_nr, unsigned addr)
 {
-       Train *trn = new Train(obj, obj.catalogue.get_locomotive(art_nr), addr);
+       Train *trn = new Train(obj, obj.catalogue.get_vehicle(art_nr), addr);
        load_sub(*trn);
 }