X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fblock.cpp;h=a29469c4fd9b97e32751987e3c42ac6f903b078e;hb=02c9a9779954d993cb73fe5f7a72b0847e87f633;hp=d4a6878a68b1b6ba475b85fd17014fe490b6cceb;hpb=f42183985c65e1e12f19e9246dee90b8e7e44a34;p=r2c2.git diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index d4a6878..a29469c 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -5,6 +5,7 @@ Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ +#include #include "control.h" #include "block.h" #include "tracktype.h" @@ -16,11 +17,9 @@ using namespace Msp; namespace Marklin { -unsigned Block::next_id = 1; - Block::Block(TrafficManager &tm, Track &start): trfc_mgr(tm), - id(next_id++), + id(0), sensor_id(start.get_sensor_id()), turnout_id(start.get_turnout_id()), train(0) @@ -49,6 +48,11 @@ Block::Block(TrafficManager &tm, Track &start): } } + if(sensor_id) + id = 0x1000|sensor_id; + else if(turnout_id) + id = 0x2000|turnout_id; + for(unsigned i=0; ilink = this; } } + + if(!sensor_id && !turnout_id && endpoints.size()==2) + { + unsigned id1 = endpoints[0].link ? endpoints[0].link->get_id() : 1; + unsigned id2 = endpoints[1].link ? endpoints[1].link->get_id() : 1; + if(id2