From 32739f060d1c025756b3ed702da1cbbdd6793064 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 8 Jul 2013 01:05:57 +0300 Subject: [PATCH] Don't reset router to free run mode until allocator has deactivated Setting route causes stop_at information to be cleared. If the allocator is still active when this happens, it will allocate more blocks. --- source/libr2c2/trainrouter.cpp | 12 +++++++----- source/libr2c2/trainrouter.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index 8de191b..100842b 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -14,7 +14,7 @@ namespace R2C2 { TrainRouter::TrainRouter(Train &t): TrainAI(t), priority(0), - arriving(false), + arriving(0), dest_zone(0), dest_block(0), update_pending(false) @@ -55,7 +55,7 @@ bool TrainRouter::set_route(const Route *r) if(r) routes.push_back(r); train.stop_at(0); - arriving = false; + arriving = 0; train.refresh_blocks_from(*fncb); @@ -142,12 +142,14 @@ void TrainRouter::tick(const Time::TimeDelta &) if(update_pending) create_plans(train.get_layout()); - if(arriving && !train.get_speed()) + if(arriving==1 && !train.get_speed()) { signal_arrived.emit(); signal_event.emit(Message("arrived")); - set_route(0); + arriving = 2; } + else if(arriving==2 && !train.get_block_allocator().is_active()) + set_route(0); } void TrainRouter::save(list &st) const @@ -223,7 +225,7 @@ void TrainRouter::train_advanced(Block &block) { b_iter = b_iter.next(); if(b_iter && !is_on_route(*b_iter)) - arriving = true; + arriving = 1; } } diff --git a/source/libr2c2/trainrouter.h b/source/libr2c2/trainrouter.h index 9938533..b36a013 100644 --- a/source/libr2c2/trainrouter.h +++ b/source/libr2c2/trainrouter.h @@ -40,7 +40,7 @@ private: int priority; RouteList routes; - bool arriving; + unsigned arriving; const Zone *dest_zone; const Block *dest_block; std::list waits; -- 2.43.0