]> git.tdb.fi Git - r2c2.git/commitdiff
Don't allow trains to become blocked in critical blocks
authorMikko Rasa <tdb@tdb.fi>
Thu, 12 Feb 2015 09:33:47 +0000 (11:33 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 12 Feb 2015 09:33:47 +0000 (11:33 +0200)
source/libr2c2/trainrouteplanner.cpp
source/libr2c2/trainrouteplanner.h

index 653cfda6d9f01fc1288722d8f1c6ca33e47634c6..9bed406f102576c893a6f3b890ad031d36329840 100644 (file)
@@ -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<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
-               if(i->remaining_estimate<0)
+               if(!i->is_viable())
                        return false;
 
        for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
index b76d663ab5f8caea318ec2bf612bc1d4ab9d83c4..9a9978137cfeb58caa9164e66f41ab3b2ee1c5cd 100644 (file)
@@ -94,6 +94,7 @@ private:
                void advance(const Msp::Time::TimeDelta &);
                void advance_track(unsigned);
                void update_estimate();
+               bool is_viable() const;
        };
 
        struct RoutingStep