void Train::sensor_state_changed(Sensor &sensor, Sensor::State state)
{
- Block *block = 0;
- if(TrackCircuit *tc = dynamic_cast<TrackCircuit *>(&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)
{
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
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());