]> git.tdb.fi Git - r2c2.git/commitdiff
Add signals for adding and removing vehicles
authorMikko Rasa <tdb@tdb.fi>
Fri, 28 Jun 2013 19:24:13 +0000 (22:24 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 28 Jun 2013 19:24:13 +0000 (22:24 +0300)
source/libr2c2/train.cpp
source/libr2c2/train.h

index e8df4d890ced6478c2e083776be81f9bc58564eb..4f6c2046d7d9e0528158bc5d5c6af560816e3cd0 100644 (file)
@@ -89,6 +89,7 @@ void Train::add_vehicle(const VehicleType &vt)
        vehicles.back()->attach_back(*veh);
        vehicles.push_back(veh);
        veh->set_train(this);
+       signal_vehicle_added.emit(vehicles.size()-1, *veh);
 }
 
 void Train::remove_vehicle(unsigned i)
@@ -97,10 +98,17 @@ void Train::remove_vehicle(unsigned i)
                throw out_of_range("Train::remove_vehicle");
        if(i==0)
                throw logic_error("can't remove locomotive");
-       delete vehicles[i];
+
+       Vehicle *veh = vehicles[i];
        vehicles.erase(vehicles.begin()+i);
+       veh->detach_front();
        if(i<vehicles.size())
+       {
+               veh->detach_back();
                vehicles[i-1]->attach_back(*vehicles[i]);
+       }
+       signal_vehicle_removed.emit(i, *veh);
+       delete veh;
 }
 
 unsigned Train::get_n_vehicles() const
index f3783893d3297628f5af69df539e3500e7b7cf66..3aaf6b14137cf8401489c39918fbba135107a011 100644 (file)
@@ -43,6 +43,8 @@ public:
        sigc::signal<void, unsigned, bool> signal_function_changed;
        sigc::signal<void, TrainAI &, const TrainAI::Message &> signal_ai_event;
        sigc::signal<void, Block &> signal_advanced;
+       sigc::signal<void, unsigned, Vehicle &> signal_vehicle_added;
+       sigc::signal<void, unsigned, Vehicle &> signal_vehicle_removed;
 
 private:
        Layout &layout;