]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/block.cpp
Set correct Z coordinate to vehicle position
[r2c2.git] / source / libmarklin / block.cpp
index 51f8ddb0dfe45dbd954f994ba75b1c82f759e290..db1942bb5b613fde7ff1b71272383455740bc875 100644 (file)
@@ -8,6 +8,7 @@ Distributed under the GPL
 #include <algorithm>
 #include "block.h"
 #include "layout.h"
+#include "route.h"
 #include "tracktype.h"
 
 using namespace std;
@@ -81,6 +82,11 @@ int Block::get_endpoint_by_link(const Block &other) const
 }
 
 unsigned Block::traverse(unsigned epi, float *len) const
+{
+       return traverse(epi, 0, len);
+}
+
+unsigned Block::traverse(unsigned epi, const Route *route, float *len) const
 {
        if(epi>=endpoints.size())
                throw InvalidParameterValue("Endpoint index out of range");
@@ -94,7 +100,11 @@ unsigned Block::traverse(unsigned epi, float *len) const
 
        while(1)
        {
-               unsigned cur_path = track->get_active_path();
+               int cur_path = -1;
+               if(track->get_turnout_id() && route)
+                       cur_path = route->get_turnout(track->get_turnout_id());
+               if(cur_path==-1)
+                       cur_path = track->get_active_path();
 
                if(len)
                        *len += track->get_type().get_path_length(cur_path);
@@ -199,6 +209,11 @@ void Block::determine_id()
                        swap(id1, id2);
                id = (id1<<16)|id2;
        }
+       else if(endpoints.size()==1)
+       {
+               unsigned id1 = endpoints[0].link ? endpoints[0].link->get_id() : 1;
+               id = 0x10000 | id1;
+       }
 }