{
for(vector<TrainRoutingInfo>::iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i)
{
- i->route = new Route(i->train->get_layout());
- i->route->set_name("Router");
- i->route->set_temporary(true);
+ Route *route = new Route(i->train->get_layout());
+ route->set_name("Router");
+ route->set_temporary(true);
+ i->routes.push_front(route);
+
+ for(unsigned j=0; j<3; ++j)
+ i->track_history[j] = 0;
}
for(const RoutingStep *i=&goal; i; i=i->prev)
{
for(vector<TrainRoutingState>::const_iterator j=i->trains.begin(); j!=i->trains.end(); ++j)
{
+ Track **history = j->info->track_history;
+ if(j->track.track()==history[0])
+ continue;
+
if(j->state==WAITING || j->state==BLOCKED)
j->info->waits.push_front(&*j);
- j->info->route->add_track(*j->track);
+
+ Route *route = j->info->routes.front();
+ if(route->has_track(*j->track))
+ {
+ route = new Route(j->info->train->get_layout());
+ route->set_name("Router");
+ route->set_temporary(true);
+ for(unsigned k=2; k>0; --k)
+ route->add_track(*history[k]);
+ j->info->routes.push_front(route);
+ }
+
+ if(history[0])
+ route->add_track(*history[0]);
+ for(unsigned k=2; k>0; --k)
+ history[k] = history[k-1];
+ history[0] = j->track.track();
}
}
for(vector<TrainRoutingInfo>::iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i)
{
- i->router->set_route(i->route);
+ for(list<Route *>::iterator j=i->routes.begin(); j!=i->routes.end(); ++j)
+ i->router->add_route(**j);
const TrainRoutingState *current_wait = 0;
for(list<const TrainRoutingState *>::const_iterator j=i->waits.begin(); j!=i->waits.end(); ++j)
if(!current_wait || (*j)->track.track()!=current_wait->track.track())
TrainRoutePlanner::TrainRoutingInfo::TrainRoutingInfo(Train &t):
train(&t),
speed(train->get_maximum_speed()),
- router(train->get_ai_of_type<TrainRouter>()),
- route(0)
+ router(train->get_ai_of_type<TrainRouter>())
{
// If no maximum speed is specified, use a sensible default
if(!speed)