]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/train.cpp
Add a virtual get_block function to Sensor
[r2c2.git] / source / libr2c2 / train.cpp
index 25dcae97da9580cea1946315674fb9bd36c5c3ed..b2a49c722e7732938cfce5ed3cdefa95b5838d9b 100644 (file)
@@ -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<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)
                {