diff --git a/addons/hearing/CfgSounds.hpp b/addons/hearing/CfgSounds.hpp index ac64f42c4e..8c6d6965df 100644 --- a/addons/hearing/CfgSounds.hpp +++ b/addons/hearing/CfgSounds.hpp @@ -11,4 +11,12 @@ class CfgSounds { sound[] = {QUOTE(PATHTOF(sounds\ACE_earringing_heavy.wav)),8,1.7}; titles[] = {}; }; + class ACE_Combat_Deafness { + sound[] = {QUOTE(PATHTOF(sounds\deafness.ogg)),2,1}; + titles[] = {}; + }; + class ACE_Ring_Backblast { + sound[] = {QUOTE(PATHTOF(sounds\backblast_ring.ogg)),1,1}; + titles[] = {}; + }; }; diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index 01b05e5f50..0c727e08df 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -6,6 +6,13 @@ GVAR(currentDeafness) = 0; GVAR(newStrength) = 0; GVAR(playerVehAttenuation) = 1; +GVAR(beep) = false; +GVAR(beep2) = false; +GVAR(time2) = 0; +GVAR(time3) = 0; +GVAR(time4) = 0; +GVAR(earRingingPFH) = -1; + // Spawn volume updating process [FUNC(updateVolume), 0.1, [] ] call CBA_fnc_addPerFrameHandler; @@ -15,6 +22,13 @@ GVAR(playerVehAttenuation) = 1; //Reset deafness on respawn (or remote control player switch) ["playerChanged", { + ACE_player setVariable [QGVAR(dv), 0]; + ACE_player setVariable [QGVAR(prior), 0]; + GVAR(beep) = false; + GVAR(beep2) = false; + GVAR(time2) = 0; + GVAR(time3) = 0; + GVAR(time4) = 0; GVAR(currentDeafness) = 0; GVAR(newStrength) = 0; }] call EFUNC(common,addEventhandler); diff --git a/addons/hearing/config.cpp b/addons/hearing/config.cpp index 777c44dd8f..1007b2095d 100644 --- a/addons/hearing/config.cpp +++ b/addons/hearing/config.cpp @@ -6,7 +6,7 @@ class CfgPatches { weapons[] = {"ACE_EarPlugs"}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"ace_interaction"}; - author[] = {"KoffeinFlummi", "esteldunedain", "HopeJ", "commy2"}; + author[] = {"KoffeinFlummi", "esteldunedain", "HopeJ", "commy2", "Rocko", "Rommel", "Ruthberg"}; authorUrl = "https://github.com/KoffeinFlummi/"; VERSION_CONFIG; }; diff --git a/addons/hearing/functions/fnc_earRinging.sqf b/addons/hearing/functions/fnc_earRinging.sqf index 2460e0fd5c..8e3c08b30d 100644 --- a/addons/hearing/functions/fnc_earRinging.sqf +++ b/addons/hearing/functions/fnc_earRinging.sqf @@ -1,56 +1,93 @@ /* - * Author: KoffeinFlummi, commy2 - * Creates ear ringing effect with set strength. + * Author: KoffeinFlummi, commy2, Rocko, Rommel, Ruthberg + * Ear ringing PFH * * Arguments: - * 0: Unit (player) + * 0: unit * 1: strength of ear ringing (Number between 0 and 1) * * Return Value: * None * * Example: - * [clientExplosionEvent] call ace_hearing_fnc_earRinging + * [_unit, _strength] call ace_hearing_fnc_earRinging * * Public: No */ #include "script_component.hpp" -private ["_unit", "_strength"]; +if (GVAR(DisableEarRinging)) exitWith {}; -_unit = _this select 0; -_strength = _this select 1; +PARAMS_2(_unit,_strength); + +if (isNull _unit) exitWith {}; +if (_strength < 0.05) exitWith {}; if (_unit getVariable ["ACE_hasEarPlugsin", false]) then { _strength = _strength / 4; }; -GVAR(newStrength) = GVAR(newStrength) max _strength; +_unit setVariable [QGVAR(dv), (_unit getVariable [QGVAR(dv), 0]) + _strength]; -if (missionNamespace getVariable [QGVAR(isEarRingingPlaying), false]) exitWith {}; +if (GVAR(earRingingPFH) != -1) exitWith {}; +GVAR(earRingingPFH) = [{ + EXPLODE_1_PVT(_this select 0,_unit); + private ["_prior"]; + _prior = (_unit getvariable [QGVAR(dv), 0]) min 20; + hintSilent Str(_prior); + if (!alive _unit || _prior <= 0) exitWith { + _unit setVariable [QGVAR(dv), 0]; + _unit setVariable [QGVAR(prior), 0]; + GVAR(beep) = false; + GVAR(beep2) = false; + GVAR(time2) = 0; + GVAR(time3) = 0; + GVAR(time4) = 0; + GVAR(earRingingPFH) = -1; + [_this select 1] call cba_fnc_removePerFrameHandler; + }; + + if (((_unit getvariable [QGVAR(dv), 0]) - (_unit getvariable [QGVAR(prior), 0])) > 2) then { + if (ACE_time > GVAR(time3)) then { + GVAR(beep2) = false; + }; + if (!GVAR(beep2)) then { + systemChat format["Deafness %1", ((_unit getvariable [QGVAR(dv), 0]) - (_unit getvariable [QGVAR(prior), 0]))]; + playSound "ACE_Combat_Deafness"; + GVAR(beep2) = true; + GVAR(time3) = ACE_time + 5; + }; + }; + + _unit setvariable [QGVAR(prior), _prior]; + GVAR(volume) = (1 - (_prior / 20)) max 0; + + if (_prior > 19.75) then { + _unit setvariable [QGVAR(deaf), true]; + } else { + _unit setvariable [QGVAR(deaf), false]; + }; + + if ((_unit getvariable [QGVAR(deaf), false]) && {ACE_time > GVAR(time4)}) then { + playSound "ACE_Combat_Deafness"; + GVAR(beep2) = true; + GVAR(time3) = ACE_time + 10; + GVAR(time4) = ACE_time + 30; + }; -if (GVAR(DisableEarRinging)) exitWith {}; - -if (_strength > 0.75) exitWith { - playSound "ACE_EarRinging_Heavy"; - GVAR(isEarRingingPlaying) = true; - [ - {GVAR(isEarRingingPlaying) = false;}, [], 7.0, 0.25 - ] call EFUNC(common,waitAndExecute); -}; -if (_strength > 0.5) exitWith { - playSound "ACE_EarRinging_Medium"; - GVAR(isEarRingingPlaying) = true; - [ - {GVAR(isEarRingingPlaying) = false;}, [], 5.0, 0.25 - ] call EFUNC(common,waitAndExecute); -}; -if (_strength > 0.2) exitWith { - playSound "ACE_EarRinging_Weak"; - GVAR(isEarRingingPlaying) = true; - GVAR(isEarRingingPlaying) = true; - [ - {GVAR(isEarRingingPlaying) = false;}, [], 3.0, 0.25 - ] call EFUNC(common,waitAndExecute); -}; + // Hearing takes longer to return to normal after it hits rock bottom + _unit setvariable [QGVAR(dv), _prior - (0.5 * (GVAR(volume) max 0.1))]; + + if (_prior > 10) then { + //check if the ringing is already being played + if (ACE_time > GVAR(time2)) then { + GVAR(beep) = false; + }; + if (!GVAR(beep)) then { + playSound "ACE_Ring_Backblast"; + GVAR(time2) = ACE_time + 22; + GVAR(beep) = true; + }; + }; +}, 1, [_unit]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/hearing/functions/fnc_explosionNear.sqf b/addons/hearing/functions/fnc_explosionNear.sqf index b213a1304a..cb9202618f 100644 --- a/addons/hearing/functions/fnc_explosionNear.sqf +++ b/addons/hearing/functions/fnc_explosionNear.sqf @@ -1,5 +1,5 @@ /* - * Author: KoffeinFlummi, commy2 + * Author: KoffeinFlummi, commy2, Ruthberg * Handles deafness due to explosions going off near the player. * * Arguments: @@ -16,12 +16,10 @@ */ #include "script_component.hpp" -private ["_unit", "_damage", "_strength"]; +PARAMS_2(_unit,_damage); -_unit = _this select 0; -_damage = _this select 1; - -_strength = (_damage * 2) min 1; +private ["_strength"]; +_strength = 0 max _damage; if (_strength < 0.01) exitWith {}; [{_this call FUNC(earRinging)}, [_unit, _strength], 0.2, 0] call EFUNC(common,waitAndExecute); diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index b456b3b872..56d4214838 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -47,10 +47,12 @@ if (_silencer != "") then { _audibleFireCoef = getNumber (configFile >> "CfgWeapons" >> _silencer >> "ItemInfo" >> "AmmoCoef" >> "audibleFire"); }; -_audibleFire = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFire"); - -_loudness = _audibleFireCoef * _audibleFire / 64; -_strength = _vehAttenuation * (_loudness - (_loudness/50 * _distance)); // linear drop off +_magazine = (getArray(configFile >> "CfgWeapons" >> _weapon >> "magazines")) select 0; +_initSpeed = getNumber(configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); +_caliber = getNumber(configFile >> "CfgAmmo" >> _ammo >> "ACE_caliber"); +if (_caliber <= 0) then { _caliber = 6.5; }; +_loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) * _audibleFireCoef / 5; +_strength = _vehAttenuation * (_loudness - (_loudness / 50 * _distance)); // linear drop off if (_strength < 0.01) exitWith {}; diff --git a/addons/hearing/functions/fnc_updateVolume.sqf b/addons/hearing/functions/fnc_updateVolume.sqf index 2e1db5c770..b89becf10b 100644 --- a/addons/hearing/functions/fnc_updateVolume.sqf +++ b/addons/hearing/functions/fnc_updateVolume.sqf @@ -1,5 +1,5 @@ /* - * Author: commy2 and esteldunedain + * Author: commy2 and esteldunedain and Ruthberg * Updates and applys the current deafness. Called every 0.1 sec from a PFEH. * * Arguments: @@ -15,19 +15,17 @@ */ #include "script_component.hpp" -#define STRENGHTODEAFNESS 3 -#define MAXDEAFNESS 1.1 - private ["_recoverRate", "_volume"]; // Exit if combat deafness is disabled if !(GVAR(enableCombatDeafness)) exitWith {}; // Check if new noises increase deafness -if (GVAR(newStrength) * STRENGHTODEAFNESS > GVAR(currentDeafness)) then { - GVAR(currentDeafness) = GVAR(newStrength) * STRENGHTODEAFNESS min MAXDEAFNESS; +GVAR(newStrength) = (((ACE_player getvariable [QGVAR(dv), 0]) min 20) / 20) ^ 2; +systemChat Str(GVAR(newStrength)); +if (GVAR(newStrength) > GVAR(currentDeafness)) then { + GVAR(currentDeafness) = GVAR(newStrength); }; -GVAR(newStrength) = 0; // Recover rate is slower if deafness is severe _recoverRate = 0.01; diff --git a/addons/hearing/sounds/backblast_ring.ogg b/addons/hearing/sounds/backblast_ring.ogg new file mode 100644 index 0000000000..8d6207e326 Binary files /dev/null and b/addons/hearing/sounds/backblast_ring.ogg differ diff --git a/addons/hearing/sounds/deafness.ogg b/addons/hearing/sounds/deafness.ogg new file mode 100644 index 0000000000..52314e374e Binary files /dev/null and b/addons/hearing/sounds/deafness.ogg differ diff --git a/addons/hearing/sounds/flashbang_ring.ogg b/addons/hearing/sounds/flashbang_ring.ogg new file mode 100644 index 0000000000..0374cb413c Binary files /dev/null and b/addons/hearing/sounds/flashbang_ring.ogg differ diff --git a/addons/hearing/sounds/muzzleblast_ring1.ogg b/addons/hearing/sounds/muzzleblast_ring1.ogg new file mode 100644 index 0000000000..c164e93c02 Binary files /dev/null and b/addons/hearing/sounds/muzzleblast_ring1.ogg differ diff --git a/addons/hearing/sounds/muzzleblast_ring2.ogg b/addons/hearing/sounds/muzzleblast_ring2.ogg new file mode 100644 index 0000000000..3b6331e011 Binary files /dev/null and b/addons/hearing/sounds/muzzleblast_ring2.ogg differ