ACE3/addons/hearing/functions/fnc_updateVolume.sqf

71 lines
2.2 KiB
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
2015-03-15 21:40:47 +00:00
/*
* Author: commy2, esteldunedain, Ruthberg
* Updates and applies the current deafness. Called every 1 sec from a PFEH.
2015-03-15 21:40:47 +00:00
*
* Arguments:
* 0: Update volume only (skip ringing/recovery) <BOOL> (default: false)
2015-03-15 21:40:47 +00:00
*
* Return Value:
* None
*
* Example:
* call ace_hearing_fnc_updateVolume
2015-03-15 21:40:47 +00:00
*
* Public: No
*/
2015-01-14 02:16:55 +00:00
if (isGamePaused) exitWith {};
if (!alive ACE_player) exitWith {
if (missionNamespace getVariable [QGVAR(disableVolumeUpdate), false]) exitWith {};
TRACE_1("dead - removing hearing effects",ACE_player);
[QUOTE(ADDON), 1, true] call EFUNC(common,setHearingCapability);
};
params [["_updateVolumeOnly", false]];
2015-08-13 21:42:20 +00:00
GVAR(deafnessDV) = (GVAR(deafnessDV) min 20) max 0;
GVAR(volume) = (1 - (GVAR(deafnessDV) / 20)) max 0.05;
2016-02-06 17:11:18 +00:00
TRACE_3("",GVAR(volume),GVAR(deafnessDV),GVAR(deafnessDV) - GVAR(deafnessPrior));
if (!_updateVolumeOnly) then {
// Ring if we got a big increase in the last second or enough accumulated damage
if (GVAR(deafnessDV) - GVAR(deafnessPrior) > 1 ||
GVAR(deafnessDV) > 10) then {
2015-01-14 02:16:55 +00:00
2016-03-02 10:01:39 +00:00
if (CBA_missionTime - GVAR(time3) < 3) exitWith {};
if (!isGameFocused) exitWith {}; // prevent audio from stacking when tabbed out
2016-03-02 10:01:39 +00:00
GVAR(time3) = CBA_missionTime;
if (GVAR(deafnessDV) > 19.75) then {
playSound (["ACE_Combat_Deafness_Heavy", "ACE_Combat_Deafness_Heavy_NoRing"] select GVAR(disableEarRinging));
} else {
playSound (["ACE_Combat_Deafness_Medium", "ACE_Combat_Deafness_Medium_NoRing"] select GVAR(disableEarRinging));
};
2015-03-15 21:40:47 +00:00
};
GVAR(deafnessPrior) = GVAR(deafnessDV);
2015-01-14 02:16:55 +00:00
// 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;
};
2015-07-11 02:01:32 +00:00
if (missionNamespace getVariable [QGVAR(disableVolumeUpdate), false]) exitWith {};
2015-01-14 02:16:55 +00:00
2016-01-20 23:19:08 +00:00
private _volume = GVAR(volume);
2015-01-14 02:16:55 +00:00
// Earplugs and headgear can attenuate hearing
_volume = _volume min GVAR(volumeAttenuation);
2015-07-01 19:21:09 +00:00
2015-01-14 02:16:55 +00:00
// Reduce volume if player is unconscious
if (lifeState ACE_player == "INCAPACITATED") then {
_volume = _volume min GVAR(unconsciousnessVolume);
2015-01-14 02:16:55 +00:00
};
[QUOTE(ADDON), _volume, true] call EFUNC(common,setHearingCapability);