From: Mikko Rasa Date: Fri, 28 Jun 2013 19:24:13 +0000 (+0300) Subject: Add signals for adding and removing vehicles X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ab64a17394440c3cb18d0b30d75fb4ed6297a6b4;p=r2c2.git Add signals for adding and removing vehicles --- diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index e8df4d8..4f6c204 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -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(idetach_back(); vehicles[i-1]->attach_back(*vehicles[i]); + } + signal_vehicle_removed.emit(i, *veh); + delete veh; } unsigned Train::get_n_vehicles() const diff --git a/source/libr2c2/train.h b/source/libr2c2/train.h index f378389..3aaf6b1 100644 --- a/source/libr2c2/train.h +++ b/source/libr2c2/train.h @@ -43,6 +43,8 @@ public: sigc::signal signal_function_changed; sigc::signal signal_ai_event; sigc::signal signal_advanced; + sigc::signal signal_vehicle_added; + sigc::signal signal_vehicle_removed; private: Layout &layout;