From: Mikko Rasa Date: Sun, 23 Mar 2014 16:48:47 +0000 (+0200) Subject: Use the TrackChain base class as destination in Router X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a7b4305930090851623da7e02e21650510ce7dae;p=r2c2.git Use the TrackChain base class as destination in Router There's no functional difference between Zones and blocks in this context. Giving a Route as a destination does not really make sense and may give unexpected results, but I see no particular reason to exclude them. --- diff --git a/source/engineer/routerpanel.cpp b/source/engineer/routerpanel.cpp index 1935bbe..d0fea39 100644 --- a/source/engineer/routerpanel.cpp +++ b/source/engineer/routerpanel.cpp @@ -95,7 +95,7 @@ void RouterPanel::button_press(int x, int y, unsigned btn) goto_highlight = 0; if(goto_target && btn==1) - train.ai_message(TrainAI::Message("set-destination-block", goto_target)); + train.ai_message(TrainAI::Message("set-destination", goto_target)); } } diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index f0e49ff..631f58a 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -150,7 +150,7 @@ void Timetable::update_route() { if(i->type==ARRIVE) { - train.ai_message(Message("set-destination-zone", i->zone)); + train.ai_message(Message("set-destination", i->target)); break; } else if(i->type==DEPART) diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 99731c6..a7bb13e 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -16,7 +16,7 @@ TrainRoutePlanner::TrainRoutePlanner(Layout &layout) for(map::const_iterator i=trains.begin(); i!=trains.end(); ++i) { TrainRoutingInfo info(*i->second); - if(info.router && info.router->has_destination()) + if(info.router && info.router->get_destination()) routed_trains.push_back(info); } diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index 65a4a24..b2993ee 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -2,9 +2,9 @@ #include "route.h" #include "trackiter.h" #include "train.h" +#include "trackchain.h" #include "trainrouteplanner.h" #include "trainrouter.h" -#include "zone.h" using namespace std; using namespace Msp; @@ -15,8 +15,7 @@ TrainRouter::TrainRouter(Train &t): TrainAI(t), priority(0), arriving(0), - dest_zone(0), - dest_block(0), + destination(0), update_pending(false) { train.get_layout().signal_block_reserved.connect(sigc::mem_fun(this, &TrainRouter::block_reserved)); @@ -61,8 +60,7 @@ bool TrainRouter::set_route(const Route *r) route, but not when the planner calls this. */ if(!r) { - dest_zone = 0; - dest_block = 0; + destination = 0; } train.refresh_blocks_from(*fncb); @@ -89,31 +87,16 @@ const Route *TrainRouter::get_route() const return routes.front(); } -void TrainRouter::set_destination(const Zone &zone) +void TrainRouter::set_destination(const TrackChain &d) { - dest_zone = &zone; - dest_block = 0; + destination = &d; update_pending = true; } -void TrainRouter::set_destination(const Block &block) -{ - dest_zone = 0; - dest_block = █ - update_pending = true; -} - -bool TrainRouter::has_destination() const -{ - return dest_zone || dest_block; -} - bool TrainRouter::is_destination(Track &track) const { - if(dest_zone) - return dest_zone->has_track(track); - else if(dest_block) - return dest_block->has_track(track); + if(destination) + return destination->has_track(track); else return false; } @@ -135,19 +118,12 @@ void TrainRouter::message(const Message &msg) } else if(msg.type=="clear-route") set_route(0); - else if(msg.type=="set-destination-block") - { - if(msg.value.check_type()) - set_destination(*msg.value.value()); - else - set_destination(*msg.value.value()); - } - else if(msg.type=="set-destination-zone") + else if(msg.type=="set-destination") { - if(msg.value.check_type()) - set_destination(*msg.value.value()); + if(msg.value.check_type()) + set_destination(*msg.value.value()); else - set_destination(*msg.value.value()); + set_destination(*msg.value.value()); } else if(msg.type=="set-departure-delay") set_departure_delay(msg.value.value()); diff --git a/source/libr2c2/trainrouter.h b/source/libr2c2/trainrouter.h index 28862a2..c518522 100644 --- a/source/libr2c2/trainrouter.h +++ b/source/libr2c2/trainrouter.h @@ -9,9 +9,8 @@ namespace R2C2 { class Block; class Layout; -class Route; class Track; -class Zone; +class TrackChain; class TrainRouter: public TrainAI { @@ -41,8 +40,7 @@ private: int priority; RouteList routes; unsigned arriving; - const Zone *dest_zone; - const Block *dest_block; + const TrackChain *destination; std::list waits; Msp::Time::TimeDelta delay; @@ -58,9 +56,8 @@ public: void add_wait(Block &, Train *); const Route *get_route() const; - void set_destination(const Zone &); - void set_destination(const Block &); - bool has_destination() const; + void set_destination(const TrackChain &); + const TrackChain *get_destination() const { return destination; } bool is_destination(Track &) const; void set_departure_delay(const Msp::Time::TimeDelta &); const Msp::Time::TimeDelta &get_departure_delay() const { return delay; }