Calculate hearing protection coefficient on events

This commit is contained in:
PabstMirror 2016-02-16 18:17:42 -06:00
parent 8fed9325c9
commit 649b0c28e2
6 changed files with 57 additions and 30 deletions

View File

@ -10,24 +10,30 @@ GVAR(deafnessPrior) = 0;
GVAR(volume) = 1; GVAR(volume) = 1;
GVAR(playerVehAttenuation) = 1; GVAR(playerVehAttenuation) = 1;
GVAR(time3) = 0; GVAR(time3) = 0;
GVAR(damageCoefficent) = 1;
["SettingsInitialized", { ["SettingsInitialized", {
TRACE_1("settingInit",GVAR(EnableCombatDeafness)); TRACE_1("settingInit",GVAR(EnableCombatDeafness));
// Only run if combat deafness is enabled // Only run PFEH and install event handlers if combat deafness is enabled
if (!GVAR(EnableCombatDeafness)) exitWith {}; if (!GVAR(EnableCombatDeafness)) exitWith {};
// Spawn volume updating process // Spawn volume updating process
[FUNC(updateVolume), 1, [false]] call CBA_fnc_addPerFrameHandler; [FUNC(updateVolume), 1, [false]] call CBA_fnc_addPerFrameHandler;
}] call EFUNC(common,addEventHandler);
//Update veh attunation when player veh changes //Update veh attunation when player veh changes
["playerVehicleChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler); ["playerVehicleChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler);
["playerTurretChanged", {_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", { ["playerChanged", {
GVAR(deafnessDV) = 0; GVAR(deafnessDV) = 0;
GVAR(deafnessPrior) = 0; GVAR(deafnessPrior) = 0;
ACE_player setVariable [QGVAR(deaf), false]; ACE_player setVariable [QGVAR(deaf), false];
GVAR(time3) = 0; GVAR(time3) = 0;
}] call EFUNC(common,addEventhandler); [] call FUNC(updateHearingProtection);
}] call EFUNC(common,addEventhandler);
//Update protection on possible helmet change
["playerInventoryChanged", {[] call FUNC(updateHearingProtection);}] call EFUNC(common,addEventhandler);
}] call EFUNC(common,addEventHandler);

View File

@ -11,6 +11,7 @@ PREP(hasEarPlugsIn);
PREP(moduleHearing); PREP(moduleHearing);
PREP(putInEarPlugs); PREP(putInEarPlugs);
PREP(removeEarPlugs); PREP(removeEarPlugs);
PREP(updateHearingProtection);
PREP(updatePlayerVehAttenuation); PREP(updatePlayerVehAttenuation);
PREP(updateVolume); PREP(updateVolume);

View File

@ -1,15 +1,15 @@
/* /*
* Author: KoffeinFlummi, commy2, Rocko, Rommel, Ruthberg * Author: KoffeinFlummi, commy2, Rocko, Rommel, Ruthberg
* Handle new sound souce near player and apply hearing damage * Handle new sound souce near ace_player and apply hearing damage
* *
* Arguments: * Arguments:
* 0: strength of ear ringing (Number between 0 and 1) <NUMBER> * 0: strength of ear ringing <NUMBER>
* *
* Return Value: * Return Value:
* None * None
* *
* Example: * Example:
* [_unit, _strength] call ace_hearing_fnc_earRinging * [_strength] call ace_hearing_fnc_earRinging
* *
* Public: No * Public: No
*/ */
@ -20,18 +20,6 @@ if (_strength < 0.05) exitWith {};
if (!isNull curatorCamera) exitWith {}; if (!isNull curatorCamera) exitWith {};
if ((!GVAR(enabledForZeusUnits)) && {player != ACE_player}) exitWith {}; if ((!GVAR(enabledForZeusUnits)) && {player != ACE_player}) exitWith {};
if (_unit getVariable ["ACE_hasEarPlugsin", false]) then { TRACE_2("adding",_strength * GVAR(damageCoefficent),GVAR(deafnessDV));
_strength = _strength / 4;
};
//headgear hearing protection GVAR(deafnessDV) = GVAR(deafnessDV) + (_strength * GVAR(damageCoefficent));
if (headgear _unit != "") then {
private _protection = (getNumber (configFile >> "CfgWeapons" >> (headgear _unit) >> QGVAR(protection))) min 1;
if (_protection > 0) then {
_strength = _strength * (1 - _protection);
};
};
TRACE_2("adding",_strength,GVAR(deafnessDV));
GVAR(deafnessDV) = GVAR(deafnessDV) + _strength;

View File

@ -29,3 +29,5 @@ _player setVariable ["ACE_hasEarPlugsIn", true, true];
/*// No Earplugs in inventory, telling user /*// No Earplugs in inventory, telling user
[localize LSTRING(NoPlugs)] call EFUNC(common,displayTextStructured);*/ [localize LSTRING(NoPlugs)] call EFUNC(common,displayTextStructured);*/
[] call FUNC(updateHearingProtection);

View File

@ -30,3 +30,5 @@ _player setVariable ["ACE_hasEarPlugsIn", false, true];
//Force an immediate fast volume update: //Force an immediate fast volume update:
[[true]] call FUNC(updateVolume); [[true]] call FUNC(updateVolume);
[] call FUNC(updateHearingProtection);

View File

@ -0,0 +1,28 @@
/*
* Author: PabstMirror
* Updates the hearing protection for player on earbuds/helmet change
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_hearing_fnc_updateHearingProtection
*
* Public: No
*/
#include "script_component.hpp"
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);
};
};