]> git.tdb.fi Git - r2c2.git/commitdiff
Avoid creating looping routes
authorMikko Rasa <tdb@tdb.fi>
Sat, 12 Apr 2014 19:45:27 +0000 (22:45 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 12 Apr 2014 19:45:27 +0000 (22:45 +0300)
If th route went past its end, adding the turnout would cause a loop to
be created.  Trying to add the next track would then throw bad_chain.

source/libr2c2/trainrouteplanner.cpp

index 69a3bbea55484de54a9d43b584563481f2a98894..dbdf293c89b03293761b7273adfd13886c218b58 100644 (file)
@@ -85,7 +85,18 @@ void TrainRoutePlanner::create_routes(const RoutingStep &goal)
                                continue;
 
                        Route *route = j->info->routes.front();
-                       if(route->has_track(*j->track))
+                       bool start_new_route = route->has_track(*j->track);
+                       if(!start_new_route)
+                       {
+                               unsigned nls = j->track->get_n_link_slots();
+                               for(unsigned k=0; (!start_new_route && k<nls); ++k)
+                               {
+                                       Track *link = j->track->get_link(k);
+                                       start_new_route = (link && link!=history[0] && route->has_track(*link));
+                               }
+                       }
+
+                       if(start_new_route)
                        {
                                route = new Route(j->info->train->get_layout());
                                route->set_name("Router");