]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/trainrouteplanner.cpp
Filter out non-viable routing steps before adding them to the list
[r2c2.git] / source / libr2c2 / trainrouteplanner.cpp
index 809bb3e5c665967a9a6d6d890d7eb58f582c6e15..c5519e45d7db1c581932b7a48e4efe8d5aba8181 100644 (file)
@@ -56,6 +56,9 @@ bool TrainRoutePlanner::update_states(RoutingStep &step)
        bool changes = false;
        for(vector<TrainRoutingState>::iterator i=next.trains.begin(); i!=next.trains.end(); ++i)
        {
+               if(i->state==ARRIVED)
+                       continue;
+
                TrainState old_state = i->state;
                if(i->state==BLOCKED)
                        i->state = MOVING;
@@ -143,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())
@@ -151,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);
                }
        }
 
@@ -357,6 +362,15 @@ void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt)
        }
 }
 
+bool TrainRoutePlanner::RoutingStep::is_viable() const
+{
+       for(vector<TrainRoutingState>::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<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)