From 19a73af1fb956636cb8b9d563ffb6a42e827a5bf Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 12 Feb 2015 11:33:47 +0200 Subject: [PATCH] Don't allow trains to become blocked in critical blocks --- source/libr2c2/trainrouteplanner.cpp | 15 ++++++++++++++- source/libr2c2/trainrouteplanner.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) 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 -- 2.45.2