X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibmarklin%2Ftrain.cpp;h=7af10280228fa751970c4df739f1506400dc7271;hb=e1e5bf92fc73bd117c509ceea1c7de7d95288a7d;hp=e904ebfc5f94b8152890c47c68a9b77cc4ebf189;hpb=6dc18b0e518407bd2a86602bae1e9bbae05da7c8;p=r2c2.git diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index e904ebf..7af1028 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -11,6 +11,7 @@ Distributed under the GPL #include #include "control.h" #include "except.h" +#include "route.h" #include "tracktype.h" #include "trafficmanager.h" #include "train.h" @@ -80,6 +81,12 @@ void Train::set_reverse(bool rev) loco.set_reverse(rev); } +void Train::set_route(const Route *r) +{ + route = r; + signal_route_changed.emit(route); +} + void Train::place(Block *block, unsigned entry) { for(list::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end();) @@ -316,27 +323,29 @@ unsigned Train::reserve_more() while(nsens<2) { int exit = last->block->traverse(last->entry); - if(exit>=0) + if(exit<0) + break; + + Block *link = last->block->get_link(exit); + if(!link || !link->reserve(this)) + break; + + if(route && link->get_turnout_id()) { - Block *link = last->block->get_link(exit); - if(link && link->reserve(this)) - { - rsv_blocks.push_back(BlockRef(link, link->get_endpoint_by_link(*last->block))); - last = &rsv_blocks.back(); - if(last->block->get_sensor_id()) - { - ++nsens; - result = true; - } - } - else - break; + int path = route->get_turnout(link->get_turnout_id()); + if(path>=0) + trfc_mgr.get_control().get_turnout(link->get_turnout_id()).set_path(path); + } + rsv_blocks.push_back(BlockRef(link, link->get_endpoint_by_link(*last->block))); + last = &rsv_blocks.back(); + if(last->block->get_sensor_id()) + { + ++nsens; + result = true; } - else - break; } - while(last && !last->block->get_sensor_id()) + while(!rsv_blocks.empty() && !last->block->get_sensor_id()) { last->block->reserve(0); rsv_blocks.erase(--rsv_blocks.end()); @@ -422,14 +431,23 @@ unsigned Train::find_speed(float real) const { if(real<=real_speed[0].speed) return 0; - if(real>=real_speed[14].speed) - return 14; unsigned low = 0; unsigned high = 0; - for(high=0; real_speed[high].speed(low*real/real_speed[low].speed), 14U); + } float f = (real-real_speed[low].speed)/(real_speed[high].speed-real_speed[low].speed); return static_cast(low*(1-f)+high*f+0.5);