Skip to content

Commit 2813ceb

Browse files
authored
Fix for ships blowing up with live debris submodels (#7139)
1 parent a2c0500 commit 2813ceb

2 files changed

Lines changed: 13 additions & 72 deletions

File tree

code/model/modelread.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,43 +3832,6 @@ void model_set_bay_path_nums(polymodel *pm)
38323832
}
38333833
}
38343834

3835-
// Get "parent" submodel for live debris submodel
3836-
int model_get_parent_submodel_for_live_debris( int model_num, int live_debris_model_num )
3837-
{
3838-
polymodel *pm = model_get(model_num);
3839-
3840-
Assert(pm->submodel[live_debris_model_num].flags[Model::Submodel_flags::Is_live_debris]);
3841-
3842-
int mn;
3843-
bsp_info *child;
3844-
3845-
// Start with the high level of detail hull
3846-
// Check all its children until we find the submodel to which the live debris belongs
3847-
child = &pm->submodel[pm->detail[0]];
3848-
mn = child->first_child;
3849-
3850-
while (mn > 0) {
3851-
child = &pm->submodel[mn];
3852-
3853-
if (child->num_live_debris > 0) {
3854-
// check all live debris submodels for the current child
3855-
for (int idx=0; idx<child->num_live_debris; idx++) {
3856-
if (child->live_debris[idx] == live_debris_model_num) {
3857-
return mn;
3858-
}
3859-
}
3860-
// DKA 5/26/99: can multiple live debris subsystems with each ship
3861-
// NO LONGER TRUE Can only be 1 submodel with live debris
3862-
// Error( LOCATION, "Could not find parent submodel for live debris. Possible model error");
3863-
}
3864-
3865-
// get next child
3866-
mn = child->next_sibling;
3867-
}
3868-
Error( LOCATION, "Could not find parent submodel for live debris");
3869-
return -1;
3870-
}
3871-
38723835

38733836
float model_get_radius( int modelnum )
38743837
{

code/ship/shipfx.cpp

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void shipfx_subsystem_maybe_create_live_debris(object *ship_objp, const s
221221
static 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

Comments
 (0)