]> git.tdb.fi Git - r2c2.git/commitdiff
Fix lead route generation
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Apr 2014 18:18:09 +0000 (21:18 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Apr 2014 19:35:13 +0000 (22:35 +0300)
Lead routes are now created up to the target, but not past it.  This fixes
a problem where a route diverging from the train's reserved blocks caused
the router to attempt to create a lead route with gaps.

source/libr2c2/trainrouter.cpp

index 508a7b19651a4835206a0c76f1b2d8e9c90eeaaa..5691ac9a30ccdbdcc15e506d3581f2be26cddc31 100644 (file)
@@ -343,17 +343,21 @@ Route *TrainRouter::create_lead_route(Route *lead, const Route *target)
                lead->set_temporary(true);
        }
 
-       set<Track *> tracks;
-       for(BlockIter i=train.get_block_allocator().first(); (i && i->get_train()==&train); i=i.next())
+       bool target_reached = false;
+       for(TrackIter i=train.get_block_allocator().first().track_iter(); i; i=i.next())
        {
-               const set<Track *> &btracks = i->get_tracks();
-               for(set<Track *>::const_iterator j=btracks.begin(); j!=btracks.end(); ++j)
-                       if(!target || !target->has_track(**j))
-                               tracks.insert(*j);
+               if(i->get_block().get_train()!=&train)
+                       break;
+               if(target)
+               {
+                       if(target->has_track(*i))
+                               target_reached = true;
+                       else if(target_reached)
+                               break;
+               }
+               lead->add_track(*i);
        }
 
-       lead->add_tracks(tracks);
-
        return lead;
 }