]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/block.cpp
Add state loading and saving to engineer
[r2c2.git] / source / libmarklin / block.cpp
index a304a152d6959717e02badca31da10ef6f3cc65e..94be126c77d088c1b44ba63303a99253a0338957 100644 (file)
@@ -1,20 +1,19 @@
 /* $Id$
 
 This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
+#include <iostream>
 #include "control.h"
 #include "block.h"
 #include "tracktype.h"
 #include "trafficmanager.h"
 #include "turnout.h"
 
-using namespace Msp;
-
-#include <iostream>
 using namespace std;
+using namespace Msp;
 
 namespace Marklin {
 
@@ -38,7 +37,7 @@ Block::Block(TrafficManager &tm, Track &start):
                for(unsigned i=0; i<links.size(); ++i)
                        if(links[i] && !tracks.count(links[i]))
                        {
-                               if(links[i]->get_sensor_id()==sensor_id)
+                               if(links[i]->get_sensor_id()==sensor_id && !links[i]->get_turnout_id() && !track->get_turnout_id())
                                {
                                        queue.push_back(links[i]);
                                        tracks.insert(links[i]);
@@ -100,11 +99,10 @@ int Block::traverse(unsigned epi, float *len) const
                                return i;
 
                Track *next=track->get_link(other_ep);
+               if(tracks.count(next)==0)
+                       return -1;
                track_ep=next->get_endpoint_by_link(*track);
                track=next;
-
-               if(tracks.count(track)==0)
-                       return -1;
        }
 }
 
@@ -136,10 +134,6 @@ bool Block::reserve(const Train *t)
        if(!t || !train)
        {
                train=t;
-               if(train)
-                       cout<<"Block "<<this<<" reserved for train "<<train->get_name()<<'\n';
-               else
-                       cout<<"Block "<<this<<" freed\n";
                trfc_mgr.signal_block_reserved.emit(*this, train);
                return true;
        }