2015-01-11 16:42:31 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
* Called on unit initialization. Adds earplugs if the unit is equipped with either a really loud primary weapon or a rocket launcher.
|
2015-01-13 04:17:52 +00:00
|
|
|
*
|
2015-03-15 21:40:47 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: A Soldier <Object>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [guy] call ace_hearing_fnc_addEarPlugs
|
2015-01-13 04:17:52 +00:00
|
|
|
*
|
2015-03-15 21:40:47 +00:00
|
|
|
* Public: No
|
2015-01-11 16:42:31 +00:00
|
|
|
*/
|
2015-01-14 01:41:53 +00:00
|
|
|
#include "script_component.hpp"
|
2015-11-08 20:02:00 +00:00
|
|
|
|
2015-08-13 21:42:20 +00:00
|
|
|
params ["_unit"];
|
2015-11-11 02:44:55 +00:00
|
|
|
TRACE_2("params",_unit,typeOf _unit);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-11-11 02:44:55 +00:00
|
|
|
// 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 {};
|
2015-06-28 19:25:01 +00:00
|
|
|
|
2015-01-11 16:42:31 +00:00
|
|
|
// add earplugs if the soldier has a rocket launcher
|
2015-11-08 20:02:00 +00:00
|
|
|
if ((secondaryWeapon _unit) != "") exitWith {
|
2015-11-11 02:44:55 +00:00
|
|
|
TRACE_1("has launcher - adding",_unit);
|
2015-03-16 15:56:05 +00:00
|
|
|
_unit addItem "ACE_EarPlugs";
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// otherwise add earplugs if the soldier has a big rifle
|
2015-11-08 20:02:00 +00:00
|
|
|
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");
|
|
|
|
|
|
|
|
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;
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-11-08 20:02:00 +00:00
|
|
|
//If unit has a machine gun boost effective loudness 50%
|
|
|
|
if (_count >= 50) then {_loudness = _loudness * 1.5};
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-11-11 02:44:55 +00:00
|
|
|
TRACE_2("primaryWeapon",_unit,_loudness);
|
|
|
|
|
2015-11-08 20:02:00 +00:00
|
|
|
if (_loudness > 0.2) then {
|
2015-11-11 02:44:55 +00:00
|
|
|
TRACE_1("loud gun - adding",_unit);
|
2015-03-16 15:56:05 +00:00
|
|
|
_unit addItem "ACE_EarPlugs";
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|