+void Train::check_turnout_paths(bool set)
+{
+ if(clear_blocks_end==blocks.end())
+ return;
+
+ list<RouteRef>::iterator route = routes.begin();
+
+ for(list<BlockIter>::iterator i=clear_blocks_end; i!=blocks.end(); ++i)
+ {
+ advance_route(route, *i->track_iter());
+
+ if((*i)->get_turnout_id())
+ {
+ TrackIter track = i->track_iter();
+ const TrackType::Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()];
+
+ int path = -1;
+ for(list<RouteRef>::iterator j=route; (path<0 && j!=routes.end()); ++j)
+ path = j->route->get_turnout((*i)->get_turnout_id());
+ if(path<0)
+ path = track->get_active_path();
+ if(!(track_ep.paths&(1<<path)))
+ {
+ list<BlockIter>::iterator j = i;
+ if(++j!=blocks.end())
+ {
+ TrackIter rev = j->track_iter().flip();
+ unsigned mask = rev->get_type().get_endpoints()[rev.entry()].paths&track_ep.paths;
+ for(path=0; mask>1; mask>>=1, ++path) ;
+ }
+ else
+ return;
+ }
+
+ if(path!=static_cast<int>(track->get_active_path()))
+ {
+ if(set)
+ track->set_active_path(path);
+
+ continue;
+ }
+ }
+
+ if(i==clear_blocks_end)
+ ++clear_blocks_end;
+ }
+}
+