From 845909f8af2faa944f1819f1e83bf386fd937912 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 8 Nov 2015 14:02:00 -0600 Subject: [PATCH 1/3] #2833 - Add earplugs based on loudness (+MGs) Use same loudness calc as firedNear (replacing old audibleFire) Give ear plugs to machine gunners (depends on magzine size) --- addons/hearing/functions/fnc_addEarPlugs.sqf | 31 +++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/addons/hearing/functions/fnc_addEarPlugs.sqf b/addons/hearing/functions/fnc_addEarPlugs.sqf index b2e43bc718..e9f737e744 100644 --- a/addons/hearing/functions/fnc_addEarPlugs.sqf +++ b/addons/hearing/functions/fnc_addEarPlugs.sqf @@ -14,29 +14,40 @@ * Public: No */ #include "script_component.hpp" + params ["_unit"]; // Exit if hearing is disabled or soldier has earplugs already in (persistence scenarios) if (!GVAR(enableCombatDeafness) || {[_unit] call FUNC(hasEarPlugsIn)}) exitWith {}; -private ["_launcher"]; - // add earplugs if the soldier has a rocket launcher -_launcher = secondaryWeapon _unit; - -if (_launcher != "") exitWith { +if ((secondaryWeapon _unit) != "") exitWith { _unit addItem "ACE_EarPlugs"; }; // otherwise add earplugs if the soldier has a big rifle -private ["_magazine", "_ammo"]; +if ((primaryWeapon _unit) == "") exitWith {}; -_magazine = primaryWeaponMagazine _unit select 0; +(primaryWeaponMagazine _unit) params [["_magazine", ""]]; +if (_magazine == "") exitWith {}; -if (isNil "_magazine") exitWith {}; +local _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); +local _ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); +local _count = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); -_ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); +local _caliber = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_caliber"); +_caliber = call { + if (_ammo isKindOf ["ShellBase", (configFile >> "CfgAmmo")]) exitWith { 80 }; + if (_ammo isKindOf ["RocketBase", (configFile >> "CfgAmmo")]) exitWith { 200 }; + if (_ammo isKindOf ["MissileBase", (configFile >> "CfgAmmo")]) exitWith { 600 }; + if (_ammo isKindOf ["SubmunitionBase", (configFile >> "CfgAmmo")]) exitWith { 80 }; + if (_caliber <= 0) then { 6.5 } else { _caliber }; +}; +local _loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) / 5; -if (getNumber (configFile >> "CfgAmmo" >> _ammo >> "audiblefire") > 8) then { +//If unit has a machine gun boost effective loudness 50% +if (_count >= 50) then {_loudness = _loudness * 1.5}; + +if (_loudness > 0.2) then { _unit addItem "ACE_EarPlugs"; }; From 87b9ff978585e94ec7dc06337bf6c871b5cb4165 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 10 Nov 2015 20:44:55 -0600 Subject: [PATCH 2/3] Hearing - Reset earplugs on respawn, addItem setting Fix #2835 - readd item on respawn Fix #2837 - setVariable false on respawn --- addons/hearing/ACE_Settings.hpp | 6 ++++ addons/hearing/CfgEventHandlers.hpp | 10 +++++- addons/hearing/CfgVehicles.hpp | 6 ++++ addons/hearing/XEH_preInit.sqf | 1 + addons/hearing/functions/fnc_addEarPlugs.sqf | 14 ++++++-- .../hearing/functions/fnc_handleRespawn.sqf | 35 +++++++++++++++++++ .../hearing/functions/fnc_moduleHearing.sqf | 1 + addons/hearing/stringtable.xml | 6 ++++ 8 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 addons/hearing/functions/fnc_handleRespawn.sqf diff --git a/addons/hearing/ACE_Settings.hpp b/addons/hearing/ACE_Settings.hpp index 262c3edc34..13f445a987 100644 --- a/addons/hearing/ACE_Settings.hpp +++ b/addons/hearing/ACE_Settings.hpp @@ -25,4 +25,10 @@ class ACE_Settings { displayName = CSTRING(enabledForZeusUnits_DisplayName); description = CSTRING(enabledForZeusUnits_Description); }; + class GVAR(autoAddEarplugsToUnits) { + value = 1; + typeName = "BOOL"; + displayName = CSTRING(autoAddEarplugsToUnits_DisplayName); + description = CSTRING(autoAddEarplugsToUnits_Description); + }; }; diff --git a/addons/hearing/CfgEventHandlers.hpp b/addons/hearing/CfgEventHandlers.hpp index f09f259266..e31501d1c3 100644 --- a/addons/hearing/CfgEventHandlers.hpp +++ b/addons/hearing/CfgEventHandlers.hpp @@ -13,7 +13,7 @@ class Extended_PostInit_EventHandlers { class Extended_Init_EventHandlers { class CAManBase { class GVAR(AddEarPlugs) { - init = QUOTE( if (local (_this select 0)) then {_this call FUNC(addEarPlugs)}; ); + serverInit = QUOTE( _this call FUNC(addEarPlugs) ); }; }; }; @@ -33,3 +33,11 @@ class Extended_Explosion_EventHandlers { }; }; }; + +class Extended_Respawn_EventHandlers { + class CAManBase { + class ADDON { + respawn = QUOTE(_this call FUNC(handleRespawn)); + }; + }; +}; diff --git a/addons/hearing/CfgVehicles.hpp b/addons/hearing/CfgVehicles.hpp index 2273653c3a..c7d796f24e 100644 --- a/addons/hearing/CfgVehicles.hpp +++ b/addons/hearing/CfgVehicles.hpp @@ -136,6 +136,12 @@ class CfgVehicles { typeName = "BOOL"; defaultValue = 1; }; + class autoAddEarplugsToUnits { + displayName = CSTRING(autoAddEarplugsToUnits_DisplayName); + description = CSTRING(autoAddEarplugsToUnits_Description); + typeName = "BOOL"; + defaultValue = 1; + }; }; class ModuleDescription { description = CSTRING(Module_Description); diff --git a/addons/hearing/XEH_preInit.sqf b/addons/hearing/XEH_preInit.sqf index 16b9f35f80..3355d0cff4 100644 --- a/addons/hearing/XEH_preInit.sqf +++ b/addons/hearing/XEH_preInit.sqf @@ -6,6 +6,7 @@ PREP(addEarPlugs); PREP(earRinging); PREP(explosionNear); PREP(firedNear); +PREP(handleRespawn); PREP(hasEarPlugsIn); PREP(moduleHearing); PREP(putInEarPlugs); diff --git a/addons/hearing/functions/fnc_addEarPlugs.sqf b/addons/hearing/functions/fnc_addEarPlugs.sqf index e9f737e744..4301012dd1 100644 --- a/addons/hearing/functions/fnc_addEarPlugs.sqf +++ b/addons/hearing/functions/fnc_addEarPlugs.sqf @@ -16,12 +16,19 @@ #include "script_component.hpp" params ["_unit"]; +TRACE_2("params",_unit,typeOf _unit); -// Exit if hearing is disabled or soldier has earplugs already in (persistence scenarios) -if (!GVAR(enableCombatDeafness) || {[_unit] call FUNC(hasEarPlugsIn)}) exitWith {}; +// only run this after the settings are initialized +if !(EGVAR(common,settingsInitFinished)) exitWith { + EGVAR(common,runAtSettingsInitialized) pushBack [FUNC(addEarPlugs), _this]; +}; + +// Exit if hearing is disabled OR autoAdd is disabled OR soldier has earplugs already in (persistence scenarios) +if (!GVAR(enableCombatDeafness) || {!GVAR(autoAddEarplugsToUnits)} || {[_unit] call FUNC(hasEarPlugsIn)}) exitWith {}; // add earplugs if the soldier has a rocket launcher if ((secondaryWeapon _unit) != "") exitWith { + TRACE_1("has launcher - adding",_unit); _unit addItem "ACE_EarPlugs"; }; @@ -48,6 +55,9 @@ local _loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) / 5; //If unit has a machine gun boost effective loudness 50% if (_count >= 50) then {_loudness = _loudness * 1.5}; +TRACE_2("primaryWeapon",_unit,_loudness); + if (_loudness > 0.2) then { + TRACE_1("loud gun - adding",_unit); _unit addItem "ACE_EarPlugs"; }; diff --git a/addons/hearing/functions/fnc_handleRespawn.sqf b/addons/hearing/functions/fnc_handleRespawn.sqf new file mode 100644 index 0000000000..08ba2946a5 --- /dev/null +++ b/addons/hearing/functions/fnc_handleRespawn.sqf @@ -0,0 +1,35 @@ +/* + * Author: PabstMirror + * Reset earplugs on respawn, and then re-add if appropriate + * + * Arguments: + * 0: Unit + * + * Return Value: + * Nothing + * + * Example: + * [player] call ACE_hearing_fnc_handleRespawn; + * + * Public: No + */ +#include "script_component.hpp" + +params ["_unit"]; +TRACE_2("params",_unit,typeOf _unit); + +if (!local _unit) exitWith {}; //XEH should only be called on local units + +local _respawn = [0] call BIS_fnc_missionRespawnType; + +//if respawn is not Group or side: +if (_respawn <= 3) then { + //Remove earplugs if they have them: + if (_unit getVariable ["ACE_hasEarPlugsin", false]) then { + TRACE_1("had EarPlugs in - removing",_unit); + _unit setVariable ["ACE_hasEarPlugsin", false, true]; + }; +}; + +//Re-add if they need them: +[_unit] call FUNC(addEarPlugs); diff --git a/addons/hearing/functions/fnc_moduleHearing.sqf b/addons/hearing/functions/fnc_moduleHearing.sqf index 0aa8843485..35836ddb0c 100644 --- a/addons/hearing/functions/fnc_moduleHearing.sqf +++ b/addons/hearing/functions/fnc_moduleHearing.sqf @@ -20,4 +20,5 @@ if ((_logic getVariable "DisableEarRinging") != -1) then { }; [_logic, QGVAR(enabledForZeusUnits), "enabledForZeusUnits"] call EFUNC(common,readSettingFromModule); +[_logic, QGVAR(autoAddEarplugsToUnits), "autoAddEarplugsToUnits"] call EFUNC(common,readSettingFromModule); ACE_LOGINFO("Hearing Module Initialized."); diff --git a/addons/hearing/stringtable.xml b/addons/hearing/stringtable.xml index 05dde3a1bf..471b16d243 100644 --- a/addons/hearing/stringtable.xml +++ b/addons/hearing/stringtable.xml @@ -165,5 +165,11 @@ Permite que unidades remotamente controladas pelo Zeus sejam atingidas por danos auditivos. Permitir a las unidades por control remoto de zeus que puedan tener daƱos auditivos. + + Add earplugs to units + + + Add the `ACE_EarPlugs` item to all units that have loud weapons. Can disable if using custom loadouts. + \ No newline at end of file From d6000ae9852a105d58ea2dda065eff87b3808b07 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 17 Nov 2015 14:33:17 -0600 Subject: [PATCH 3/3] local -> private --- addons/hearing/functions/fnc_addEarPlugs.sqf | 10 +++++----- addons/hearing/functions/fnc_handleRespawn.sqf | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/hearing/functions/fnc_addEarPlugs.sqf b/addons/hearing/functions/fnc_addEarPlugs.sqf index 4301012dd1..9e6bd0cab2 100644 --- a/addons/hearing/functions/fnc_addEarPlugs.sqf +++ b/addons/hearing/functions/fnc_addEarPlugs.sqf @@ -38,11 +38,11 @@ if ((primaryWeapon _unit) == "") exitWith {}; (primaryWeaponMagazine _unit) params [["_magazine", ""]]; if (_magazine == "") exitWith {}; -local _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); -local _ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); -local _count = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); +private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); +private _ammo = getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"); +private _count = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); -local _caliber = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_caliber"); +private _caliber = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_caliber"); _caliber = call { if (_ammo isKindOf ["ShellBase", (configFile >> "CfgAmmo")]) exitWith { 80 }; if (_ammo isKindOf ["RocketBase", (configFile >> "CfgAmmo")]) exitWith { 200 }; @@ -50,7 +50,7 @@ _caliber = call { if (_ammo isKindOf ["SubmunitionBase", (configFile >> "CfgAmmo")]) exitWith { 80 }; if (_caliber <= 0) then { 6.5 } else { _caliber }; }; -local _loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) / 5; +private _loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) / 5; //If unit has a machine gun boost effective loudness 50% if (_count >= 50) then {_loudness = _loudness * 1.5}; diff --git a/addons/hearing/functions/fnc_handleRespawn.sqf b/addons/hearing/functions/fnc_handleRespawn.sqf index 08ba2946a5..527d5d6b16 100644 --- a/addons/hearing/functions/fnc_handleRespawn.sqf +++ b/addons/hearing/functions/fnc_handleRespawn.sqf @@ -20,7 +20,7 @@ TRACE_2("params",_unit,typeOf _unit); if (!local _unit) exitWith {}; //XEH should only be called on local units -local _respawn = [0] call BIS_fnc_missionRespawnType; +private _respawn = [0] call BIS_fnc_missionRespawnType; //if respawn is not Group or side: if (_respawn <= 3) then {