X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fblock.cpp;h=a304a152d6959717e02badca31da10ef6f3cc65e;hb=ae0600f7c3df5b6ef46992b1423888dd0e9a5026;hp=0106a50731d6dc3fb98e2e5a8f68a4c359614a04;hpb=aead7f2da831199fbb8f6950b067656b2965c2fa;p=r2c2.git diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index 0106a50..a304a15 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -1,3 +1,10 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + #include "control.h" #include "block.h" #include "tracktype.h" @@ -59,7 +66,7 @@ int Block::get_endpoint_by_link(const Block &other) const return -1; } -int Block::traverse(unsigned epi) const +int Block::traverse(unsigned epi, float *len) const { if(epi>=endpoints.size()) throw InvalidParameterValue("Endpoint index out of range"); @@ -68,6 +75,9 @@ int Block::traverse(unsigned epi) const Track *track=ep.track; unsigned track_ep=ep.track_ep; + if(len) + *len=0; + while(1) { unsigned cur_route=0; @@ -78,9 +88,12 @@ int Block::traverse(unsigned epi) const cur_route=turnout.get_route(); } + if(len) + *len+=track->get_type().get_route_length(cur_route); + int other_ep=track->traverse(track_ep, cur_route); if(other_ep<0) - return 0; + return -1; for(unsigned i=0; i(other_ep)) @@ -124,7 +137,7 @@ bool Block::reserve(const Train *t) { train=t; if(train) - cout<<"Block "<get_name()<<'\n'; else cout<<"Block "<