BlockIter fncb = train.get_first_noncritical_block();
TrackIter next_track = fncb.track_iter();
- if(!routes.front()->has_track(*next_track.flip()))
+
+ unsigned count = 0;
+ for(TrackIter i=next_track.flip(); (i && i->get_block().get_train()==&train); i=i.next())
+ {
+ if(routes.front()->has_track(*i))
+ ++count;
+ else if(count>0)
+ {
+ if(count==routes.front()->get_tracks().size())
+ next_track = i.flip();
+ break;
+ }
+ }
+
+ if(!routes.front()->has_track(*next_track) && !routes.front()->has_track(*next_track.flip()))
{
Route *pf = Route::find(next_track, *routes.front());
if(!pf)
routes.push_front(pf);
}
- TrackIter first_track = train.get_block_allocator().first().track_iter();
- if(!routes.front()->has_track(*first_track))
+ Route *lead = 0;
+ for(TrackIter i=next_track.flip(); (i && i->get_block().get_train()==&train); i=i.next())
{
- Route *lead = new Route(train.get_layout());
- lead->set_name("Lead");
- lead->set_temporary(true);
-
- unsigned target_tracks = 0;
- for(TrackIter i=first_track; (target_tracks<2 && i); i=i.next())
+ if(!lead && !routes.front()->has_track(*i))
{
- if(i->get_block().get_train()!=&train)
- break;
- if(routes.front()->has_track(*i))
- ++target_tracks;
- else if(target_tracks>0)
- break;
- lead->add_track(*i);
+ lead = new Route(train.get_layout());
+ lead->set_name("Lead");
+ lead->set_temporary(true);
+ routes.push_front(lead);
+
+ TrackIter j = i.flip();
+ lead->add_track(*j);
+ lead->add_track(*j.next());
}
- routes.push_front(lead);
+ if(lead)
+ lead->add_track(*i);
}
return true;