2015-01-11 16:42:31 +00:00
|
|
|
/*
|
|
|
|
* Author: KoffeinFlummi, commy2
|
|
|
|
* Handles deafness due to large-caliber weapons going off near the player.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-03-15 21:40:47 +00:00
|
|
|
* 0: Unit - Object the event handler is assigned to <OBJECT>
|
|
|
|
* 1: Firer: Object - Object which fires a weapon near the unit <OBJECT>
|
|
|
|
* 2: Distance - Distance in meters between the unit and firer <NUMBER>
|
|
|
|
* 3: weapon - Fired weapon <STRING>
|
2015-08-30 06:37:14 +00:00
|
|
|
* 4: muzzle - Muzzle that was used (not used) <STRING>
|
|
|
|
* 5: mode - Current mode of the fired weapon (not used) <STRING>
|
2015-03-15 21:40:47 +00:00
|
|
|
* 6: ammo - Ammo used <STRING>
|
2015-01-11 16:42:31 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-03-15 21:40:47 +00:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [clientFiredNearEvent] call ace_hearing_fnc_firedNear
|
2015-08-30 06:37:14 +00:00
|
|
|
* [player, player, 10, "arifle_MX_ACO_pointer_F", "arifle_MX_ACO_pointer_F", "single", "B_65x39_Caseless"] call ace_hearing_fnc_firedNear
|
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-01-11 16:42:31 +00:00
|
|
|
|
2015-08-30 06:37:14 +00:00
|
|
|
params ["_object", "_firer", "_distance", "_weapon", "", "", "_ammo"];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
if (_weapon in ["Throw", "Put"]) exitWith {};
|
2015-06-13 16:42:09 +00:00
|
|
|
if (_distance > 50) exitWith {};
|
2015-04-11 04:21:54 +00:00
|
|
|
|
2016-01-10 00:51:41 +00:00
|
|
|
private _vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttenuation)};
|
|
|
|
private _distance = 1 max _distance;
|
2015-07-11 02:01:32 +00:00
|
|
|
|
2016-01-10 00:51:41 +00:00
|
|
|
private _silencer = switch (_weapon) do {
|
2015-08-13 22:36:36 +00:00
|
|
|
case (primaryWeapon _firer) : {(primaryWeaponItems _firer) select 0};
|
|
|
|
case (secondaryWeapon _firer) : {(secondaryWeaponItems _firer) select 0};
|
|
|
|
case (handgunWeapon _firer) : {(handgunItems _firer) select 0};
|
|
|
|
default {""};
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
2016-01-10 00:51:41 +00:00
|
|
|
private _audibleFireCoef = 1;
|
2015-01-11 16:42:31 +00:00
|
|
|
if (_silencer != "") then {
|
2015-03-15 21:40:47 +00:00
|
|
|
_audibleFireCoef = getNumber (configFile >> "CfgWeapons" >> _silencer >> "ItemInfo" >> "AmmoCoef" >> "audibleFire");
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
2016-01-10 00:51:41 +00:00
|
|
|
private _loudness = GVAR(cacheAmmoLoudness) getVariable (format ["%1%2",_weapon,_ammo]);
|
|
|
|
if (isNil "_loudness") then {
|
|
|
|
private _muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles");
|
|
|
|
private _weaponMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
|
2015-06-13 16:57:02 +00:00
|
|
|
{
|
|
|
|
if (_x != "this") then {
|
2016-01-10 00:51:41 +00:00
|
|
|
private _muzzleMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines");
|
2015-06-13 16:57:02 +00:00
|
|
|
_weaponMagazines append _muzzleMagazines;
|
|
|
|
};
|
2015-08-13 21:42:20 +00:00
|
|
|
} count _muzzles;
|
2015-06-18 09:56:58 +00:00
|
|
|
{
|
2017-05-14 19:48:05 +00:00
|
|
|
private _ammoType = getText(configFile >> "CfgMagazines" >> _x >> "ammo");
|
2015-06-18 09:56:58 +00:00
|
|
|
_weaponMagazines set [_forEachIndex, [_x, _ammoType]];
|
|
|
|
} forEach _weaponMagazines;
|
2015-06-13 16:57:02 +00:00
|
|
|
|
2016-01-10 00:51:41 +00:00
|
|
|
private _magazine = "";
|
|
|
|
{
|
|
|
|
_x params ["_magazineType", "_ammoType"];
|
|
|
|
if (_ammoType == _ammo) exitWith {
|
|
|
|
_magazine = _magazineType;
|
|
|
|
};
|
|
|
|
} count _weaponMagazines;
|
2015-06-13 16:32:48 +00:00
|
|
|
|
2016-01-10 00:51:41 +00:00
|
|
|
if (_magazine == "") then {
|
|
|
|
_loudness = 0;
|
|
|
|
TRACE_2("No mag for Weapon/Ammo??",_weapon,_ammo);
|
|
|
|
} else {
|
|
|
|
private _initSpeed = getNumber(configFile >> "CfgMagazines" >> _magazine >> "initSpeed");
|
|
|
|
private _caliber = getNumber (configFile >> "CfgAmmo" >> _ammo >> "ACE_caliber");
|
|
|
|
_caliber = call {
|
2016-09-30 20:10:20 +00:00
|
|
|
// If explicilty defined, use ACE_caliber
|
|
|
|
if ((count configProperties [(configFile >> "CfgAmmo" >> _ammo), "configName _x == 'ACE_caliber'", false]) == 1) exitWith {_caliber};
|
2016-01-10 00:51:41 +00:00
|
|
|
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 };
|
|
|
|
};
|
2015-06-13 16:32:48 +00:00
|
|
|
|
2016-01-10 00:51:41 +00:00
|
|
|
_loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) / 5;
|
|
|
|
TRACE_6("building cache",_weapon,_ammo,_magazine,_initSpeed,_caliber,_loudness);
|
|
|
|
};
|
|
|
|
GVAR(cacheAmmoLoudness) setVariable [(format ["%1%2",_weapon,_ammo]), _loudness];
|
2015-06-13 15:43:27 +00:00
|
|
|
};
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2016-01-10 00:51:41 +00:00
|
|
|
_loudness = _loudness * _audibleFireCoef;
|
|
|
|
private _strength = _vehAttenuation * (_loudness - (_loudness / 50 * _distance)); // linear drop off
|
|
|
|
|
|
|
|
TRACE_1("result",_strength);
|
2015-06-13 16:19:35 +00:00
|
|
|
|
2015-01-11 16:42:31 +00:00
|
|
|
if (_strength < 0.01) exitWith {};
|
|
|
|
|
2016-02-06 16:59:31 +00:00
|
|
|
// Call inmediately, as it will get pick up later anyway by the update thread
|
2016-02-16 18:58:42 +00:00
|
|
|
[_strength] call FUNC(earRinging);
|