From: Mikko Rasa Date: Fri, 11 Apr 2014 18:18:09 +0000 (+0300) Subject: Fix lead route generation X-Git-Url: http://git.tdb.fi/?p=r2c2.git;a=commitdiff_plain;h=fb5bd959109927ea02ead1483a4bb0c5a66784a4 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. --- 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; }