From 5c3d55f48318bb16865012c13619990004747090 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 5 Feb 2015 16:01:13 +0200 Subject: [PATCH] Allow an undetermined turnout at the beginning of a route If route plans are regenerated when the train's last vehicle is on the sensor following a turnout in a points-facing movement, the first track of the lead route is a turnout with undetermined path. Route_changed would then try to figure out which route the next allocation will occur on and fail at the very beginning because advance_to_track refused to use the undetermined turnout. --- source/libr2c2/trainrouter.cpp | 14 +++++++------- source/libr2c2/trainrouter.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index 13b2970..a1582fd 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -79,7 +79,7 @@ void TrainRouter::route_changed() TrackIter track = train.get_block_allocator().first().track_iter(); for(; track; track=track.next()) { - if(!advance_to_track(reserving_route, *track)) + if(!advance_to_track(reserving_route, track)) { already_at_end = true; break; @@ -307,7 +307,7 @@ void TrainRouter::block_reserved(Block &block, Train *t) track = t->get_block_allocator().first().track_iter(); for(; track; track=track.next()) { - if(!advance_to_track(reserving_route, *track)) + if(!advance_to_track(reserving_route, track)) throw logic_error("internal error (reservation outside of route)"); else if(&track->get_block()==&block) break; @@ -318,7 +318,7 @@ void TrainRouter::block_reserved(Block &block, Train *t) expected to be allocated next. */ for(; track; track=track.next((*reserving_route)->get_path(*track))) { - if(!advance_to_track(reserving_route, *track)) + if(!advance_to_track(reserving_route, track)) { // We've reached the end of the route. Stop here. arrival = RESERVED_TO_END; @@ -444,16 +444,16 @@ bool TrainRouter::create_lead_route() return true; } -bool TrainRouter::is_valid_for_track(const Route &route, Track &track) const +bool TrainRouter::is_valid_for_track(const Route &route, const TrackIter &track) const { - if(!route.has_track(track)) + if(!route.has_track(*track)) return false; - if(track.get_type().is_turnout() && route.get_turnout(track.get_turnout_address())<0) + if(track->get_type().is_turnout() && route.get_turnout(track->get_turnout_address())<0 && route.has_track(*track.flip())) return false; return true; } -bool TrainRouter::advance_to_track(RouteList::iterator &route, Track &track) +bool TrainRouter::advance_to_track(RouteList::iterator &route, const TrackIter &track) { if(!is_valid_for_track(**route, track)) { diff --git a/source/libr2c2/trainrouter.h b/source/libr2c2/trainrouter.h index 7a560a1..3d8b722 100644 --- a/source/libr2c2/trainrouter.h +++ b/source/libr2c2/trainrouter.h @@ -106,8 +106,8 @@ private: void create_metrics(); bool create_lead_route(); - bool is_valid_for_track(const Route &, Track &) const; - bool advance_to_track(RouteList::iterator &, Track &); + bool is_valid_for_track(const Route &, const TrackIter &) const; + bool advance_to_track(RouteList::iterator &, const TrackIter &); static void start_planning(Layout &); }; -- 2.45.2