]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/trainrouter.cpp
Fix critical block logic
[r2c2.git] / source / libr2c2 / trainrouter.cpp
index d95bdff4bc85c0db6afa45ff55ef3ffe166e0ae0..3d8b9d4b7b42a3c7ee3c69c84a81407232107107 100644 (file)
@@ -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))
                {