From: Mikko Rasa Date: Thu, 12 Feb 2015 09:33:47 +0000 (+0200) Subject: Don't allow trains to become blocked in critical blocks X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=19a73af1fb956636cb8b9d563ffb6a42e827a5bf;p=r2c2.git Don't allow trains to become blocked in critical blocks --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 653cfda..9bed406 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -448,6 +448,15 @@ void TrainRoutePlanner::TrainRoutingState::update_estimate() remaining_estimate = distance; } +bool TrainRoutePlanner::TrainRoutingState::is_viable() const +{ + if(remaining_estimate<0) + return false; + if(critical && state==BLOCKED) + return false; + return true; +} + TrainRoutePlanner::RoutingStep::RoutingStep(): prev(0) @@ -546,7 +555,11 @@ bool TrainRoutePlanner::RoutingStep::update_states() { i->blocked_by = get_occupant(*next_track); if(i->blocked_by>=0) + { + if(i->info->first_noncritical->has_track(*next_track)) + i->critical = false; i->state = BLOCKED; + } else if(i->state==BLOCKED) i->state = MOVING; } @@ -630,7 +643,7 @@ void TrainRoutePlanner::RoutingStep::update_estimate() bool TrainRoutePlanner::RoutingStep::is_viable() const { for(vector::const_iterator i=trains.begin(); i!=trains.end(); ++i) - if(i->remaining_estimate<0) + if(!i->is_viable()) return false; for(vector::const_iterator i=trains.begin(); i!=trains.end(); ++i) diff --git a/source/libr2c2/trainrouteplanner.h b/source/libr2c2/trainrouteplanner.h index b76d663..9a99781 100644 --- a/source/libr2c2/trainrouteplanner.h +++ b/source/libr2c2/trainrouteplanner.h @@ -94,6 +94,7 @@ private: void advance(const Msp::Time::TimeDelta &); void advance_track(unsigned); void update_estimate(); + bool is_viable() const; }; struct RoutingStep