@@ -221,7 +221,7 @@ static void shipfx_subsystem_maybe_create_live_debris(object *ship_objp, const s
221221static void shipfx_maybe_create_live_debris_at_ship_death ( object *ship_objp )
222222{
223223 // if ship has live debris, detonate that subsystem now
224- // search for any live debris
224+ // search for any submodels which have live debris
225225
226226 ship *shipp = &Ships[ship_objp->instance ];
227227 polymodel *pm = model_get (Ship_info[shipp->ship_info_index ].model_num );
@@ -232,41 +232,19 @@ static void shipfx_maybe_create_live_debris_at_ship_death( object *ship_objp )
232232 return ;
233233 }
234234
235- int live_debris_submodel = -1 ;
236- for (int idx=0 ; idx<pm->num_debris_objects ; idx++) {
237- if (pm->submodel [pm->debris_objects [idx]].flags [Model::Submodel_flags::Is_live_debris]) {
238- live_debris_submodel = pm->debris_objects [idx];
239-
240- // get submodel that produces live debris
241- int model_get_parent_submodel_for_live_debris ( int model_num, int live_debris_model_num );
242- int parent = model_get_parent_submodel_for_live_debris (pm->id , live_debris_submodel);
243- Assert (parent != -1 );
244-
245- // check if already blown off (ship model set)
246- if ( !pmi->submodel [parent].blown_off ) {
247-
248- // get ship_subsys for live_debris
249- // Go through all subsystems and look for submodel the subsystems with "parent" submodel.
250- ship_subsys *pss = NULL ;
251- for ( pss = GET_FIRST (&shipp->subsys_list ); pss != END_OF_LIST (&shipp->subsys_list ); pss = GET_NEXT (pss) ) {
252- if (pss->system_info ->subobj_num == parent) {
253- break ;
254- }
255- }
256-
257- Assert (pss != NULL );
258- if (pss != NULL ) {
259- if (pss->system_info != NULL ) {
260- vec3d exp_center, tmp = ZERO_VECTOR ;
261- model_instance_local_to_global_point (&exp_center, &tmp, pm, pmi, parent, &ship_objp->orient , &ship_objp->pos );
262-
263- // if not blown off, blow it off
264- shipfx_subsystem_maybe_create_live_debris (ship_objp, shipp, pss, &exp_center, 3 .0f );
235+ for (auto pss: list_range (&shipp->subsys_list )) {
236+ if (pss->system_info != nullptr ) {
237+ int submodel_num = pss->system_info ->subobj_num ;
238+ // find the submodels which aren't already blown up and have live debris
239+ if (!pmi->submodel [submodel_num].blown_off && pm->submodel [submodel_num].num_live_debris > 0 ) {
240+ vec3d exp_center, tmp = ZERO_VECTOR ;
241+ model_instance_local_to_global_point (&exp_center, &tmp, pm, pmi, submodel_num, &ship_objp->orient , &ship_objp->pos );
242+
243+ // create its debris
244+ shipfx_subsystem_maybe_create_live_debris (ship_objp, shipp, pss, &exp_center, 3 .0f );
265245
266- // now set subsystem as blown off, so we only get one copy
267- pmi->submodel [parent].blown_off = true ;
268- }
269- }
246+ // now set subsystem as blown off, so we only get one copy
247+ pmi->submodel [submodel_num].blown_off = true ;
270248 }
271249 }
272250 }
0 commit comments