Skip to content

Commit

Permalink
Merge pull request #2146 from jokoho48/codeCleanupHearing
Browse files Browse the repository at this point in the history
Code cleanup of Hearing module
  • Loading branch information
PabstMirror committed Aug 30, 2015
2 parents 6a17e3f + bd56d1b commit 2f54cfa
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion addons/hearing/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions addons/hearing/functions/fnc_addEarPlugs.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
3 changes: 1 addition & 2 deletions addons/hearing/functions/fnc_earRinging.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
2 changes: 1 addition & 1 deletion addons/hearing/functions/fnc_explosionNear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 10 additions & 12 deletions addons/hearing/functions/fnc_firedNear.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down Expand Up @@ -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]];
Expand All @@ -68,26 +68,24 @@ if (count _weaponMagazines == 0) then {

_magazine = "";
{
EXPLODE_2_PVT(_x,_magazineType,_ammoType);
_x params ["_magazineType", "_ammoType"];
if (_ammoType == _ammo) exitWith {
_magazine = _magazineType;
};
} forEach _weaponMagazines;
} count _weaponMagazines;

if (_magazine == "") exitWith {};

_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
Expand Down
3 changes: 1 addition & 2 deletions addons/hearing/functions/fnc_hasEarPlugsIn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* Public: No
*/
#include "script_component.hpp"

PARAMS_1(_unit);
params ["_unit"];

_unit getVariable ["ACE_hasEarPlugsin", false]
3 changes: 1 addition & 2 deletions addons/hearing/functions/fnc_moduleHearing.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
* None
*/
#include "script_component.hpp"

PARAMS_3(_logic,_units,_activated);
params ["_logic", "_units", "_activated"];

if !(_activated) exitWith {};

Expand Down
2 changes: 1 addition & 1 deletion addons/hearing/functions/fnc_putInEarplugs.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
#include "script_component.hpp"

PARAMS_1(_player);
params ["_player"];

// Plugs in inventory, putting them in
_player removeItem "ACE_EarPlugs";
Expand Down
2 changes: 1 addition & 1 deletion addons/hearing/functions/fnc_removeEarplugs.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions addons/hearing/functions/fnc_updateVolume.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2f54cfa

Please sign in to comment.