From 59e4c75da550e96ae74162a5ed70e8b1999721d8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 1 Oct 2010 12:20:14 +0000 Subject: [PATCH] Place vehicles on the track when attached Fix Vehicle::attach_front to actually attach to the front Initialize VehicleType::locomotive --- source/libmarklin/vehicle.cpp | 10 ++++++++-- source/libmarklin/vehicletype.cpp | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/libmarklin/vehicle.cpp b/source/libmarklin/vehicle.cpp index d818480..8761bb6 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() diff --git a/source/libmarklin/vehicletype.cpp b/source/libmarklin/vehicletype.cpp index 937ce89..c206108 100644 --- a/source/libmarklin/vehicletype.cpp +++ b/source/libmarklin/vehicletype.cpp @@ -14,6 +14,7 @@ namespace Marklin { VehicleType::VehicleType(unsigned n): art_nr(n), + locomotive(false), length(0), width(0), height(0) -- 2.45.2