float result = 0;
while(t_iter && has_track(*t_iter))
{
- int path = -1;
- if(t_iter->get_turnout_id() && route)
- path = route->get_turnout(t_iter->get_turnout_id());
- if(path==-1)
- path = t_iter->get_active_path();
-
+ unsigned path = (route ? route->get_path(*t_iter) : t_iter->get_active_path());
result += t_iter->get_type().get_path_length(path);
t_iter = t_iter.next(path);
if(!_block->has_track(*t_iter))
throw LogicError("Block traversal strayed out of the block");
- int path = -1;
- if(t_iter->get_turnout_id() && route)
- path = route->get_turnout(t_iter->get_turnout_id());
- if(path==-1)
- path = t_iter->get_active_path();
-
+ unsigned path = (route ? route->get_path(*t_iter) : t_iter->get_active_path());
TrackIter t_exit = t_iter.reverse(path);
for(unsigned i=0; i<eps.size(); ++i)
if(eps[i].track==t_exit.track() && eps[i].track_ep==t_exit.entry())
return i;
- t_iter = t_iter.next(path);
+ t_iter = t_exit.flip();
}
return -1;
return -1;
}
+unsigned Route::get_path(Track &trk) const
+{
+ if(unsigned tid = trk.get_turnout_id())
+ {
+ map<unsigned, int>::const_iterator i = turnouts.find(tid);
+ if(i!=turnouts.end())
+ return i->second;
+ }
+ return trk.get_active_path();
+}
+
void Route::add_track(Track &trk)
{
if(tracks.count(&trk))
void set_turnout(unsigned, unsigned);
void update_turnouts();
int get_turnout(unsigned) const;
+ unsigned get_path(Track &) const;
const std::map<unsigned, int> &get_turnouts() const { return turnouts; }
void add_track(Track &);
void add_tracks(const std::set<Track *> &);
break;
}
- unsigned tid = track->get_turnout_id();
- track = track.next(tid ? route->route->get_turnout(tid) : 0);
+ track = track.next(route->route->get_path(*track));
if(!track || track.looped())
return false;
else if(!diversion->has_track(*track))
throw LogicError("Pathfinder returned a bad route");
- unsigned tid = track->get_turnout_id();
- track = track.next(tid ? diversion->get_turnout(tid) : 0);
+ track = track.next(diversion->get_path(*track));
}
if(route==end)
TrackLoopIter track1 = from;
while(diversion.has_track(*track1))
{
- unsigned tid = track1->get_turnout_id();
- unsigned path = (tid ? diversion.get_turnout(tid) : 0);
+ unsigned path = diversion.get_path(*track1);
diversion_len += track1->get_type().get_path_length(path);
track1 = track1.next(path);
TrackLoopIter track2 = from;
while(1)
{
- unsigned tid = track2->get_turnout_id();
- unsigned path = (tid ? route->route->get_turnout(tid) : 0);
+ unsigned path = route->route->get_path(*track2);
route_len += track2->get_type().get_path_length(path);
bool ok = (track2!=from && diversion.has_track(*track2));