X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibmarklin%2Ftrain.cpp;h=a6fd46d1e40519381c9723058b7252736a5f3b98;hb=cf52013784607dc4d307bd1244c5346ee88336a4;hp=634f45c11a692a6ecbbd94f06b77051b6e5de7d2;hpb=d3907f4b0e60f246a53201b93b06e86062f1b48a;p=r2c2.git diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 634f45c..a6fd46d 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -141,6 +141,12 @@ bool Train::get_function(unsigned func) const return (functions>>func)&1; } +void Train::set_timetable(Timetable *tt) +{ + delete timetable; + timetable = tt; +} + void Train::set_route(const Route *r) { if(!rsv_blocks.empty()) @@ -169,8 +175,7 @@ void Train::set_route(const Route *r) } } - if(active) - reserve_more(); + reserve_more(); signal_route_changed.emit(route); } @@ -524,8 +529,11 @@ void Train::sensor_event(unsigned addr, bool state) if(pure_speed) { - RealSpeed &rs = real_speed[current_speed]; - rs.add(travel_dist/travel_time_secs, travel_time_secs); + if(current_speed) + { + RealSpeed &rs = real_speed[current_speed]; + rs.add(travel_dist/travel_time_secs, travel_time_secs); + } set_status(format("Traveling %d kmh", get_travel_speed())); } @@ -630,6 +638,9 @@ void Train::block_reserved(const Block &block, const Train *train) unsigned Train::reserve_more() { + if(!active) + return 0; + BlockRef *last = 0; if(!rsv_blocks.empty()) last = &rsv_blocks.back(); @@ -832,7 +843,12 @@ unsigned Train::find_speed(float real) const if(!high) { if(!low) - return 0; + { + if(real) + return 3; + else + return 0; + } return min(static_cast(low*real/real_speed[low].speed), 14U); }