From: Mikko Rasa Date: Tue, 25 Jun 2013 16:12:22 +0000 (+0300) Subject: Make vehicles aware of which train they are in X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0c2a3e6c435fd4cf05cc5275f750d341842aa543;p=r2c2.git Make vehicles aware of which train they are in --- diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 6cb3205..74bc503 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -53,6 +53,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p): speed_quantizer = new SpeedQuantizer(speed_steps); vehicles.push_back(new Vehicle(layout, loco_type)); + vehicles.back()->set_train(this); layout.add_train(*this); @@ -87,6 +88,7 @@ void Train::add_vehicle(const VehicleType &vt) Vehicle *veh = new Vehicle(layout, vt); vehicles.back()->attach_back(*veh); vehicles.push_back(veh); + veh->set_train(this); } void Train::remove_vehicle(unsigned i) @@ -561,6 +563,7 @@ void Train::Loader::vehicle(ArticleNumber art_nr) Vehicle *veh = new Vehicle(obj.layout, vtype); obj.vehicles.back()->attach_back(*veh); obj.vehicles.push_back(veh); + veh->set_train(&obj); } } // namespace R2C2 diff --git a/source/libr2c2/vehicle.cpp b/source/libr2c2/vehicle.cpp index 457cb33..a9d5135 100644 --- a/source/libr2c2/vehicle.cpp +++ b/source/libr2c2/vehicle.cpp @@ -16,6 +16,7 @@ namespace R2C2 { Vehicle::Vehicle(Layout &l, const VehicleType &t): Object(l), type(t), + train(0), next(0), prev(0), front_sensor(0), @@ -45,6 +46,11 @@ Vehicle *Vehicle::clone(Layout *to_layout) const return veh; } +void Vehicle::set_train(Train *t) +{ + train = t; +} + void Vehicle::attach_back(Vehicle &veh) { if(next || veh.prev) diff --git a/source/libr2c2/vehicle.h b/source/libr2c2/vehicle.h index e7427b1..616ad36 100644 --- a/source/libr2c2/vehicle.h +++ b/source/libr2c2/vehicle.h @@ -9,6 +9,7 @@ namespace R2C2 { class Layout; +class Train; class attachment_error: public std::logic_error { @@ -69,6 +70,7 @@ private: }; const VehicleType &type; + Train *train; Vehicle *next; Vehicle *prev; TrackPosition track_pos; @@ -85,6 +87,8 @@ public: virtual Vehicle *clone(Layout * = 0) const; virtual const VehicleType &get_type() const { return type; } + void set_train(Train *); + Train *get_train() const { return train; } void attach_back(Vehicle &); void attach_front(Vehicle &); void detach_back();