X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrainrouter.cpp;h=266bc6fc3641f4e6a72c069771132cb734f0546b;hb=443cb39c7ca3b4e56eb561aa054fa48dd3cbc7d8;hp=cef98eebbe46c3a5793579b168d970e4e6734957;hpb=e0508185b2b7d22ab955ba3baa641246b21aac5c;p=r2c2.git diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index cef98ee..266bc6f 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -77,6 +77,7 @@ void TrainRouter::route_changed() can't rely on the resync code in block_reserved since we may need to clear the stop marker to continue allocation. */ TrackIter track = train.get_block_allocator().first().track_iter(); + list::iterator seq_begin = sequence_points.begin(); for(; track; track=track.next()) { if(!advance_to_track(reserving_route, track)) @@ -86,7 +87,15 @@ void TrainRouter::route_changed() } if(&track->get_block()==fncb.block()) break; + + if(seq_begin!=sequence_points.end() && seq_begin->block==&track->get_block()) + { + current_sequence = seq_begin->sequence_out; + ++seq_begin; + } } + + sequence_points.erase(sequence_points.begin(), seq_begin); } if(!already_at_end) @@ -411,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) @@ -420,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;