X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fvehicle.cpp;h=75afa4bba78f9c10c03c4fb3254875d49770d9d1;hb=97443d96ff3ce51388d2edd1e0dca8f2cd231346;hp=d81848076c5984a26928873a49b13023785817d1;hpb=d01230572abde870055844b6efaa777a2ba93226;p=r2c2.git diff --git a/source/libmarklin/vehicle.cpp b/source/libmarklin/vehicle.cpp index d818480..75afa4b 100644 --- a/source/libmarklin/vehicle.cpp +++ b/source/libmarklin/vehicle.cpp @@ -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() @@ -150,6 +156,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; } @@ -207,6 +214,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(); @@ -214,7 +223,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