From: Mikko Rasa Date: Mon, 23 Mar 2015 20:49:29 +0000 (+0200) Subject: Fix handling of trains that are becoming blocked X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7bb91be43af2af92cc1cc16035b8fe97f9e14384;p=r2c2.git Fix handling of trains that are becoming blocked --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index b9bbfbc..95b981c 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -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 &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)