From: Mikko Rasa Date: Fri, 6 Feb 2015 14:26:10 +0000 (+0200) Subject: Further improve lead route generation X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=443cb39c7ca3b4e56eb561aa054fa48dd3cbc7d8;p=r2c2.git Further improve lead route generation The previous version generated nonsense if the first actual route was completely covered by existing critical blocks. --- diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index 38027db..266bc6f 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -420,7 +420,21 @@ bool TrainRouter::create_lead_route() 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) @@ -429,26 +443,23 @@ bool TrainRouter::create_lead_route() 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;