ACE3/addons/hearing/functions/fnc_explosion.sqf
johnb432 72f230a3a2
Hearing - Fix explosions not affecting hearing (#10002)
* Have explosions affect hearing

* Update fnc_explosion.sqf

* Update XEH_postInit.sqf

* Update addons/hearing/functions/fnc_explosion.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Update fnc_explosion.sqf

* Make EH local

* Use sound entry instead

---------

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2024-08-12 06:45:03 -07:00

56 lines
1.6 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: johnb43
* Handles deafness due to explosions going off near the player.
*
* Arguments:
* 0: Projectile <OBJECT>
* 1: Explosion position ASL <ARRAY>
* 2: Velocity <ARRAY> (unused)
*
* Return Value:
* None
*
* Example:
* [_projectile, [0, 0, 0], [0, 0, 0]] call ace_hearing_fnc_explosion
*
* Public: No
*/
// Ignore spectators, curators and alike
if ((getNumber (configOf ACE_player >> "isPlayableLogic")) == 1) exitWith {};
params ["_projectile", "_pos"];
// Don't allow for distances under 1
private _distance = ((eyePos ACE_player) vectorDistance _pos) max 1;
// Fast exit if explosion far away
if (_distance > 100) exitWith {
TRACE_1("too far away",_distance);
};
private _ammoConfig = configOf _projectile;
private _explosive = getNumber (_ammoConfig >> "explosive");
private _vehAttenuation = [GVAR(playerVehAttenuation), 1] select (isNull objectParent ACE_player || {isTurnedOut ACE_player});
TRACE_5("",typeOf _projectile,_distance,_explosive,_audibleFire,_vehAttenuation);
(if (isArray (_ammoConfig >> "soundHit1")) then {
getArray (_ammoConfig >> "soundHit1")
} else {
getArray (_ammoConfig >> "soundHit")
}) params ["", ["_volume", 1], "", ["_maxDistance", 1500]];
if (_distance > _maxDistance) exitWith {
TRACE_2("too far away",_distance,_maxDistance);
};
private _strength = _vehAttenuation * _explosive * _volume * _maxDistance / _distance^2;
TRACE_2("strength",_volume,_strength);
// Call immediately, as it will get picked up later by the update thread anyway
_strength call FUNC(earRinging);