X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibr2c2%2Ftrain.cpp;h=0cbe306234c09b11a9535f1e21fe71673e4bed2e;hb=90f9efba8d88f41c7a180734b7bcbdd1501d995e;hp=dd7139f864824c7aac2e80b1eea4f8c40691c6ab;hpb=1ff06c5bc46a677fa389ef86c6b26664368f1653;p=r2c2.git diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index dd7139f..0cbe306 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -21,6 +21,7 @@ Distributed under the GPL #include "train.h" #include "vehicle.h" #include "vehicletype.h" +#include "zone.h" using namespace std; using namespace Msp; @@ -47,6 +48,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p): protocol(p), priority(0), yielding_to(0), + preceding_train(0), cur_blocks_end(blocks.end()), clear_blocks_end(blocks.end()), pending_block(0), @@ -266,6 +268,35 @@ bool Train::go_to(Track &to) return set_route(route); } +bool Train::go_to(const Zone &to) +{ + set tracks; + for(BlockList::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) + tracks.insert((*i)->get_tracks().begin(), (*i)->get_tracks().end()); + + const Zone::TrackSet &ztracks = to.get_tracks(); + unsigned union_size = 0; + for(Zone::TrackSet::const_iterator i=ztracks.begin(); i!=ztracks.end(); ++i) + union_size += tracks.count(*i); + + if(union_size==tracks.size() || union_size==ztracks.size()) + { + signal_arrived.emit(); + return set_route(0); + } + + free_noncritical_blocks(); + + TrackIter next = blocks.back().next().track_iter(); + + Route *route = Route::find(next, to); + if(!route) + return false; + create_lead_route(route, route); + route->add_tracks(ztracks); + return set_route(route); +} + bool Train::divert(Track &from) { if(!from.get_turnout_id()) @@ -811,6 +842,7 @@ void Train::reserve_more() BlockIter start = blocks.back(); pending_block = 0; + preceding_train = 0; // See how many sensor blocks and how much track we already have unsigned nsens = 0; @@ -922,10 +954,15 @@ void Train::reserve_more() bool entry_conflict = (block.entry()==other_exit); bool exit_conflict = (exit==static_cast(other_entry)); if(!entry_conflict && !last->get_turnout_id()) + { /* The other train is not coming to the blocks we're holding, so we can keep them. */ good_end = blocks.end(); + if(static_cast(other_entry)==block.entry()) + preceding_train = other_train; + } + int other_prio = other_train->get_priority(); if(!entry_conflict && !exit_conflict && other_prio