]> git.tdb.fi Git - r2c2.git/commitdiff
Don't diverge from critical blocks
authorMikko Rasa <tdb@tdb.fi>
Thu, 5 Feb 2015 18:02:20 +0000 (20:02 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 6 Feb 2015 14:47:51 +0000 (16:47 +0200)
Doing so could confuse the router.

source/libr2c2/trainrouteplanner.cpp
source/libr2c2/trainrouteplanner.h

index 9e74eca1c7b1b2c0c18846d586cf86a774c363a1..a05e97ea7fb2fed688651a3b6b81c104d3d5d19c 100644 (file)
@@ -214,6 +214,7 @@ void TrainRoutePlanner::finalize_plan()
 TrainRoutePlanner::TrainRoutingInfo::TrainRoutingInfo(Train &t):
        train(&t),
        speed(train->get_maximum_speed()),
+       first_noncritical(train->get_first_noncritical_block().block()),
        router(train->get_ai_of_type<TrainRouter>()),
        destination(0),
        has_duration(false)
@@ -272,6 +273,7 @@ TrainRoutePlanner::OccupiedTrack::~OccupiedTrack()
 
 TrainRoutePlanner::TrainRoutingState::TrainRoutingState(TrainRoutingInfo &inf):
        info(&inf),
+       critical(true),
        occupied_tracks(0),
        state(MOVING),
        delay(info->router->get_departure_delay()),
@@ -307,6 +309,7 @@ TrainRoutePlanner::TrainRoutingState::TrainRoutingState(const TrainRoutingState
        info(other.info),
        track(other.track),
        path(other.path),
+       critical(other.critical),
        occupied_tracks(other.occupied_tracks),
        offset(other.offset),
        back_offset(other.back_offset),
@@ -361,6 +364,9 @@ bool TrainRoutePlanner::TrainRoutingState::check_arrival()
                        waypoint = -1;
        }
 
+       if(info->first_noncritical->has_track(*track))
+               critical = false;
+
        return false;
 }
 
@@ -475,15 +481,26 @@ void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &new_st
        train.advance_track(0);
 
        const TrackType::Endpoint &next_entry_ep = next_track.endpoint();
-       for(unsigned i=0; next_entry_ep.paths>>i; ++i)
-               if(next_entry_ep.has_path(i))
-               {
-                       train.path = i;
-                       train.update_estimate();
-                       next.update_estimate();
-                       if(next.is_viable())
-                               new_steps.push_back(next);
-               }
+       if(train.critical)
+       {
+               train.path = train.track->get_type().coerce_path(train.track.entry(), train.track->get_active_path());
+               train.update_estimate();
+               next.update_estimate();
+               if(next.is_viable())
+                       new_steps.push_back(next);
+       }
+       else
+       {
+               for(unsigned i=0; next_entry_ep.paths>>i; ++i)
+                       if(next_entry_ep.has_path(i))
+                       {
+                               train.path = i;
+                               train.update_estimate();
+                               next.update_estimate();
+                               if(next.is_viable())
+                                       new_steps.push_back(next);
+                       }
+       }
 
        new_steps.sort();
        for(list<RoutingStep>::iterator i=new_steps.begin(); ++i!=new_steps.end(); )
@@ -492,7 +509,7 @@ void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &new_st
                i->update_estimate();
        }
 
-       if(next_entry_ep.paths!=next_track->get_type().get_paths())
+       if(next_entry_ep.paths!=next_track->get_type().get_paths() && !train.critical)
        {
                RoutingStep wait(this);
                wait.advance(dt);
index 85a748c204099bd4e5cff2947ce5962a687528a1..0ed2e118e7bb4e5ef503769f7ef3c765848752e2 100644 (file)
@@ -32,6 +32,7 @@ private:
        {
                Train *train;
                float speed;
+               Block *first_noncritical;
                TrainRouter *router;
                const TrackChain *destination;
                std::vector<const TrackChain *> waypoints;
@@ -69,7 +70,8 @@ private:
        {
                TrainRoutingInfo *info;
                TrackIter track;
-               unsigned path;
+               unsigned char path;
+               bool critical;
                OccupiedTrack *occupied_tracks;
                float offset;
                float back_offset;