return true;
}
-bool TrainRouter::is_valid_for_track(const Route &route, const TrackIter &track) const
-{
- if(!route.has_track(*track))
- return false;
- if(track->get_type().is_turnout() && route.get_turnout(track->get_turnout_address())<0 && route.has_track(*track.flip()))
- return false;
- return true;
-}
-
bool TrainRouter::advance_to_track(RouteList::iterator &route, const TrackIter &track)
{
- if(!is_valid_for_track(**route, track))
+ Track &prev_track = *track.flip();
+ unsigned taddr = (track->get_type().is_turnout() ? track->get_turnout_address() : 0);
+ for(unsigned i=0; route!=routes.end(); ++i)
{
- ++route;
- if(route==routes.end())
- return false;
- if(!is_valid_for_track(**route, track))
+ bool in_route = (*route)->has_track(*track);
+ bool prev_in_route = (*route)->has_track(prev_track);
+ bool known_path = (!taddr || (*route)->get_turnout(taddr)>=0);
+
+ if(in_route && (known_path || !prev_in_route))
+ return true;
+ else if(i==0 || prev_in_route)
+ ++route;
+ else
throw logic_error("internal error (routes are not continuous)");
}
- return true;
+ return false;
}
void TrainRouter::get_routers(Layout &layout, vector<TrainRouter *> &routers)
void create_metrics();
bool create_lead_route();
- bool is_valid_for_track(const Route &, const TrackIter &) const;
bool advance_to_track(RouteList::iterator &, const TrackIter &);
static void get_routers(Layout &, std::vector<TrainRouter *> &);