Skip to content

Commit 0f168ec

Browse files
authored
warn on mismatched turret objects (#4458)
1 parent 1768f5b commit 0f168ec

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

code/model/modelread.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,26 +2385,29 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode
23852385
int n_banks = cfread_int(fp); // Number of turrets
23862386

23872387
for ( i = 0; i < n_banks; i++ ) {
2388-
int parent; // The parent subobj of the turret (the gun base)
2389-
int physical_parent; // The subobj that the firepoints are physically attached to (the gun barrel)
23902388
int n_slots; // How many firepoints the turret has
23912389
model_subsystem *subsystemp; // The actual turret subsystem
23922390

2393-
parent = cfread_int( fp );
2394-
physical_parent = cfread_int(fp);
2391+
int base_obj = cfread_int(fp); // The parent subobj of the turret (the gun base)
2392+
int gun_obj = cfread_int(fp); // The subobj that the firepoints are physically attached to (the gun barrel)
2393+
2394+
if (base_obj != gun_obj && pm->submodel[gun_obj].parent != base_obj) {
2395+
Warning(LOCATION, "Model %s turret %s has a gun submodel that is not an immediate child object of the base", pm->filename, pm->submodel[base_obj].name);
2396+
gun_obj = base_obj; // fall back to singlepart handling
2397+
}
23952398

23962399
int snum=-1;
23972400
if ( subsystems ) {
23982401
for ( snum = 0; snum < n_subsystems; snum++ ) {
23992402
subsystemp = &subsystems[snum];
24002403

2401-
if ( parent == subsystemp->subobj_num ) {
2404+
if ( base_obj == subsystemp->subobj_num ) {
24022405
cfread_vector( &temp_vec, fp );
24032406
vm_vec_normalize_safe(&temp_vec);
24042407
subsystemp->turret_norm = temp_vec;
24052408

24062409
n_slots = cfread_int( fp );
2407-
subsystemp->turret_gun_sobj = physical_parent;
2410+
subsystemp->turret_gun_sobj = gun_obj;
24082411
if(n_slots > MAX_TFP) {
24092412
Warning(LOCATION, "Model %s has %i turret firing points on subsystem %s, maximum is %i", pm->filename, n_slots, subsystemp->name, MAX_TFP);
24102413
}
@@ -2423,8 +2426,8 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode
24232426
subsystemp->turret_num_firing_points = n_slots;
24242427

24252428
// copy the subsystem index that the gun base submodel should have at this point
2426-
Assertion(pm->submodel[parent].subsys_num >= 0, "Turret gun base should have a subsystem index!");
2427-
pm->submodel[physical_parent].subsys_num = pm->submodel[parent].subsys_num;
2429+
Assertion(pm->submodel[base_obj].subsys_num >= 0, "Turret gun base should have a subsystem index!");
2430+
pm->submodel[gun_obj].subsys_num = pm->submodel[base_obj].subsys_num;
24282431

24292432
break;
24302433
}
@@ -2434,7 +2437,7 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode
24342437
if ( (n_subsystems == 0) || (snum == n_subsystems) ) {
24352438
vec3d bogus;
24362439

2437-
nprintf(("Warning", "Turret submodel %i not found for turret %i in model %s\n", parent, i, pm->filename));
2440+
nprintf(("Warning", "Turret submodel %i not found for turret %i in model %s\n", base_obj, i, pm->filename));
24382441
cfread_vector( &bogus, fp );
24392442
n_slots = cfread_int( fp );
24402443
for (j = 0; j < n_slots; j++ )

0 commit comments

Comments
 (0)