Hearing - Merge PFEH (ringing/volume)

This commit is contained in:
PabstMirror 2015-07-10 21:01:32 -05:00
parent 4e5368ba93
commit d11fa939e1
5 changed files with 66 additions and 98 deletions

View File

@ -2,8 +2,8 @@
if (!hasInterface) exitWith {};
GVAR(currentDeafness) = 0;
GVAR(newStrength) = 0;
GVAR(deafnessDV) = 0;
GVAR(deafnessPrior) = 0;
GVAR(playerVehAttenuation) = 1;
GVAR(beep) = false;
@ -11,10 +11,15 @@ 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;
["SettingsInitialized", {
//If not enabled, dont't add draw eventhandler or PFEH (for performance)
if (!GVAR(enableCombatDeafness)) exitWith {};
// Spawn volume updating process
[FUNC(updateVolume), 1, [] ] call CBA_fnc_addPerFrameHandler;
}] call EFUNC(common,addEventHandler);
//Update veh attunation when player veh changes
["playerVehicleChanged", {_this call FUNC(updatePlayerVehAttenuation);}] call EFUNC(common,addEventHandler);
@ -22,14 +27,13 @@ GVAR(earRingingPFH) = -1;
//Reset deafness on respawn (or remote control player switch)
["playerChanged", {
ACE_player setVariable [QGVAR(dv), 0];
ACE_player setVariable [QGVAR(prior), 0];
GVAR(deafnessDV) = 0;
GVAR(deafnessPrior) = 0;
ACE_player setvariable [QGVAR(deaf), false];
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);

View File

@ -20,7 +20,7 @@ if (GVAR(DisableEarRinging)) exitWith {};
PARAMS_2(_unit,_strength);
if (isNull _unit) exitWith {};
if (_unit != ACE_player) exitWith {};
if (_strength < 0.05) exitWith {};
if (_unit getVariable ["ACE_hasEarPlugsin", false]) then {
@ -36,66 +36,4 @@ if(headgear _unit != "") then {
};
};
_unit setVariable [QGVAR(dv), (_unit getVariable [QGVAR(dv), 0]) + _strength];
if (GVAR(earRingingPFH) != -1) exitWith {};
GVAR(earRingingPFH) = [{
EXPLODE_1_PVT(_this select 0,_unit);
private ["_prior"];
_prior = (_unit getvariable [QGVAR(dv), 0]) min 20;
if (!alive _unit || _prior <= 0 || GVAR(DisableEarRinging)) 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 {
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;
};
// 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;
GVAR(deafnessDV) = GVAR(deafnessDV) + _strength;

View File

@ -16,6 +16,9 @@
*/
#include "script_component.hpp"
//Only run if combatDeafness enabled:
if (!GVAR(enableCombatDeafness)) exitWith {};
PARAMS_2(_unit,_damage);
private ["_strength"];

View File

@ -21,17 +21,18 @@
*/
#include "script_component.hpp"
private ["_silencer", "_audibleFireCoef", "_loudness", "_strength", "_vehAttenuation", "_magazine", "_muzzles", "_weaponMagazines", "_muzzleMagazines", "_ammoType", "_initSpeed", "_ammoConfig", "_caliber", "_parentClasses"];
//Only run if combatDeafness enabled:
if (!GVAR(enableCombatDeafness)) exitWith {};
PARAMS_7(_object,_firer,_distance,_weapon,_muzzle,_mode,_ammo);
//Only run if combatDeafness enabled:
if (!GVAR(enableCombatDeafness)) exitWith {};
//Only run if firedNear object is player or player's vehicle:
if ((ACE_player != _object) && {(vehicle ACE_player) != _object}) exitWith {};
if (_weapon in ["Throw", "Put"]) exitWith {};
if (_distance > 50) exitWith {};
private ["_silencer", "_audibleFireCoef", "_loudness", "_strength", "_vehAttenuation", "_magazine", "_muzzles", "_weaponMagazines", "_muzzleMagazines", "_ammoType", "_initSpeed", "_ammoConfig", "_caliber", "_parentClasses"];
_vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttenuation)};
_distance = 1 max _distance;

View File

@ -15,31 +15,53 @@
*/
#include "script_component.hpp"
private ["_recoverRate", "_volume"];
GVAR(deafnessDV) = (GVAR(deafnessDV) min 20) max 0;
// Exit if combat deafness is disabled
if !(GVAR(enableCombatDeafness)) exitWith {};
// Check if new noises increase deafness
GVAR(newStrength) = (((ACE_player getvariable [QGVAR(dv), 0]) min 20) / 20) ^ 2;
if (GVAR(newStrength) > GVAR(currentDeafness)) then {
GVAR(currentDeafness) = GVAR(newStrength);
};
// Recover rate is slower if deafness is severe
_recoverRate = 0.01;
if (GVAR(currentDeafness) > 0.7) then {
_recoverRate = 0.005;
if (GVAR(currentDeafness) > 0.9) then {
_recoverRate = 0.002;
//If we got a big increase in the last second:
if ((GVAR(deafnessDV) - GVAR(deafnessPrior)) > 2) then {
if (ACE_time > GVAR(time3)) then {
GVAR(beep2) = false;
};
if (!GVAR(beep2)) then {
playSound "ACE_Combat_Deafness";
GVAR(beep2) = true;
GVAR(time3) = ACE_time + 5;
};
};
// Deafness recovers with ACE_time
GVAR(currentDeafness) = GVAR(currentDeafness) - _recoverRate max 0;
GVAR(deafnessPrior) = GVAR(deafnessDV);
GVAR(volume) = (1 - (GVAR(deafnessDV) / 20)) max 0;
// needed until Bohemia fixes playSound to actually use the second argument
_volume = (1 - GVAR(currentDeafness) max 0)^2 max 0.04;
if (GVAR(deafnessDV) > 19.75) then {
ACE_player setvariable [QGVAR(deaf), true];
if (ACE_time > GVAR(time4)) then {
playSound "ACE_Combat_Deafness";
GVAR(beep2) = true;
GVAR(time3) = ACE_time + 10;
GVAR(time4) = ACE_time + 30;
};
} else {
ACE_player setvariable [QGVAR(deaf), false];
};
if (GVAR(deafnessDV) > 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;
};
};
// Hearing takes longer to return to normal after it hits rock bottom
GVAR(deafnessDV) = (GVAR(deafnessDV) - (0.5 * (GVAR(volume) max 0.1))) max 0;
systemChat format ["%1 - %2/%3", time, GVAR(deafnessDV), GVAR(volume)];
_volume = GVAR(volume);
// Earplugs reduce hearing 50%
if ([ACE_player] call FUNC(hasEarPlugsIn)) then {
@ -61,8 +83,8 @@ if (ACE_player getVariable ["ACE_isUnconscious", false]) then {
};
if (!(missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false])) then {
0.1 fadeSound _volume;
0.1 fadeSpeech _volume;
1 fadeSound _volume;
1 fadeSpeech _volume;
ACE_player setVariable ["tf_globalVolume", _volume];
if (!isNil "acre_api_fnc_setGlobalVolume") then {[_volume^(0.33)] call acre_api_fnc_setGlobalVolume;};
};