- RouteList::iterator next_route = route;
- if(!advance_route(next_route, *b_iter_next))
+ // Is the block a turnout? If it is, set it to the correct path.
+ if(unsigned taddr = block.get_turnout_address())
+ {
+ int path = (*reserving_route)->get_turnout(taddr);
+ if(path>=0)
+ track->set_active_path(path);
+ }
+
+ /* If the allocator has released blocks from the front, we may need to
+ resync reserving_route. */
+ if(reserving_route==routes.end() || !(*reserving_route)->has_track(*track))
+ {
+ reserving_route = routes.begin();
+ arrival = ON_THE_WAY;
+ track = t->get_block_allocator().first().track_iter();
+ for(; track; track=track.next())
+ {
+ if(!advance_to_track(reserving_route, track))
+ throw logic_error("internal error (reservation outside of route)");
+ else if(&track->get_block()==&block)
+ break;
+ }
+ }
+
+ /* Keep reserving_route pointing to the route containing the block that is
+ expected to be allocated next. */
+ for(; track; track=track.next((*reserving_route)->get_path(*track)))
+ {
+ if(!advance_to_track(reserving_route, track))