X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrain.cpp;h=b2a49c722e7732938cfce5ed3cdefa95b5838d9b;hb=218f194f537dfda55d32ce8d8739e322a3d0c07d;hp=4f6c2046d7d9e0528158bc5d5c6af560816e3cd0;hpb=ab64a17394440c3cb18d0b30d75fb4ed6297a6b4;p=r2c2.git diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 4f6c204..b2a49c7 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -422,13 +422,9 @@ void Train::loco_func_event(unsigned addr, unsigned func, bool state) void Train::sensor_state_changed(Sensor &sensor, Sensor::State state) { - Block *block = 0; - if(TrackCircuit *tc = dynamic_cast(&sensor)) - block = &tc->get_block(); - else - return; + Block *block = sensor.get_block(); - if(block->get_train()==this && state==Sensor::MAYBE_ACTIVE) + if(block && block->get_train()==this && state==Sensor::MAYBE_ACTIVE) { if(last_entry_block) { @@ -490,8 +486,7 @@ float Train::get_reserved_distance_until(const Block *until_block) const if(!track) // XXX Probably unnecessary return 0; - BlockIter block = track.block_iter(); - if(&*block==until_block) + if(&track->get_block()==until_block) return 0; // Account for the vehicle's offset on its current track @@ -502,6 +497,8 @@ float Train::get_reserved_distance_until(const Block *until_block) const result = track->get_type().get_path_length(track->get_active_path())-result; result -= veh.get_type().get_length()/2; + BlockIter block = track.block_iter(); + // Count remaining distance in the vehicle's current block for(track=track.next(); &track->get_block()==&*block; track=track.next()) result += track->get_type().get_path_length(track->get_active_path());