X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibr2c2%2Ftrain.cpp;h=25dcae97da9580cea1946315674fb9bd36c5c3ed;hb=4481da8b54bba32b338befd509360816b08402e5;hp=e8df4d890ced6478c2e083776be81f9bc58564eb;hpb=4529bf980cf3558d86c07266de7d890d3f5e06a6;p=r2c2.git diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index e8df4d8..25dcae9 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 @@ -482,8 +490,7 @@ float Train::get_reserved_distance_until(const Block *until_block) const if(!track) // XXX Probably unnecessary return 0; - BlockIter block = track.block_iter(); - if(&*block==until_block) + if(&track->get_block()==until_block) return 0; // Account for the vehicle's offset on its current track @@ -494,6 +501,8 @@ float Train::get_reserved_distance_until(const Block *until_block) const result = track->get_type().get_path_length(track->get_active_path())-result; result -= veh.get_type().get_length()/2; + BlockIter block = track.block_iter(); + // Count remaining distance in the vehicle's current block for(track=track.next(); &track->get_block()==&*block; track=track.next()) result += track->get_type().get_path_length(track->get_active_path());