2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
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:
|
2024-05-24 23:05:19 +00:00
|
|
|
* 0: Unit <Object>
|
2015-03-15 21:40:47 +00:00
|
|
|
*
|
|
|
|
* 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-11-08 20:02:00 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
// Only run this after the settings are initialized
|
|
|
|
if (!EGVAR(common,settingsInitFinished)) exitWith {
|
|
|
|
EGVAR(common,runAtSettingsInitialized) pushBack [LINKFUNC(addEarPlugs), _this];
|
2015-11-11 02:44:55 +00:00
|
|
|
};
|
|
|
|
|
2024-04-28 16:04:56 +00:00
|
|
|
// Exit if hearing is disabled or if autoAdd is disabled
|
|
|
|
if (!GVAR(enableCombatDeafness) || {GVAR(autoAddEarplugsToUnits) == 0}) exitWith {};
|
|
|
|
|
2024-03-21 19:26:46 +00:00
|
|
|
params ["_unit"];
|
|
|
|
TRACE_2("params",_unit,typeOf _unit);
|
|
|
|
|
2024-04-28 16:04:56 +00:00
|
|
|
// Exit if the unit already has earplugs (in ears (persistence scenarios) or inventory)
|
|
|
|
if (_unit call FUNC(hasEarPlugsIn) || {[_unit, "ACE_EarPlugs"] call EFUNC(common,hasItem)}) exitWith {};
|
2015-06-28 19:25:01 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
// Add earplugs if enabled for everyone or if the unit has a rocket launcher
|
2024-04-10 11:23:50 +00:00
|
|
|
if (GVAR(autoAddEarplugsToUnits) == 2 || {(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
|
|
|
};
|
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
// Otherwise add earplugs if the unit has a big rifle
|
|
|
|
private _weapon = primaryWeapon _unit;
|
2015-11-08 20:02:00 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
if (_weapon == "") exitWith {};
|
2015-11-08 20:02:00 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
if (isNil QGVAR(cacheMaxAmmoLoudness)) then {
|
|
|
|
GVAR(cacheMaxAmmoLoudness) = createHashMap;
|
|
|
|
};
|
2024-03-21 19:26:46 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
// Cache maximum loudness for future calls
|
|
|
|
private _maxLoudness = GVAR(cacheMaxAmmoLoudness) getOrDefaultCall [_weapon, {
|
|
|
|
// Get the weapon's compatible magazines, so that all magazines are cached
|
|
|
|
// From all the loudness factors, take the max
|
|
|
|
private _maxLoudness = selectMax ((compatibleMagazines _weapon) apply {_x call FUNC(getAmmoLoudness)});
|
2024-03-21 19:26:46 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
// ace_gunbag_fnc_isMachineGun
|
|
|
|
private _config = _weapon call CBA_fnc_getItemConfig;
|
2015-11-08 20:02:00 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
// Definition of a machine gun by BIS_fnc_itemType
|
|
|
|
private _cursor = getText (_config >> "cursor");
|
|
|
|
|
|
|
|
if (toLowerANSI _cursor in ["", "emptycursor"]) then {
|
|
|
|
_cursor = getText (_config >> "cursorAim");
|
|
|
|
};
|
|
|
|
|
|
|
|
// If unit has a machine gun boost effective loudness 50%
|
|
|
|
if (_cursor == "MG") then {
|
|
|
|
_maxLoudness = _maxLoudness * 1.5;
|
|
|
|
};
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
_maxLoudness
|
|
|
|
}, true];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
TRACE_3("primaryWeapon",_unit,_weapon,_maxLoudness);
|
2015-11-11 02:44:55 +00:00
|
|
|
|
2024-05-24 23:05:19 +00:00
|
|
|
if (_maxLoudness > 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
|
|
|
};
|