]> git.tdb.fi Git - r2c2.git/commitdiff
Tweak the picking of the next train to process
authorMikko Rasa <tdb@tdb.fi>
Mon, 23 Mar 2015 21:12:33 +0000 (23:12 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 23 Mar 2015 22:09:48 +0000 (00:09 +0200)
If a train just became unblocked, it should be considered for picking
immediately.

source/libr2c2/trainrouteplanner.cpp

index 95b981cb2e7965f650034f773361ef2920107aa8..c07f9e8c188aeeb70fef0fe8be1b29dff155eaef 100644 (file)
@@ -569,7 +569,7 @@ void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &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; 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)