Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hearing - Add hearing damage factor attribute to CfgAmmo #10617

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/compat_sog/CfgAmmo/grenades.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 9 additions & 7 deletions addons/hearing/functions/fnc_explosion.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
5 changes: 3 additions & 2 deletions addons/hearing/functions/fnc_getAmmoLoudness.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
9 changes: 9 additions & 0 deletions docs/wiki/framework/hearing-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};
```
Loading