]> git.tdb.fi Git - r2c2.git/commitdiff
Make vehicles aware of which train they are in
authorMikko Rasa <tdb@tdb.fi>
Tue, 25 Jun 2013 16:12:22 +0000 (19:12 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 25 Jun 2013 16:12:22 +0000 (19:12 +0300)
source/libr2c2/train.cpp
source/libr2c2/vehicle.cpp
source/libr2c2/vehicle.h

index 6cb3205eb175fad4f6e6d8b18997a725df2da7b5..74bc50328ce8b6bb60f7f917c149b97989d5e7b7 100644 (file)
@@ -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
index 457cb332dc2f5148327988ad797184205fee632a..a9d5135e9d7806955148e62b8558bd854339372a 100644 (file)
@@ -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)
index e7427b1e92ef6bb61b95ae48b9241664997b7413..616ad366d2de5ce2973a48848e2e33fb2d169719 100644 (file)
@@ -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();