Skip to content

Commit f1a25ab

Browse files
authored
Per Request add flag for $Disabled or disrupted engines are silent: (#6792)
* Per Request add flag for `$Disabled engines are silent:` Follow-up to #6781 as there are modders who use engine sound as ambient sound. Also cleans up the sound engine disabled logic. * cleanup name * update flag name
1 parent d3db542 commit f1a25ab

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

code/mod_table/mod_table.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ bool Auto_assign_personas;
153153
bool Countermeasures_use_capacity;
154154
bool Play_thruster_sounds_for_player;
155155
bool Unify_minimum_engine_sound;
156+
bool Disabled_or_disrupted_engines_silent;
156157
std::array<std::tuple<float, float>, 6> Fred_spacemouse_nonlinearity;
157158
bool Randomize_particle_rotation;
158159
bool Disable_shield_effects;
@@ -1048,6 +1049,10 @@ void parse_mod_table(const char *filename)
10481049
stuff_boolean(&Unify_minimum_engine_sound);
10491050
}
10501051

1052+
if (optional_string("$Disabled or disrupted engines are silent:")) {
1053+
stuff_boolean(&Disabled_or_disrupted_engines_silent);
1054+
}
1055+
10511056
optional_string("#FRED SETTINGS");
10521057

10531058
if (optional_string("$Disable Hard Coded Message Head Ani Files:")) {
@@ -1734,6 +1739,7 @@ void mod_table_reset()
17341739
Countermeasures_use_capacity = false;
17351740
Play_thruster_sounds_for_player = false;
17361741
Unify_minimum_engine_sound = false;
1742+
Disabled_or_disrupted_engines_silent = false;
17371743
Fred_spacemouse_nonlinearity = std::array<std::tuple<float, float>, 6>{{
17381744
std::tuple<float, float>{ 1.0f, 1.0f },
17391745
std::tuple<float, float>{ 1.0f, 1.0f },

code/mod_table/mod_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ extern bool Auto_assign_personas;
168168
extern bool Countermeasures_use_capacity;
169169
extern bool Play_thruster_sounds_for_player;
170170
extern bool Unify_minimum_engine_sound;
171+
extern bool Disabled_or_disrupted_engines_silent;
171172
extern std::array<std::tuple<float, float>, 6> Fred_spacemouse_nonlinearity;
172173
extern bool Randomize_particle_rotation;
173174
extern bool Disable_shield_effects;

code/object/objectsnd.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ void obj_snd_do_frame()
446446
obj_snd *osp;
447447
object *objp, *closest_objp;
448448
game_snd *gs;
449-
ship *sp;
450449
int channel;
451450
vec3d source_pos;
452451
float add_distance;
@@ -487,6 +486,8 @@ void obj_snd_do_frame()
487486
continue;
488487
}
489488

489+
bool obj_is_ship = (objp->type == OBJ_SHIP);
490+
490491
obj_snd_source_pos(&source_pos, osp);
491492
distance = vm_vec_dist_quick( &source_pos, &View_position );
492493

@@ -502,7 +503,7 @@ void obj_snd_do_frame()
502503
}
503504

504505
// save closest distance (used for flyby sound) if this is a small ship (and not the observer)
505-
if ( (objp->type == OBJ_SHIP) && (distance < closest_dist) && (objp != observer_obj) ) {
506+
if ( (obj_is_ship) && (distance < closest_dist) && (objp != observer_obj) ) {
506507
if ( Ship_info[Ships[objp->instance].ship_info_index].is_small_ship() ) {
507508
closest_dist = distance;
508509
closest_objp = objp;
@@ -512,7 +513,7 @@ void obj_snd_do_frame()
512513
speed_vol_multiplier = 1.0f;
513514
rot_vol_mult = 1.0f;
514515
alive_vol_mult = 1.0f;
515-
if ( objp->type == OBJ_SHIP ) {
516+
if ( obj_is_ship ) {
516517
ship_info *sip = &Ship_info[Ships[objp->instance].ship_info_index];
517518

518519
// we don't want to start the engine sound unless the ship is
@@ -658,16 +659,21 @@ void obj_snd_do_frame()
658659
if (!osp->instance.isValid())
659660
continue;
660661

661-
sp = nullptr;
662-
if ( objp->type == OBJ_SHIP )
662+
bool sound_allowed = true;
663+
ship* sp = nullptr;
664+
if (obj_is_ship) {
663665
sp = &Ships[objp->instance];
664-
666+
if (osp->flags & OS_ENGINE) {
667+
bool disabled_and_silent = Disabled_or_disrupted_engines_silent &&
668+
(sp->flags[Ship::Ship_Flags::Disabled] || ship_subsys_disrupted(sp, SUBSYSTEM_ENGINE));
669+
sound_allowed = (sp->flags[Ship::Ship_Flags::Engine_sound_on]) && !disabled_and_silent;
670+
}
671+
}
665672

666673
channel = ds_get_channel(osp->instance);
667674
// for DirectSound3D sounds, re-establish the maximum speed based on the
668675
// speed_vol_multiplier
669-
if ( (sp == nullptr) || !(osp->flags & OS_ENGINE) ||
670-
((sp->flags[Ship::Ship_Flags::Engine_sound_on]) && !(sp->flags[Ship::Ship_Flags::Disabled])) ) {
676+
if ( sound_allowed ) {
671677
snd_set_volume( osp->instance, gs->volume_range.next() *speed_vol_multiplier*rot_vol_mult*alive_vol_mult );
672678
}
673679
else {
@@ -678,7 +684,7 @@ void obj_snd_do_frame()
678684
vec3d vel = objp->phys_info.vel;
679685

680686
// Don't play doppler effect for cruisers or capitals
681-
if ( sp ) {
687+
if (obj_is_ship) {
682688
if ( Ship_info[sp->ship_info_index].is_big_or_huge() ) {
683689
vel = vmd_zero_vector;
684690
}

0 commit comments

Comments
 (0)