]> git.tdb.fi Git - r2c2.git/commitdiff
Avoid negative values of wait_time
authorMikko Rasa <tdb@tdb.fi>
Tue, 24 Mar 2015 10:07:47 +0000 (12:07 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 24 Mar 2015 17:24:22 +0000 (19:24 +0200)
source/libr2c2/trainrouteplanner.cpp

index 43c61282edaca406241d338a2260d532f31bd14e..476d102617ff1045658d80391f73cf1f4ccedfee 100644 (file)
@@ -493,15 +493,16 @@ void TrainRoutePlanner::TrainRoutingState::advance(const Time::TimeDelta &dt)
        if(estimated_wait)
                estimated_wait = max(estimated_wait-secs*Time::sec, Time::zero);
 
-       if(state==MOVING)
+       float distance = info->speed*secs;
+       float remaining_on_track = occupied_tracks->path_length-offset;
+       if(state==MOVING || distance<remaining_on_track)
                advance(info->speed*secs);
        else if(state!=ARRIVED)
        {
-               float remaining_distance = occupied_tracks->path_length-offset;
-               if(remaining_distance>0)
+               if(remaining_on_track>0)
                {
-                       advance(remaining_distance);
-                       wait_time += (secs-remaining_distance/info->speed)*Time::sec;
+                       advance(remaining_on_track);
+                       wait_time += (secs-remaining_on_track/info->speed)*Time::sec;
                }
                else
                        wait_time += secs*Time::sec;