if(next.update_states() && next.check_deadlocks())
return;
- int train_index = find_next_train();
+ int train_index = next.find_next_train();
if(train_index<0)
return;
int TrainRoutePlanner::RoutingStep::find_next_train() const
{
+ /* Pick a moving train with the lowest time to next track. A train that
+ just became blocked can still travel until the end of its current track,
+ so consider those too. */
Time::TimeDelta min_dt;
int next_train = -1;
for(unsigned i=0; i<trains.size(); ++i)
- if(trains[i].state==MOVING)
+ if(trains[i].state==MOVING || (trains[i].state==BLOCKED && prev && prev->trains[i].state==MOVING))
{
Time::TimeDelta dt = trains[i].get_time_to_next_track();
if(dt<min_dt || next_train<0)