+ Track &track = *train.get_block_allocator().iter_for(block).endpoint().track;
+
+ // Drop any routes that are now completely behind the train.
+ for(RouteList::iterator i=routes.begin(); i!=routes.end(); ++i)
+ if((*i)->has_track(track))
+ {
+ if(i!=routes.begin())
+ {
+ routes.erase(routes.begin(), i);
+ const Route *route = get_route();
+ signal_route_changed.emit(route);
+ signal_event.emit(Message("route-changed", route));
+ }
+ break;
+ }
+}
+
+void TrainRouter::create_metrics()
+{
+ for(vector<TrainRouteMetric *>::iterator i=metrics.begin(); i!=metrics.end(); ++i)
+ delete *i;
+ metrics.clear();
+
+ metrics_stale = false;
+
+ if(waypoints.empty())
+ return;
+
+ for(vector<Waypoint>::const_iterator i=waypoints.begin(); i!=waypoints.end(); ++i)
+ metrics.push_back(new TrainRouteMetric(*i->chain, i->direction));
+
+ for(unsigned i=metrics.size()-1; i-->0; )
+ metrics[i]->chain_to(*metrics[i+1]);
+}
+
+bool TrainRouter::create_lead_route()
+{
+ if(routes.empty() || !train.is_placed())
+ return false;
+
+ BlockIter lcb = train.get_last_critical_block();
+ TrackIter last_track_rev = lcb.reverse().track_iter();
+
+ unsigned count = 0;
+ for(TrackIter i=last_track_rev; (i && i->get_block().get_train()==&train); i=i.next())