Distributed under the GPL
*/
+#include <algorithm>
#include "control.h"
#include "block.h"
#include "tracktype.h"
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)
}
}
+ if(sensor_id)
+ id = 0x1000|sensor_id;
+ else if(turnout_id)
+ id = 0x2000|turnout_id;
+
for(unsigned i=0; i<endpoints.size(); ++i)
{
unsigned path = 1<<i;
j->link = 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<id1)
+ swap(id1, id2);
+ id = (id1<<16)|id2;
+ }
}
Block *Block::get_link(unsigned epi) const