]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/vehicle.cpp
Place vehicles on the track when attached
[r2c2.git] / source / libmarklin / vehicle.cpp
index d81848076c5984a26928873a49b13023785817d1..8761bb6f9f80bfc9a906da113ac3c7ff38adf8d7 100644 (file)
@@ -48,6 +48,9 @@ void Vehicle::attach_back(Vehicle &veh)
 
        next = &veh;
        veh.prev = this;
+
+       if(track_pos.track)
+               propagate_backward();
 }
 
 void Vehicle::attach_front(Vehicle &veh)
@@ -55,8 +58,11 @@ void Vehicle::attach_front(Vehicle &veh)
        if(prev || veh.next)
                throw InvalidState("Already attached");
 
-       next = &veh;
-       veh.prev = this;
+       prev = &veh;
+       veh.next = this;
+
+       if(prev->get_track())
+               prev->propagate_backward();
 }
 
 void Vehicle::detach_back()