X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Froute.cpp;h=79886d28c371c793ed223909ef343b79edc0b726;hb=975ea87cc7be179618b06291cb2506a2523cad1f;hp=663bd8847c08f2467c1d9376b8900271bcba7428;hpb=2707158feba5f9740d51618692914db05410f9a6;p=r2c2.git diff --git a/source/libmarklin/route.cpp b/source/libmarklin/route.cpp index 663bd88..79886d2 100644 --- a/source/libmarklin/route.cpp +++ b/source/libmarklin/route.cpp @@ -87,7 +87,7 @@ list dijkstra(const TrackIter &from, const Pred &goal) break; } - unsigned paths = lowest.track->get_type().get_endpoints()[lowest.track.entry()].paths; + unsigned paths = lowest.track.endpoint().paths; for(unsigned i=0; paths>>i; ++i) if(paths&(1< &links = (*i)->get_links(); // Build a combined path mask from linked endpoints - unsigned mask = 15; + unsigned mask = (*i)->get_type().get_paths(); for(unsigned j=0; jget_turnout_id()) { - const TrackType::Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)]; + const TrackType::Endpoint &ep = links[j]->get_type().get_endpoint(links[j]->get_endpoint_by_link(**i)); int p = get_turnout(tid2); if(p>=0 && !(ep.paths&(1< &st) const unsigned Route::check_validity(Track &trk) const { unsigned result = 4; - for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + const vector &links = trk.get_links(); + for(vector::const_iterator i=links.begin(); i!=links.end(); ++i) { - int epi=(*i)->get_endpoint_by_link(trk); - if(epi>=0) + if(!*i) + continue; + if(!tracks.count(*i)) + continue; + + // Linked to an existing track - good + result |= 1; + + if(unsigned tid = (*i)->get_turnout_id()) { - // Linked to an existing track - good - result |= 1; - const vector &endpoints = (*i)->get_type().get_endpoints(); - if(unsigned tid=(*i)->get_turnout_id()) + const TrackType::Endpoint &ep = (*i)->get_type().get_endpoint((*i)->get_endpoint_by_link(trk)); + int path = get_turnout(tid); + if(path>=0) { - int r = get_turnout(tid); - if(r>=0) - { - // Linking to a turnout with path set is only good if we're continuing that path - if(endpoints[epi].paths&(1< &links = (*i)->get_links(); - int epj = -1; - for(unsigned k=0; k &tlinks = (*i)->get_links(); + unsigned count = 0; + for(unsigned j=0; jget_turnout_id(); + if(tid2) { - ++count; - epj = k; + const TrackType::Endpoint &ep2 = tlinks[j]->get_type().get_endpoint(tlinks[j]->get_endpoint_by_link(**i)); + path = get_turnout(tid2); + // Ignore a linked turnout with some other path set + if(path>0 && !(ep2.paths&(1<=0 && !(endpoints[epi].paths&endpoints[epj].paths)) + ++count; + + const TrackType::Endpoint &ep2 = (*i)->get_type().get_endpoint(j); + if(!(ep.paths&ep2.paths)) // Impossible path through the turnout - not good result &= 3; } - } + + // Only good if at most one other track is linked to the turnout + if(count<=1) + result |= 2; } - else - // Linked to something linear - good - result |= 2; } + else + // Linked to something linear - good + result |= 2; } return result;