+void Vehicle::check_sensor(float offset, unsigned &sensor)
+{
+ TrackPosition pos = track_pos;
+ pos.advance(offset);
+ unsigned s = pos.track->get_sensor_id();
+ if(s!=sensor)
+ {
+ /* Sensor ID under axle has changed. Deduce movement direction by using
+ the sensor ID under the midpoint of the vehicle. */
+ unsigned old = sensor;
+ sensor = s;
+ unsigned mid = track_pos.track->get_sensor_id();
+
+ if(s && s!=mid)
+ /* There's a sensor and it's different from mid. We've just entered
+ that sensor. */
+ // XXX The Train will reset the vehicles to the start of the sensor, which is somewhat undesirable
+ layout.get_driver().set_sensor(sensor, true);
+ if(old && old!=mid)
+ /* A sensor was under the axle and it was different from mid. We've
+ just left that sensor. */
+ layout.get_driver().set_sensor(old, false);
+ }
+}
+