From c6fbdb420c13f0c3d0224079cd84fe8ec7d25c83 Mon Sep 17 00:00:00 2001 From: jokoho48 Date: Thu, 13 Aug 2015 23:42:20 +0200 Subject: [PATCH 1/3] Code cleanup of Hearing module --- addons/hearing/XEH_postInit.sqf | 2 +- addons/hearing/functions/fnc_addEarPlugs.sqf | 3 +- addons/hearing/functions/fnc_earRinging.sqf | 3 +- .../hearing/functions/fnc_explosionNear.sqf | 2 +- addons/hearing/functions/fnc_firedNear.sqf | 32 +++++++++---------- .../hearing/functions/fnc_hasEarPlugsIn.sqf | 3 +- .../hearing/functions/fnc_moduleHearing.sqf | 3 +- .../hearing/functions/fnc_putInEarplugs.sqf | 2 +- .../hearing/functions/fnc_removeEarplugs.sqf | 2 +- addons/hearing/functions/fnc_updateVolume.sqf | 4 +-- 10 files changed, 25 insertions(+), 31 deletions(-) diff --git a/addons/hearing/XEH_postInit.sqf b/addons/hearing/XEH_postInit.sqf index ad73ed55d5..66406ad917 100644 --- a/addons/hearing/XEH_postInit.sqf +++ b/addons/hearing/XEH_postInit.sqf @@ -15,7 +15,7 @@ GVAR(time4) = 0; ["SettingsInitialized", { // Spawn volume updating process - [FUNC(updateVolume), 1, [false] ] call CBA_fnc_addPerFrameHandler; + [FUNC(updateVolume), 1, [false]] call CBA_fnc_addPerFrameHandler; }] call EFUNC(common,addEventHandler); //Update veh attunation when player veh changes diff --git a/addons/hearing/functions/fnc_addEarPlugs.sqf b/addons/hearing/functions/fnc_addEarPlugs.sqf index 62ed4518e2..b2e43bc718 100644 --- a/addons/hearing/functions/fnc_addEarPlugs.sqf +++ b/addons/hearing/functions/fnc_addEarPlugs.sqf @@ -14,8 +14,7 @@ * Public: No */ #include "script_component.hpp" - -PARAMS_1(_unit); +params ["_unit"]; // Exit if hearing is disabled or soldier has earplugs already in (persistence scenarios) if (!GVAR(enableCombatDeafness) || {[_unit] call FUNC(hasEarPlugsIn)}) exitWith {}; diff --git a/addons/hearing/functions/fnc_earRinging.sqf b/addons/hearing/functions/fnc_earRinging.sqf index 6a896c1820..63ca3e5f1c 100644 --- a/addons/hearing/functions/fnc_earRinging.sqf +++ b/addons/hearing/functions/fnc_earRinging.sqf @@ -15,8 +15,7 @@ * Public: No */ #include "script_component.hpp" - -PARAMS_2(_unit,_strength); +params ["_unit", "_strength"]; if (_unit != ACE_player) exitWith {}; if (_strength < 0.05) exitWith {}; diff --git a/addons/hearing/functions/fnc_explosionNear.sqf b/addons/hearing/functions/fnc_explosionNear.sqf index dde9bc50cc..8cea263fec 100644 --- a/addons/hearing/functions/fnc_explosionNear.sqf +++ b/addons/hearing/functions/fnc_explosionNear.sqf @@ -19,7 +19,7 @@ //Only run if deafness or ear ringing is enabled: if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {}; -PARAMS_2(_unit,_damage); +params ["_unit", "_damage"]; private ["_strength"]; _strength = 0 max _damage; diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index 6fc48b27fa..5adf66fb25 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -24,7 +24,7 @@ //Only run if deafness or ear ringing is enabled: if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {}; -PARAMS_7(_object,_firer,_distance,_weapon,_muzzle,_mode,_ammo); +params ["_object", "_firer", "_distance", "_weapon", "_muzzle", "_mode", "_ammo"]; //Only run if firedNear object is player or player's vehicle: if ((ACE_player != _object) && {(vehicle ACE_player) != _object}) exitWith {}; @@ -37,11 +37,11 @@ _vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_p _distance = 1 max _distance; -_silencer = switch (_weapon) do { - case (primaryWeapon _firer) : {(primaryWeaponItems _firer) select 0}; - case (secondaryWeapon _firer) : {(secondaryWeaponItems _firer) select 0}; - case (handgunWeapon _firer) : {(handgunItems _firer) select 0}; - default {""}; +_silencer = call { + if (primaryWeapon _firer) exitWith {(primaryWeaponItems _firer) select 0}; + if (secondaryWeapon _firer) exitWith {(secondaryWeaponItems _firer) select 0}; + if (handgunWeapon _firer) exitWith {(handgunItems _firer) select 0}; + "" }; _audibleFireCoef = 1; @@ -58,7 +58,7 @@ if (count _weaponMagazines == 0) then { _muzzleMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines"); _weaponMagazines append _muzzleMagazines; }; - } forEach _muzzles; + } count _muzzles; { _ammoType = getText(configFile >> "CfgMagazines" >> _x >> "ammo"); _weaponMagazines set [_forEachIndex, [_x, _ammoType]]; @@ -68,11 +68,11 @@ if (count _weaponMagazines == 0) then { _magazine = ""; { - EXPLODE_2_PVT(_x,_magazineType,_ammoType); + params ["_magazineType", "_ammoType"]; if (_ammoType == _ammo) exitWith { _magazine = _magazineType; }; -} forEach _weaponMagazines; +} count _weaponMagazines; if (_magazine == "") exitWith {}; @@ -80,14 +80,12 @@ _initSpeed = getNumber(configFile >> "CfgMagazines" >> _magazine >> "initSpeed") _ammoConfig = (configFile >> "CfgAmmo" >> _ammo); _parentClasses = [_ammoConfig, true] call BIS_fnc_returnParents; _caliber = getNumber(_ammoConfig >> "ACE_caliber"); -_caliber = switch (true) do { - case ("ShellBase" in _parentClasses): { 80 }; - case ("RocketBase" in _parentClasses): { 200 }; - case ("MissileBase" in _parentClasses): { 600 }; - case ("SubmunitionBase" in _parentClasses): { 80 }; - default { - if (_caliber <= 0) then { 6.5 } else { _caliber }; - }; +_caliber = call { + if ("ShellBase" in _parentClasses) exitWith { 80 }; + if ("RocketBase" in _parentClasses) exitWith { 200 }; + if ("MissileBase" in _parentClasses) exitWith { 600 }; + if ("SubmunitionBase" in _parentClasses) exitWith { 80 }; + if (_caliber <= 0) then { 6.5 } else { _caliber }; }; _loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) * _audibleFireCoef / 5; _strength = _vehAttenuation * (_loudness - (_loudness / 50 * _distance)); // linear drop off diff --git a/addons/hearing/functions/fnc_hasEarPlugsIn.sqf b/addons/hearing/functions/fnc_hasEarPlugsIn.sqf index 58dc302888..67a76685f4 100644 --- a/addons/hearing/functions/fnc_hasEarPlugsIn.sqf +++ b/addons/hearing/functions/fnc_hasEarPlugsIn.sqf @@ -14,7 +14,6 @@ * Public: No */ #include "script_component.hpp" - -PARAMS_1(_unit); +params ["_unit"]; _unit getVariable ["ACE_hasEarPlugsin", false] diff --git a/addons/hearing/functions/fnc_moduleHearing.sqf b/addons/hearing/functions/fnc_moduleHearing.sqf index 6ec0af0231..50675022a0 100644 --- a/addons/hearing/functions/fnc_moduleHearing.sqf +++ b/addons/hearing/functions/fnc_moduleHearing.sqf @@ -9,8 +9,7 @@ * None */ #include "script_component.hpp" - -PARAMS_3(_logic,_units,_activated); +params ["_logic", "_units", "_activated"]; if !(_activated) exitWith {}; diff --git a/addons/hearing/functions/fnc_putInEarplugs.sqf b/addons/hearing/functions/fnc_putInEarplugs.sqf index 8b11e6ba25..8d5479c17b 100644 --- a/addons/hearing/functions/fnc_putInEarplugs.sqf +++ b/addons/hearing/functions/fnc_putInEarplugs.sqf @@ -15,7 +15,7 @@ */ #include "script_component.hpp" -PARAMS_1(_player); +params ["_player"]; // Plugs in inventory, putting them in _player removeItem "ACE_EarPlugs"; diff --git a/addons/hearing/functions/fnc_removeEarplugs.sqf b/addons/hearing/functions/fnc_removeEarplugs.sqf index 19a34831cd..f5b5ca2442 100644 --- a/addons/hearing/functions/fnc_removeEarplugs.sqf +++ b/addons/hearing/functions/fnc_removeEarplugs.sqf @@ -15,7 +15,7 @@ */ #include "script_component.hpp" -PARAMS_1(_player); +params ["_player"]; if !(_player canAdd "ACE_EarPlugs") exitWith { // inventory full [localize LSTRING(Inventory_Full)] call EFUNC(common,displayTextStructured); diff --git a/addons/hearing/functions/fnc_updateVolume.sqf b/addons/hearing/functions/fnc_updateVolume.sqf index 3a72e8eb3b..f1cb063971 100644 --- a/addons/hearing/functions/fnc_updateVolume.sqf +++ b/addons/hearing/functions/fnc_updateVolume.sqf @@ -19,9 +19,9 @@ //Only run if deafness or ear ringing is enabled: if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {}; -EXPLODE_1_PVT((_this select 0),_justUpdateVolume); - private["_volume", "_soundTransitionTime"]; +(_this select 0) params ["_justUpdateVolume"]; + GVAR(deafnessDV) = (GVAR(deafnessDV) min 20) max 0; GVAR(volume) = (1 - (GVAR(deafnessDV) / 20)) max 0; From cb8d009ef033a629fbb41328007ba8cebdf8d816 Mon Sep 17 00:00:00 2001 From: jokoho48 Date: Fri, 14 Aug 2015 00:31:42 +0200 Subject: [PATCH 2/3] Woops --- addons/hearing/functions/fnc_firedNear.sqf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index 5adf66fb25..02de8db928 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -38,9 +38,9 @@ _vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_p _distance = 1 max _distance; _silencer = call { - if (primaryWeapon _firer) exitWith {(primaryWeaponItems _firer) select 0}; - if (secondaryWeapon _firer) exitWith {(secondaryWeaponItems _firer) select 0}; - if (handgunWeapon _firer) exitWith {(handgunItems _firer) select 0}; + if (_weapon == primaryWeapon _firer) exitWith {(primaryWeaponItems _firer) select 0}; + if (_weapon == secondaryWeapon _firer) exitWith {(secondaryWeaponItems _firer) select 0}; + if (_weapon == handgunWeapon _firer) exitWith {(handgunItems _firer) select 0}; "" }; @@ -68,7 +68,7 @@ if (count _weaponMagazines == 0) then { _magazine = ""; { - params ["_magazineType", "_ammoType"]; + _x params ["_magazineType", "_ammoType"]; if (_ammoType == _ammo) exitWith { _magazine = _magazineType; }; From bd56d1bb83855cd055f21b2e779337e19fab87f1 Mon Sep 17 00:00:00 2001 From: jokoho48 Date: Fri, 14 Aug 2015 00:36:36 +0200 Subject: [PATCH 3/3] ok that is my fault --- addons/hearing/functions/fnc_firedNear.sqf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/hearing/functions/fnc_firedNear.sqf b/addons/hearing/functions/fnc_firedNear.sqf index 02de8db928..1ede8db3ea 100644 --- a/addons/hearing/functions/fnc_firedNear.sqf +++ b/addons/hearing/functions/fnc_firedNear.sqf @@ -37,11 +37,11 @@ _vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_p _distance = 1 max _distance; -_silencer = call { - if (_weapon == primaryWeapon _firer) exitWith {(primaryWeaponItems _firer) select 0}; - if (_weapon == secondaryWeapon _firer) exitWith {(secondaryWeaponItems _firer) select 0}; - if (_weapon == handgunWeapon _firer) exitWith {(handgunItems _firer) select 0}; - "" +_silencer = switch (_weapon) do { + case (primaryWeapon _firer) : {(primaryWeaponItems _firer) select 0}; + case (secondaryWeapon _firer) : {(secondaryWeaponItems _firer) select 0}; + case (handgunWeapon _firer) : {(handgunItems _firer) select 0}; + default {""}; }; _audibleFireCoef = 1;