From 9a7097fed866060efb8738f8b2f17d5c96a6c980 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 1 Apr 2015 00:49:03 +0300 Subject: [PATCH] Handle the case of a train being late Send it on its next trip after a short fixed delay instead of waiting for the next day. --- source/libr2c2/timetable.cpp | 33 ++++++++++++++++++++++++++++----- source/libr2c2/timetable.h | 5 +++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index da01b59..5cd4b64 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -17,7 +17,9 @@ Timetable::Timetable(Train &t): TrainAI(t), current_row(rows.end()), update_pending(false), - sync_to_clock(true) + sync_to_clock(true), + late_arrival(false), + next_depart(rows.end()) { if(!train.get_ai_of_type()) new AIControl(train); @@ -89,6 +91,21 @@ void Timetable::tick(const Time::TimeDelta &dt) { if(update_pending && !train.get_block_allocator().is_active()) update_route(); + + if(next_depart!=rows.end() && next_depart!=current_row && passed_row(*next_depart, dt)) + late_arrival = true; +} + +bool Timetable::passed_row(const Row &row, const Time::TimeDelta &dt) const +{ + const Clock &clock = train.get_layout().get_clock(); + + Time::TimeDelta t = clock.get_current_time(); + if(t &st) const @@ -163,9 +180,15 @@ void Timetable::update_route() { if(i->type==DEPART) { - Time::TimeDelta dt = i->time-clock.get_current_time(); - while(dttime-clock.get_current_time(); + while(dt::iterator next_depart = find_trip(arrive, 0); + next_depart = find_trip(arrive, 0); if(next_depart==rows.end()) next_depart = find_trip(rows.begin(), 0); if(next_depart!=rows.end()) diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h index 7557249..67e5ad4 100644 --- a/source/libr2c2/timetable.h +++ b/source/libr2c2/timetable.h @@ -76,6 +76,8 @@ private: std::list::iterator current_row; bool update_pending; bool sync_to_clock; + bool late_arrival; + std::list::iterator next_depart; public: Timetable(Train &); @@ -89,7 +91,10 @@ public: const Row &get_row(unsigned) const; virtual void tick(const Msp::Time::TimeDelta &); +private: + bool passed_row(const Row &, const Msp::Time::TimeDelta &) const; +public: void save(std::list &) const; private: -- 2.43.0