From: Mikko Rasa Date: Tue, 24 Mar 2015 10:07:47 +0000 (+0200) Subject: Avoid negative values of wait_time X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=61dbeed5017acf9d8e7eeb5ecf1df23d6e546afd;p=r2c2.git Avoid negative values of wait_time --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 43c6128..476d102 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -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 || distancespeed*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;