From 0236c16e8fb8ce3d0f54c425cd2b5a4d7c83dfa1 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Thu, 18 Feb 2016 13:48:40 -0300 Subject: [PATCH] Cache volume attenuation due to earplugs and headgear --- addons/hearing/XEH_postInit.sqf | 13 +++++----- .../functions/fnc_updateHearingProtection.sqf | 26 ++++++++++++------- addons/hearing/functions/fnc_updateVolume.sqf | 14 ++-------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index adf5187ac9..dfded663f9 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -11,20 +11,24 @@ GVAR(volume) = 1; GVAR(playerVehAttenuation) = 1; GVAR(time3) = 0; GVAR(damageCoefficent) = 1; +GVAR(volumeAttenuation) = 1; ["SettingsInitialized", { TRACE_1("settingInit",GVAR(EnableCombatDeafness)); // Only run PFEH and install event handlers if combat deafness is enabled if (!GVAR(EnableCombatDeafness)) exitWith {}; + // Update hearing protection now: + [] call FUNC(updateHearingProtection); + // Spawn volume updating process [FUNC(updateVolume), 1, [false]] call CBA_fnc_addPerFrameHandler; - //Update veh attunation when player veh changes + // Update veh attunation when player veh changes ["playerVehicleChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler); ["playerTurretChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler); - //Reset deafness on respawn (or remote control player switch) + // Reset deafness on respawn (or remote control player switch) ["playerChanged", { GVAR(deafnessDV) = 0; GVAR(deafnessPrior) = 0; @@ -33,9 +37,6 @@ GVAR(damageCoefficent) = 1; [] call FUNC(updateHearingProtection); }] call EFUNC(common,addEventhandler); - //Update protection on possible helmet change + // Update protection on possible helmet change ["playerInventoryChanged", {[] call FUNC(updateHearingProtection);}] call EFUNC(common,addEventhandler); - - //Update hearing protection now: - [] call FUNC(updateHearingProtection); }] call EFUNC(common,addEventHandler); diff --git a/addons/hearing/functions/fnc_updateHearingProtection.sqf b/addons/hearing/functions/fnc_updateHearingProtection.sqf index d7726fd681..b1b7df48c5 100644 --- a/addons/hearing/functions/fnc_updateHearingProtection.sqf +++ b/addons/hearing/functions/fnc_updateHearingProtection.sqf @@ -1,6 +1,6 @@ /* * Author: PabstMirror - * Updates the hearing protection for player on earbuds/helmet change + * Updates the hearing protection and volume attenuation for player on earbuds/helmet change * * Arguments: * None @@ -17,12 +17,20 @@ TRACE_1("params",_this); -if (isNull ACE_player) exitWith {GVAR(damageCoefficent) = 0;}; - -GVAR(damageCoefficent) = if (ACE_player getVariable ["ACE_hasEarPlugsin", false]) then {0.25} else {1}; -if (headgear ACE_player != "") then { //headgear hearing protection - private _protection = (getNumber (configFile >> "CfgWeapons" >> (headgear ACE_player) >> QGVAR(protection))) min 1; - if (_protection > 0) then { - GVAR(damageCoefficent) = GVAR(damageCoefficent) * (1 - _protection); - }; +if (isNull ACE_player) exitWith { + GVAR(damageCoefficent) = 0; + GVAR(volumeAttenuation) = 1; +}; + +// Handle Earplugs +private _hasEarPlugsIn = [ACE_player] call FUNC(hasEarPlugsIn); +GVAR(damageCoefficent) = [1, 0.25] select _hasEarPlugsIn; +GVAR(volumeAttenuation) = [1, GVAR(EarplugsVolume)] select _hasEarPlugsIn; + +// Handle Headgear +if (headgear ACE_player != "") then { + private _protection = (getNumber (configFile >> "CfgWeapons" >> (headgear ACE_player) >> QGVAR(protection))) min 1; + GVAR(damageCoefficent) = GVAR(damageCoefficent) * (1 - _protection); + private _attenuation = (getNumber (configFile >> "CfgWeapons" >> (headgear ACE_player) >> QGVAR(lowerVolume))) min 1; + GVAR(volumeAttenuation) = GVAR(volumeAttenuation) * (1 - _attenuation); }; diff --git a/addons/hearing/functions/fnc_updateVolume.sqf b/addons/hearing/functions/fnc_updateVolume.sqf index 4467cbf14c..58eedc7b39 100644 --- a/addons/hearing/functions/fnc_updateVolume.sqf +++ b/addons/hearing/functions/fnc_updateVolume.sqf @@ -46,18 +46,8 @@ if (missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false]) exitWith { private _volume = GVAR(volume); -// Earplugs reduce hearing 50% -if ([ACE_player] call FUNC(hasEarPlugsIn)) then { - _volume = _volume min GVAR(EarplugsVolume); -}; - -// Headgear can reduce hearing -if (headgear ACE_player != "") then { - private _lowerVolume = (getNumber (configFile >> "CfgWeapons" >> (headgear ACE_player) >> QGVAR(lowerVolume))) min 1; - if (_lowerVolume > 0) then { - _volume = _volume min (1 - _lowerVolume); - }; -}; +// Earplugs and headgear can attenuate hearing +_volume = _volume min GVAR(volumeAttenuation); // Reduce volume if player is unconscious if (ACE_player getVariable ["ACE_isUnconscious", false]) then {