X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrain.cpp;h=a6fd46d1e40519381c9723058b7252736a5f3b98;hb=e2ecc5a6e8e8056cd09599e60140498f322b87b6;hp=9f97c33182160b9053573cf0fa40115660189199;hpb=bf0d5936a84425e851d25f9fde83a965024693e9;p=r2c2.git diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 9f97c33..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()) @@ -523,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,7 +639,7 @@ void Train::block_reserved(const Block &block, const Train *train) unsigned Train::reserve_more() { if(!active) - return; + return 0; BlockRef *last = 0; if(!rsv_blocks.empty()) @@ -834,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); }