From 524cce124fd8857483c28571c65f0a446d7be865 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 29 Mar 2014 18:16:51 +0200 Subject: [PATCH] Filter out non-viable routing steps before adding them to the list --- source/libr2c2/trainrouteplanner.cpp | 15 +++++++++++++-- source/libr2c2/trainrouteplanner.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 1c7d996..c5519e4 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -146,7 +146,8 @@ void TrainRoutePlanner::add_steps(RoutingStep &step, unsigned train_index) if(next_entry_ep.has_path(i)) { next.trains[train_index].path = i; - new_steps.push_back(next); + if(next.is_viable()) + new_steps.push_back(next); } if(next_entry_ep.paths!=next_track->get_type().get_paths()) @@ -154,7 +155,8 @@ void TrainRoutePlanner::add_steps(RoutingStep &step, unsigned train_index) RoutingStep wait(&step); wait.advance(dt); wait.trains[train_index].state = WAITING; - new_steps.push_back(wait); + if(wait.is_viable()) + new_steps.push_back(wait); } } @@ -360,6 +362,15 @@ void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt) } } +bool TrainRoutePlanner::RoutingStep::is_viable() const +{ + for(vector::const_iterator i=trains.begin(); i!=trains.end(); ++i) + if(i->state==MOVING) + return true; + + return false; +} + bool TrainRoutePlanner::RoutingStep::is_goal() const { for(vector::const_iterator i=trains.begin(); i!=trains.end(); ++i) diff --git a/source/libr2c2/trainrouteplanner.h b/source/libr2c2/trainrouteplanner.h index 2ae7dc4..b241150 100644 --- a/source/libr2c2/trainrouteplanner.h +++ b/source/libr2c2/trainrouteplanner.h @@ -83,6 +83,7 @@ private: RoutingStep(RoutingStep *); void advance(const Msp::Time::TimeDelta &); + bool is_viable() const; bool is_goal() const; bool operator<(const RoutingStep &) const; -- 2.43.0