From 28947c087bd2d05c1850e320844f2e33fc0fc253 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 23 Mar 2015 23:12:33 +0200 Subject: [PATCH] Tweak the picking of the next train to process If a train just became unblocked, it should be considered for picking immediately. --- source/libr2c2/trainrouteplanner.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 95b981c..c07f9e8 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -569,7 +569,7 @@ void TrainRoutePlanner::RoutingStep::create_successors(list &new_st 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; @@ -726,10 +726,13 @@ int TrainRoutePlanner::RoutingStep::get_occupant(Track &track) const 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; itrains[i].state==MOVING)) { Time::TimeDelta dt = trains[i].get_time_to_next_track(); if(dt