Skip to content

Commit b5f3edc

Browse files
authored
Fix engine not updating with change-ship (#6893)
* Fix engine not updating with change-ship Yet another caveat of the change-ship function was discovered by Darius, who found that that both the 3D assigned engine sounds and the 2D throttle/cockpit engine sounds do not properly updated when a ship type is changed via sexp/script. This PR fixes this by properly calling the respective clearing functions and it also resets the throttle sound check timestamp to ensure the 2D sounds are indeed updated on the next frame. Tested and works as expected. Fixes #6892. * cleanup for safety
1 parent e28b3bb commit b5f3edc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

code/hud/hud.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,7 @@ void hud_stop_looped_engine_sounds()
21752175
snd_stop(Player_engine_snd_loop);
21762176
Player_engine_snd_loop = sound_handle::invalid();
21772177
}
2178+
throttle_sound_check_id = timestamp(THROTTLE_SOUND_CHECK_INTERVAL);
21782179
}
21792180

21802181
#define ZERO_PERCENT 0.01f

code/ship/ship.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12203,8 +12203,12 @@ void change_ship_type(int n, int ship_type, int by_sexp)
1220312203
animation::anim_set_initial_states(sp);
1220412204

1220512205
//Reassign sound stuff
12206-
if (!Fred_running)
12206+
if (!Fred_running) {
12207+
if (objp == Player_obj) {
12208+
hud_stop_looped_engine_sounds();
12209+
}
1220712210
ship_assign_sound(sp);
12211+
}
1220812212

1220912213
// Valathil - Reinitialize collision checks
1221012214
obj_remove_collider(OBJ_INDEX(objp));
@@ -16317,6 +16321,9 @@ void ship_assign_sound(ship *sp)
1631716321
objp = &Objects[sp->objnum];
1631816322
sip = &Ship_info[sp->ship_info_index];
1631916323

16324+
// clear out any existing assigned sounds --wookieejedi
16325+
obj_snd_delete_type(OBJ_INDEX(objp));
16326+
1632016327
// Do subsystem sounds
1632116328
moveup = GET_FIRST(&sp->subsys_list);
1632216329
while(moveup != END_OF_LIST(&sp->subsys_list)) {

0 commit comments

Comments
 (0)