]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/vehicle.cpp
Display the total length of selected tracks in status bar
[r2c2.git] / source / libmarklin / vehicle.cpp
index 8761bb6f9f80bfc9a906da113ac3c7ff38adf8d7..5a26f9294b665c8a5178696e482f78a8489f17dd 100644 (file)
@@ -83,9 +83,9 @@ void Vehicle::detach_front()
        prev = 0;
 }
 
-void Vehicle::place(Track *t, unsigned e, float o, PlaceMode m)
+void Vehicle::place(Track &t, unsigned e, float o, PlaceMode m)
 {
-       track_pos = TrackPosition(t, e, o);
+       track_pos = TrackPosition(&t, e, o);
 
        if(m==FRONT_AXLE)
                track_pos.advance(-type.get_front_axle_offset());
@@ -100,6 +100,19 @@ void Vehicle::place(Track *t, unsigned e, float o, PlaceMode m)
        propagate_position();
 }
 
+void Vehicle::unplace()
+{
+       if(!track_pos.track)
+               return;
+
+       track_pos = TrackPosition();
+
+       if(prev)
+               prev->unplace();
+       if(next)
+               next->unplace();
+}
+
 void Vehicle::advance(float d)
 {
        track_pos.advance(d);
@@ -156,6 +169,7 @@ void Vehicle::update_position()
                check_sensor(type.get_back_axle_offset(), back_sensor);
 
        position = tp.pos;
+       position.z += layout.get_catalogue().get_rail_elevation();
        direction = tp.dir;
 }
 
@@ -213,6 +227,8 @@ void Vehicle::check_sensor(float offset, unsigned &sensor)
        {
                /* Sensor ID under axle has changed.  Deduce movement direction by using
                the sensor ID under the midpoint of the vehicle. */
+               /* XXX This depends on the simulation running fast enough.  Something
+               more robust would be preferable. */
                unsigned old = sensor;
                sensor = s;
                unsigned mid = track_pos.track->get_sensor_id();
@@ -220,7 +236,6 @@ void Vehicle::check_sensor(float offset, unsigned &sensor)
                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