From 589c85782fa79833ffa824c3dde219d609f2a4df Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Thu, 9 May 2024 18:17:42 +0200 Subject: [PATCH 1/7] Have explosions affect hearing --- addons/hearing/XEH_PREP.hpp | 2 +- addons/hearing/XEH_postInit.sqf | 15 ++++--- addons/hearing/functions/fnc_explosion.sqf | 44 +++++++++++++++++++ .../hearing/functions/fnc_explosionNear.sqf | 27 ------------ 4 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 addons/hearing/functions/fnc_explosion.sqf delete mode 100644 addons/hearing/functions/fnc_explosionNear.sqf diff --git a/addons/hearing/XEH_PREP.hpp b/addons/hearing/XEH_PREP.hpp index e06fa5d56c0..b1a210a8159 100644 --- a/addons/hearing/XEH_PREP.hpp +++ b/addons/hearing/XEH_PREP.hpp @@ -1,7 +1,7 @@ PREP(addEarPlugs); PREP(earRinging); -PREP(explosionNear); +PREP(explosion); PREP(firedNear); PREP(handleRespawn); PREP(hasEarPlugsIn); diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index e6f328ad78c..970ce4ea875 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -67,10 +67,7 @@ GVAR(lastPlayerVehicle) = objNull; private _firedEH = _oldPlayer getVariable [QGVAR(firedEH), -1]; _oldPlayer removeEventHandler ["FiredNear", _firedEH]; _oldPlayer setVariable [QGVAR(firedEH), nil]; - private _explosionEH = _oldPlayer getVariable [QGVAR(explosionEH), -1]; - _oldPlayer removeEventHandler ["Explosion", _explosionEH]; - _oldPlayer setVariable [QGVAR(explosionEH), nil]; - TRACE_3("removed unit eh",_oldPlayer,_firedEH,_explosionEH); + TRACE_2("removed unit eh",_oldPlayer,_firedEH); }; // Don't add a new EH if the unit respawned if ((_player getVariable [QGVAR(firedEH), -1]) == -1) then { @@ -79,9 +76,7 @@ GVAR(lastPlayerVehicle) = objNull; }; private _firedEH = _player addEventHandler ["FiredNear", {call FUNC(firedNear)}]; _player setVariable [QGVAR(firedEH), _firedEH]; - private _explosionEH = _player addEventHandler ["Explosion", {call FUNC(explosionNear)}]; - _player setVariable [QGVAR(explosionEH), _explosionEH]; - TRACE_3("added unit eh",_player,_firedEH,_explosionEH); + TRACE_2("added unit eh",_player,_firedEH); }; GVAR(deafnessDV) = 0; @@ -90,6 +85,12 @@ GVAR(lastPlayerVehicle) = objNull; [] call FUNC(updateHearingProtection); }, true] call CBA_fnc_addPlayerEventHandler; + addMissionEventHandler ["ProjectileCreated", { + params ["_projectile"]; + + _projectile addEventHandler ["Explode", {call FUNC(explosion)}]; + }]; + // Update protection on possible helmet change ["loadout", LINKFUNC(updateHearingProtection), false] call CBA_fnc_addPlayerEventHandler; }] call CBA_fnc_addEventHandler; diff --git a/addons/hearing/functions/fnc_explosion.sqf b/addons/hearing/functions/fnc_explosion.sqf new file mode 100644 index 00000000000..f6bf6a548f8 --- /dev/null +++ b/addons/hearing/functions/fnc_explosion.sqf @@ -0,0 +1,44 @@ +#include "..\script_component.hpp" +/* + * Author: johnb43 + * Handles deafness due to explosions going off near the player. + * + * Arguments: + * 0: Projectile + * 1: Explosion position ASL + * 2: Velocity (unused) + * + * Return Value: + * None + * + * Example: + * [_projectile, [0, 0, 0], [0, 0, 0]] call ace_hearing_fnc_explosion + * + * Public: No + */ + +params ["_projectile", "_pos"]; + +// Don't allow for distances under 1 +private _distance = ((eyePos ACE_player) vectorDistance _pos) max 1; +private _ammoConfig = configOf _projectile; +private _audibleFire = getNumber (_ammoConfig >> "audibleFire"); +private _explosive = getNumber (_ammoConfig >> "explosive") * 300; + +private _vehAttenuation = [GVAR(playerVehAttenuation), 1] select (isNull objectParent ACE_player || {isTurnedOut ACE_player}); + +TRACE_5("",typeOf _projectile,_distance,_explosive,_audibleFire,_vehAttenuation); + +// Handles grenades differently from shells and other +_distance = if (_projectile isKindOf "Grenade") then { + _distance / 4 +} else { + _distance ^ linearConversion [1, 30, _distance, 1, 2.5, true] +}; + +private _strength = _vehAttenuation * _audibleFire / _distance * _explosive; + +TRACE_2("adjusted distance",_distance,_strength); + +// Call inmediately, as it will get pick up later anyway by the update thread +[_strength] call FUNC(earRinging); diff --git a/addons/hearing/functions/fnc_explosionNear.sqf b/addons/hearing/functions/fnc_explosionNear.sqf deleted file mode 100644 index c65cf31c764..00000000000 --- a/addons/hearing/functions/fnc_explosionNear.sqf +++ /dev/null @@ -1,27 +0,0 @@ -#include "..\script_component.hpp" -/* - * Author: KoffeinFlummi, commy2, Ruthberg - * Handles deafness due to explosions going off near the player. - * - * Arguments: - * 0: vehicle - Object the event handler is assigned to (player) - * 1: damage - Damage inflicted to the object - * - * Return Value: - * None - * - * Example: - * [clientExplosionEvent] call ace_hearing_fnc_explosionNear - * - * Public: No - */ - -params ["_unit", "_damage"]; - -TRACE_2("explosion near player",_unit,_damage); - -private _strength = (0 max _damage) * 30; -if (_strength < 0.01) exitWith {}; - -// Call inmediately, as it will get pick up later anyway by the update thread -[_strength] call FUNC(earRinging); From ba7cbbc53c1973b0cbc6e86e9f64758b8013cb22 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Thu, 9 May 2024 18:17:57 +0200 Subject: [PATCH 2/7] Update fnc_explosion.sqf --- addons/hearing/functions/fnc_explosion.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hearing/functions/fnc_explosion.sqf b/addons/hearing/functions/fnc_explosion.sqf index f6bf6a548f8..2aac21d1b7d 100644 --- a/addons/hearing/functions/fnc_explosion.sqf +++ b/addons/hearing/functions/fnc_explosion.sqf @@ -29,7 +29,7 @@ private _vehAttenuation = [GVAR(playerVehAttenuation), 1] select (isNull objectP TRACE_5("",typeOf _projectile,_distance,_explosive,_audibleFire,_vehAttenuation); -// Handles grenades differently from shells and other +// Handle grenades differently from shells and other _distance = if (_projectile isKindOf "Grenade") then { _distance / 4 } else { From 034fea91d189118d1c4d0bfe2b0f809ff64454fd Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Thu, 9 May 2024 18:24:32 +0200 Subject: [PATCH 3/7] Update XEH_postInit.sqf --- addons/hearing/XEH_postInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index 970ce4ea875..0c91b8bfd55 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -86,7 +86,7 @@ GVAR(lastPlayerVehicle) = objNull; }, true] call CBA_fnc_addPlayerEventHandler; addMissionEventHandler ["ProjectileCreated", { - params ["_projectile"]; + params ["_projectile"]; _projectile addEventHandler ["Explode", {call FUNC(explosion)}]; }]; From ef5d2dacf22237a09370243d3ace15efdddf101f Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 27 May 2024 23:46:31 -0700 Subject: [PATCH 4/7] Update addons/hearing/functions/fnc_explosion.sqf Co-authored-by: PabstMirror --- addons/hearing/functions/fnc_explosion.sqf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/hearing/functions/fnc_explosion.sqf b/addons/hearing/functions/fnc_explosion.sqf index 2aac21d1b7d..d71579cd19c 100644 --- a/addons/hearing/functions/fnc_explosion.sqf +++ b/addons/hearing/functions/fnc_explosion.sqf @@ -21,6 +21,8 @@ params ["_projectile", "_pos"]; // Don't allow for distances under 1 private _distance = ((eyePos ACE_player) vectorDistance _pos) max 1; +if (_distance > 100) exitWith {}; // fast exit if explosion far away +if ((getNumber (configOf ACE_player>> "isPlayableLogic")) == 1) exitWith {}; private _ammoConfig = configOf _projectile; private _audibleFire = getNumber (_ammoConfig >> "audibleFire"); private _explosive = getNumber (_ammoConfig >> "explosive") * 300; From 8fa91656c5f5af470918618b3931342f11a3c904 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Tue, 28 May 2024 23:14:17 +0200 Subject: [PATCH 5/7] Update fnc_explosion.sqf --- addons/hearing/functions/fnc_explosion.sqf | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/hearing/functions/fnc_explosion.sqf b/addons/hearing/functions/fnc_explosion.sqf index d71579cd19c..239b29dc485 100644 --- a/addons/hearing/functions/fnc_explosion.sqf +++ b/addons/hearing/functions/fnc_explosion.sqf @@ -17,12 +17,17 @@ * 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; -if (_distance > 100) exitWith {}; // fast exit if explosion far away -if ((getNumber (configOf ACE_player>> "isPlayableLogic")) == 1) exitWith {}; + +// Fast exit if explosion far away +if (_distance > 100) exitWith {}; + private _ammoConfig = configOf _projectile; private _audibleFire = getNumber (_ammoConfig >> "audibleFire"); private _explosive = getNumber (_ammoConfig >> "explosive") * 300; @@ -42,5 +47,5 @@ private _strength = _vehAttenuation * _audibleFire / _distance * _explosive; TRACE_2("adjusted distance",_distance,_strength); -// Call inmediately, as it will get pick up later anyway by the update thread -[_strength] call FUNC(earRinging); +// Call immediately, as it will get pick up later anyway by the update thread +_strength call FUNC(earRinging); From d13d48771766ec01efde5861e7c19b2c7f998266 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Fri, 7 Jun 2024 20:07:09 +0200 Subject: [PATCH 6/7] Make EH local --- addons/hearing/XEH_postInit.sqf | 8 +++++++- addons/hearing/functions/fnc_explosion.sqf | 16 ++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index c53b572844a..e0bee153f80 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -35,6 +35,7 @@ GVAR(lastPlayerVehicle) = objNull; // Spawn volume updating process [LINKFUNC(updateVolume), 1, false] call CBA_fnc_addPerFrameHandler; + [QGVAR(explosion), LINKFUNC(explosion)] call CBA_fnc_addEventHandler; [QGVAR(updateVolume), LINKFUNC(updateVolume)] call CBA_fnc_addEventHandler; // Update veh attunation when player veh changes @@ -94,7 +95,12 @@ GVAR(lastPlayerVehicle) = objNull; addMissionEventHandler ["ProjectileCreated", { params ["_projectile"]; - _projectile addEventHandler ["Explode", {call FUNC(explosion)}]; + if (!local _projectile) exitWith {}; + + // Rockets only explode on local clients + _projectile addEventHandler ["Explode", { + [QGVAR(explosion), _this] call CBA_fnc_globalEvent; + }]; }]; // Update protection on possible helmet change diff --git a/addons/hearing/functions/fnc_explosion.sqf b/addons/hearing/functions/fnc_explosion.sqf index 239b29dc485..b7bf92b45d1 100644 --- a/addons/hearing/functions/fnc_explosion.sqf +++ b/addons/hearing/functions/fnc_explosion.sqf @@ -17,8 +17,10 @@ * Public: No */ +#define STRENGTH_MULTIPLIER 300 + // Ignore spectators, curators and alike -if ((getNumber (configOf ACE_player>> "isPlayableLogic")) == 1) exitWith {}; +if ((getNumber (configOf ACE_player >> "isPlayableLogic")) == 1) exitWith {}; params ["_projectile", "_pos"]; @@ -26,26 +28,28 @@ params ["_projectile", "_pos"]; private _distance = ((eyePos ACE_player) vectorDistance _pos) max 1; // Fast exit if explosion far away -if (_distance > 100) exitWith {}; +if (_distance > 100) exitWith { + TRACE_1("too far away",_distance); +}; private _ammoConfig = configOf _projectile; private _audibleFire = getNumber (_ammoConfig >> "audibleFire"); -private _explosive = getNumber (_ammoConfig >> "explosive") * 300; +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); // Handle grenades differently from shells and other -_distance = if (_projectile isKindOf "Grenade") then { +_distance = if (_projectile isKindOf "Grenade" || {_projectile isKindOf "GrenadeCore"}) then { _distance / 4 } else { _distance ^ linearConversion [1, 30, _distance, 1, 2.5, true] }; -private _strength = _vehAttenuation * _audibleFire / _distance * _explosive; +private _strength = _vehAttenuation * _audibleFire / _distance * _explosive * STRENGTH_MULTIPLIER; TRACE_2("adjusted distance",_distance,_strength); -// Call immediately, as it will get pick up later anyway by the update thread +// Call immediately, as it will get picked up later by the update thread anyway _strength call FUNC(earRinging); From 54f52596a67d728560b345247eb357e7c6bd08d5 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Fri, 28 Jun 2024 19:27:15 +0200 Subject: [PATCH 7/7] Use sound entry instead --- addons/hearing/functions/fnc_explosion.sqf | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/hearing/functions/fnc_explosion.sqf b/addons/hearing/functions/fnc_explosion.sqf index b7bf92b45d1..159f6660114 100644 --- a/addons/hearing/functions/fnc_explosion.sqf +++ b/addons/hearing/functions/fnc_explosion.sqf @@ -17,8 +17,6 @@ * Public: No */ -#define STRENGTH_MULTIPLIER 300 - // Ignore spectators, curators and alike if ((getNumber (configOf ACE_player >> "isPlayableLogic")) == 1) exitWith {}; @@ -33,23 +31,25 @@ if (_distance > 100) exitWith { }; private _ammoConfig = configOf _projectile; -private _audibleFire = getNumber (_ammoConfig >> "audibleFire"); 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); -// Handle grenades differently from shells and other -_distance = if (_projectile isKindOf "Grenade" || {_projectile isKindOf "GrenadeCore"}) then { - _distance / 4 +(if (isArray (_ammoConfig >> "soundHit1")) then { + getArray (_ammoConfig >> "soundHit1") } else { - _distance ^ linearConversion [1, 30, _distance, 1, 2.5, true] + getArray (_ammoConfig >> "soundHit") +}) params ["", ["_volume", 1], "", ["_maxDistance", 1500]]; + +if (_distance > _maxDistance) exitWith { + TRACE_2("too far away",_distance,_maxDistance); }; -private _strength = _vehAttenuation * _audibleFire / _distance * _explosive * STRENGTH_MULTIPLIER; +private _strength = _vehAttenuation * _explosive * _volume * _maxDistance / _distance^2; -TRACE_2("adjusted distance",_distance,_strength); +TRACE_2("strength",_volume,_strength); // Call immediately, as it will get picked up later by the update thread anyway _strength call FUNC(earRinging);