Skip to content

Commit

Permalink
Hearing - New XEH, Fix dead effects, Medical var (#3802)
Browse files Browse the repository at this point in the history
* Hearing - New XEH, Fix dead effects, Medical var

* Use setHearingCapability

* Cleanup dead player vol update

* Don't change global hearing in medical

* Fix exitWith
  • Loading branch information
PabstMirror committed May 20, 2016
1 parent f67b356 commit f69142d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 55 deletions.
2 changes: 2 additions & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ if (isServer) then {
GVAR(statusEffect_Names) = [];
GVAR(statusEffect_isGlobal) = [];

GVAR(setHearingCapabilityMap) = [];

//////////////////////////////////////////////////
// Set up PlayerChanged eventhandler for pre init (EH is installed in postInit)
//////////////////////////////////////////////////
Expand Down
42 changes: 19 additions & 23 deletions addons/common/functions/fnc_setHearingCapability.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,45 @@
* Arguments:
* 0: id <STRING>
* 1: settings <NUMBER>
* 2: add (default: true) <BOOL>
* 2: add [true] OR remove [false] (default: true) <BOOL>
*
* Return Value:
* None
*
* Public: Yes
* Example:
* ["earwax", 0.5, true] call ace_common_fnc_setHearingCapability
*
* Note: uses player
* Public: Yes
*/
#include "script_component.hpp"

params ["_id", "_settings", ["_add", true]];

private _map = missionNamespace getVariable [QGVAR(setHearingCapabilityMap),[]];
params ["_id", "_setting", ["_add", true]];

private _exists = false;
private _lowestVolume = 1;

{
if (_id == _x select 0) exitWith {
GVAR(setHearingCapabilityMap) = GVAR(setHearingCapabilityMap) select {
_x params ["_xID", "_xSetting"];
if (_id == _xID) then {
_exists = true;
if (_add) then {
_x set [1, _settings];
_x set [1, _setting];
_lowestVolume = _lowestVolume min _setting;
true
} else {
_map set [_forEachIndex, 0];
_map = _map - [0];
false
};
} else {
_lowestVolume = _lowestVolume min _xSetting;
true
};
} forEach _map;
};

if (!_exists && _add) then {
_map pushBack [_id, _settings];
_lowestVolume = _lowestVolume min _setting;
GVAR(setHearingCapabilityMap) pushBack [_id, _setting];
};

missionNamespace setVariable [QGVAR(setHearingCapabilityMap), _map];

// find lowest volume
private _lowestVolume = 1;

{
_lowestVolume = (_x select 1) min _lowestVolume;
false
} count _map;

// in game sounds
0 fadeSound _lowestVolume;
0 fadeRadio _lowestVolume;
Expand Down
16 changes: 0 additions & 16 deletions addons/hearing/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ class Extended_Init_EventHandlers {
};
};

class Extended_FiredNear_EventHandlers {
class AllVehicles {
class GVAR(FiredNear) {
clientFiredNear = QUOTE(_this call FUNC(firedNear););
};
};
};

class Extended_Explosion_EventHandlers {
class CAManBase {
class GVAR(ExplosionNear) {
clientExplosion = QUOTE(_this call FUNC(explosionNear););
};
};
};

class Extended_Respawn_EventHandlers {
class CAManBase {
class ADDON {
Expand Down
4 changes: 4 additions & 0 deletions addons/hearing/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ GVAR(volumeAttenuation) = 1;
// Only run PFEH and install event handlers if combat deafness is enabled
if (!GVAR(EnableCombatDeafness)) exitWith {};

//Add XEH:
["CAManBase", "FiredNear", FUNC(firedNear)] call CBA_fnc_addClassEventHandler;
["CAManBase", "Explosion", FUNC(explosionNear)] call CBA_fnc_addClassEventHandler;

// Update hearing protection now:
[] call FUNC(updateHearingProtection);

Expand Down
3 changes: 0 additions & 3 deletions addons/hearing/functions/fnc_explosionNear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
#include "script_component.hpp"

// Only run if combat deafness is enabled
if (!GVAR(EnableCombatDeafness)) exitWith {};

params ["_unit", "_damage"];

if (_unit != ACE_player) exitWith {};
Expand Down
3 changes: 0 additions & 3 deletions addons/hearing/functions/fnc_firedNear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*/
#include "script_component.hpp"

// Only run if combat deafness is enabled
if (!GVAR(EnableCombatDeafness)) exitWith {};

params ["_object", "_firer", "_distance", "_weapon", "", "", "_ammo"];

//Only run if firedNear object is player or player's vehicle:
Expand Down
13 changes: 7 additions & 6 deletions addons/hearing/functions/fnc_updateVolume.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
*/
#include "script_component.hpp"

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);
};

(_this select 0) params ["_justUpdateVolume"];

GVAR(deafnessDV) = (GVAR(deafnessDV) min 20) max 0;
Expand Down Expand Up @@ -54,9 +60,4 @@ if (ACE_player getVariable ["ACE_isUnconscious", false]) then {
_volume = _volume min GVAR(UnconsciousnessVolume);
};

private _soundTransitionTime = if (_justUpdateVolume) then {0.1} else {1};

_soundTransitionTime fadeSound _volume;
_soundTransitionTime fadeSpeech _volume;
ACE_player setVariable ["tf_globalVolume", _volume];
if (!isNil "acre_api_fnc_setGlobalVolume") then {[_volume^(0.33)] call acre_api_fnc_setGlobalVolume;};
[QUOTE(ADDON), _volume, true] call EFUNC(common,setHearingCapability);
4 changes: 0 additions & 4 deletions addons/medical/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,15 @@ if (isServer) then {["placedInBodyBag", FUNC(serverRemoveBody)] call EFUNC(commo
params ["_unit", "_status"];
if (local _unit) then {
if (_status) then {
_unit setVariable ["tf_globalVolume", 0.4];
_unit setVariable ["tf_voiceVolume", 0, true];
_unit setVariable ["tf_unable_to_use_radio", true, true];

_unit setVariable ["acre_sys_core_isDisabled", true, true];
if (!isNil "acre_api_fnc_setGlobalVolume") then { [0.4^0.33] call acre_api_fnc_setGlobalVolume; };
} else {
_unit setVariable ["tf_globalVolume", 1];
_unit setVariable ["tf_voiceVolume", 1, true];
_unit setVariable ["tf_unable_to_use_radio", false, true];

_unit setVariable ["acre_sys_core_isDisabled", false, true];
if (!isNil "acre_api_fnc_setGlobalVolume") then { [1] call acre_api_fnc_setGlobalVolume; };
};
};
}] call EFUNC(common,addEventHandler);
Expand Down

0 comments on commit f69142d

Please sign in to comment.