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)
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
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;