From fb5bd959109927ea02ead1483a4bb0c5a66784a4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 11 Apr 2014 21:18:09 +0300 Subject: [PATCH] Fix lead route generation 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 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index 508a7b1..5691ac9 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -343,17 +343,21 @@ Route *TrainRouter::create_lead_route(Route *lead, const Route *target) lead->set_temporary(true); } - set 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 &btracks = i->get_tracks(); - for(set::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; } -- 2.43.0