]> git.tdb.fi Git - r2c2.git/commitdiff
Fix handling of trains that are becoming blocked
authorMikko Rasa <tdb@tdb.fi>
Mon, 23 Mar 2015 20:49:29 +0000 (22:49 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 23 Mar 2015 22:05:34 +0000 (00:05 +0200)
source/libr2c2/trainrouteplanner.cpp

index b9bbfbcf1760c494d39c62464a1fdb4a5271333b..95b981cb2e7965f650034f773361ef2920107aa8 100644 (file)
@@ -479,7 +479,7 @@ void TrainRoutePlanner::TrainRoutingState::advance(const Time::TimeDelta &dt)
        }
 
        float secs = dt/Time::sec;
-       // There may be negative delay remaining after previous step.
+       // There may be some delay remaining.
        if(delay)
        {
                secs -= delay/Time::sec;
@@ -495,7 +495,16 @@ void TrainRoutePlanner::TrainRoutingState::advance(const Time::TimeDelta &dt)
        if(state==MOVING)
                advance(info->speed*secs);
        else if(state!=ARRIVED)
-               wait_time += secs*Time::sec;
+       {
+               float remaining_distance = occupied_tracks->path_length-offset;
+               if(remaining_distance>0)
+               {
+                       advance(remaining_distance);
+                       wait_time += (secs-remaining_distance/info->speed)*Time::sec;
+               }
+               else
+                       wait_time += secs*Time::sec;
+       }
 }
 
 void TrainRoutePlanner::TrainRoutingState::advance_track(unsigned next_path)
@@ -577,7 +586,13 @@ void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &new_st
                return;
        }
 
-       train.advance_track(0);
+       if(train.state==MOVING)
+               train.advance_track(0);
+       else
+       {
+               new_steps.push_back(next);
+               return;
+       }
 
        const TrackType::Endpoint &entry_ep = train.track.endpoint();
        if(train.critical)