From d284c154438ffec9f0feb6b8dc4d9aa77ae13e24 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 15 Apr 2014 22:20:10 +0300 Subject: [PATCH] Tinker with arrival logic --- source/libr2c2/trainrouter.cpp | 18 +++++++----------- source/libr2c2/trainrouter.h | 9 ++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index c551050..959eba2 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -15,7 +15,7 @@ namespace R2C2 { TrainRouter::TrainRouter(Train &t): TrainAI(t), priority(0), - arriving(0), + arrival(ON_THE_WAY), destination(0), destination_changed(false), metrics_stale(false), @@ -105,6 +105,7 @@ void TrainRouter::route_changed() if(!already_at_end) { + arrival = ON_THE_WAY; train.stop_at(0); train.refresh_blocks_from(*fncb); } @@ -233,13 +234,13 @@ void TrainRouter::tick(const Time::TimeDelta &dt) sequence_check_pending = false; } - if(arriving==1 && !train.get_speed()) + if(arrival==RESERVED_TO_END && !train.get_speed()) { signal_arrived.emit(destination); signal_event.emit(Message("arrived", destination)); - arriving = 2; + arrival = ARRIVED; } - else if(arriving==2 && !train.get_block_allocator().is_active()) + else if(arrival==ARRIVED && !train.get_block_allocator().is_active()) set_route(0); } @@ -301,6 +302,7 @@ void TrainRouter::block_reserved(Block &block, Train *t) if(reserving_route==routes.end() || !(*reserving_route)->has_track(*track)) { reserving_route = routes.begin(); + arrival = ON_THE_WAY; track = t->get_block_allocator().first().track_iter(); for(; track; track=track.next()) { @@ -316,6 +318,7 @@ void TrainRouter::block_reserved(Block &block, Train *t) { if(!advance_to_track(reserving_route, *track)) { + arrival = RESERVED_TO_END; train.stop_at(&block); return; } @@ -376,13 +379,6 @@ void TrainRouter::train_advanced(Block &block) } } } - - if(!routes.empty()) - { - b_iter = b_iter.next(); - if(b_iter && !is_on_route(*b_iter)) - arriving = 1; - } } void TrainRouter::create_metrics() diff --git a/source/libr2c2/trainrouter.h b/source/libr2c2/trainrouter.h index 27307e7..589c729 100644 --- a/source/libr2c2/trainrouter.h +++ b/source/libr2c2/trainrouter.h @@ -40,6 +40,13 @@ public: private: typedef std::list RouteList; + enum ArrivalState + { + ON_THE_WAY, + RESERVED_TO_END, + ARRIVED + }; + public: sigc::signal signal_route_changed; sigc::signal signal_arrived; @@ -49,7 +56,7 @@ private: int priority; RouteList routes; RouteList::iterator reserving_route; - unsigned arriving; + ArrivalState arrival; const TrackChain *destination; std::vector waypoints; bool destination_changed; -- 2.45.2