From e493eb374f956086cb8e0510c96c60684c2de8d3 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 4 Jan 2025 11:00:28 -0800 Subject: [PATCH] Hearing - Add hearing damage factor attribute to `CfgAmmo` (#10617) --- addons/compat_sog/CfgAmmo/grenades.hpp | 1 + addons/hearing/functions/fnc_explosion.sqf | 16 +++++++++------- addons/hearing/functions/fnc_getAmmoLoudness.sqf | 5 +++-- docs/wiki/framework/hearing-framework.md | 9 +++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/addons/compat_sog/CfgAmmo/grenades.hpp b/addons/compat_sog/CfgAmmo/grenades.hpp index 6395756f640..1a40b48429f 100644 --- a/addons/compat_sog/CfgAmmo/grenades.hpp +++ b/addons/compat_sog/CfgAmmo/grenades.hpp @@ -2,6 +2,7 @@ class vn_grenadehand; class vn_molotov_grenade_ammo: vn_grenadehand { ACE_damageType = QGVAR(explosive_incendiary); EGVAR(frag,enabled) = 0; + EGVAR(hearing,hearingDamageFactor) = 0; }; class vn_t67_grenade_ammo: vn_grenadehand { diff --git a/addons/hearing/functions/fnc_explosion.sqf b/addons/hearing/functions/fnc_explosion.sqf index 2d3d5929895..8eceeeaf148 100644 --- a/addons/hearing/functions/fnc_explosion.sqf +++ b/addons/hearing/functions/fnc_explosion.sqf @@ -32,11 +32,6 @@ if (_distance > 100) exitWith { private _ammoConfig = configOf _projectile; private _hit = getNumber (_ammoConfig >> "hit"); if (_hit < 0.5) exitWith { TRACE_1("ignore smoke/flare",_hit) }; -private _explosive = getNumber (_ammoConfig >> "explosive"); - -private _vehAttenuation = [GVAR(playerVehAttenuation), 1] select (isNull objectParent ACE_player || {isTurnedOut ACE_player}); - -TRACE_4("",typeOf _projectile,_distance,_explosive,_vehAttenuation); (if (isArray (_ammoConfig >> "soundHit1")) then { getArray (_ammoConfig >> "soundHit1") @@ -48,9 +43,16 @@ if (_distance > _maxDistance) exitWith { TRACE_2("too far away",_distance,_maxDistance); }; +private _explosive = getNumber (_ammoConfig >> "explosive"); +private _hearingDamageFactor = [_ammoConfig >> QGVAR(hearingDamageFactor), "NUMBER", 1] call CBA_fnc_getConfigEntry; + +private _vehAttenuation = [GVAR(playerVehAttenuation), 1] select (isNull objectParent ACE_player || {isTurnedOut ACE_player}); + +TRACE_5("",typeOf _projectile,_distance,_explosive,_hearingDamageFactor,_vehAttenuation); + // Tone down _maxDistance to bring strength back to similar levels as a large burst of a loud weapon -private _strength = _vehAttenuation * _explosive * _volume * (_maxDistance / 2) / _distance^2; -TRACE_6("strength",_vehAttenuation,_explosive,_volume,_maxDistance,_distance,_strength); +private _strength = _vehAttenuation * _explosive * _hearingDamageFactor * _volume * (_maxDistance / 2) / _distance^2; +TRACE_7("strength",_vehAttenuation,_explosive,_hearingDamageFactor,_volume,_maxDistance,_distance,_strength); // Call immediately, as it will get picked up later by the update thread anyway (_strength * GVAR(explosionDeafnessCoefficient)) call FUNC(earRinging); diff --git a/addons/hearing/functions/fnc_getAmmoLoudness.sqf b/addons/hearing/functions/fnc_getAmmoLoudness.sqf index 062b96fa718..1ad072f157e 100644 --- a/addons/hearing/functions/fnc_getAmmoLoudness.sqf +++ b/addons/hearing/functions/fnc_getAmmoLoudness.sqf @@ -37,8 +37,9 @@ GVAR(cacheAmmoLoudness) getOrDefaultCall [_magazine, { default {[_caliber, 6.5] select (_caliber <= 0)}; }; - private _loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) / 5; - TRACE_5("building cache",_ammo,_magazine,_initSpeed,_caliber,_loudness); + private _hearingDamageFactor = [_ammoConfig >> QGVAR(hearingDamageFactor), "NUMBER", 1] call CBA_fnc_getConfigEntry; + private _loudness = _hearingDamageFactor * (_caliber ^ 1.25 / 10) * (_initspeed / 1000) / 5; + TRACE_6("building cache",_ammo,_magazine,_initSpeed,_caliber,_hearingDamageFactor,_loudness); _loudness }, true] diff --git a/docs/wiki/framework/hearing-framework.md b/docs/wiki/framework/hearing-framework.md index 4e1131d4a45..308b37bf4b9 100644 --- a/docs/wiki/framework/hearing-framework.md +++ b/docs/wiki/framework/hearing-framework.md @@ -25,3 +25,12 @@ class CfgWeapons { ``` The protection/muffling is a multiplier and not an absolute value, you can still be deafened/muffled with a value of 1. + +```cpp +class CfgAmmo { + class MyAmmo { + ace_hearing_hearingDamageFactor = 0; // Allows to tune how much hearing damage the ammo causes when being fired/exploding (default: 1) + // Example: Removing hearing damage from throwables such as Molotovs + }; +}; +```