X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrainrouter.cpp;h=3d8b9d4b7b42a3c7ee3c69c84a81407232107107;hb=ecd7af790bd3ab7c7e768f68968379e1feea56a9;hp=d95bdff4bc85c0db6afa45ff55ef3ffe166e0ae0;hpb=19a73af1fb956636cb8b9d563ffb6a42e827a5bf;p=r2c2.git diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index d95bdff..3d8b9d4 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -83,7 +83,7 @@ void TrainRouter::use_planned_route() void TrainRouter::route_changed() { - BlockIter fncb = train.get_first_noncritical_block(); + BlockIter fncb = train.get_last_critical_block().next(); arrival = ON_THE_WAY; reserving_route = routes.begin(); @@ -438,23 +438,24 @@ bool TrainRouter::create_lead_route() if(routes.empty() || !train.is_placed()) return false; - BlockIter fncb = train.get_first_noncritical_block(); - TrackIter next_track = fncb.track_iter(); + BlockIter lcb = train.get_last_critical_block(); + TrackIter last_track_rev = lcb.reverse().track_iter(); unsigned count = 0; - for(TrackIter i=next_track.flip(); (i && i->get_block().get_train()==&train); i=i.next()) + for(TrackIter i=last_track_rev; (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(); + last_track_rev = i; break; } } - if(!routes.front()->has_track(*next_track) && !routes.front()->has_track(*next_track.flip())) + TrackIter next_track = last_track_rev.flip(); + if(!routes.front()->has_track(*last_track_rev) && !routes.front()->has_track(*next_track)) { Route *pf = Route::find(next_track, *routes.front()); if(!pf) @@ -464,7 +465,7 @@ bool TrainRouter::create_lead_route() } Route *lead = 0; - for(TrackIter i=next_track.flip(); (i && i->get_block().get_train()==&train); i=i.next()) + for(TrackIter i=last_track_rev; (i && i->get_block().get_train()==&train); i=i.next()) { if(!lead && !routes.front()->has_track(*i)) {