mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #3200 from acemod/moreCache
Hearing - Cache Weapon/Ammo loudness
This commit is contained in:
commit
73b29085e2
@ -2,6 +2,9 @@
|
||||
|
||||
if (!hasInterface) exitWith {};
|
||||
|
||||
GVAR(cacheAmmoLoudness) = createLocation ["ACE_HashLocation", [-10000,-10000,-10000], 0, 0];
|
||||
GVAR(cacheAmmoLoudness) setText QGVAR(cacheAmmoLoudness);
|
||||
|
||||
GVAR(deafnessDV) = 0;
|
||||
GVAR(deafnessPrior) = 0;
|
||||
GVAR(volume) = 1;
|
||||
|
@ -28,11 +28,12 @@ if (_unit getVariable ["ACE_hasEarPlugsin", false]) then {
|
||||
|
||||
//headgear hearing protection
|
||||
if(headgear _unit != "") then {
|
||||
private ["_protection"];
|
||||
_protection = (getNumber (configFile >> "CfgWeapons" >> (headgear _unit) >> QGVAR(protection))) min 1;
|
||||
private _protection = (getNumber (configFile >> "CfgWeapons" >> (headgear _unit) >> QGVAR(protection))) min 1;
|
||||
if(_protection > 0) then {
|
||||
_strength = _strength * (1 - _protection);
|
||||
};
|
||||
};
|
||||
|
||||
TRACE_2("adding",_strength,GVAR(deafnessDV));
|
||||
|
||||
GVAR(deafnessDV) = GVAR(deafnessDV) + _strength;
|
||||
|
@ -32,31 +32,28 @@ if ((ACE_player != _object) && {(vehicle ACE_player) != _object}) exitWith {};
|
||||
if (_weapon in ["Throw", "Put"]) exitWith {};
|
||||
if (_distance > 50) exitWith {};
|
||||
|
||||
private ["_silencer", "_audibleFireCoef", "_loudness", "_strength", "_vehAttenuation", "_magazine", "_muzzles", "_weaponMagazines", "_muzzleMagazines", "_ammoType", "_initSpeed", "_ammoConfig", "_caliber"];
|
||||
private _vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttenuation)};
|
||||
private _distance = 1 max _distance;
|
||||
|
||||
_vehAttenuation = if ((ACE_player == (vehicle ACE_player)) || {isTurnedOut ACE_player}) then {1} else {GVAR(playerVehAttenuation)};
|
||||
|
||||
_distance = 1 max _distance;
|
||||
|
||||
_silencer = switch (_weapon) do {
|
||||
private _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;
|
||||
private _audibleFireCoef = 1;
|
||||
if (_silencer != "") then {
|
||||
_audibleFireCoef = getNumber (configFile >> "CfgWeapons" >> _silencer >> "ItemInfo" >> "AmmoCoef" >> "audibleFire");
|
||||
};
|
||||
|
||||
_weaponMagazines = missionNamespace getVariable [format[QEGVAR(common,weaponMagazines_%1),_weapon], []];
|
||||
if (count _weaponMagazines == 0) then {
|
||||
_muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles");
|
||||
_weaponMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
|
||||
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");
|
||||
{
|
||||
if (_x != "this") then {
|
||||
_muzzleMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines");
|
||||
private _muzzleMagazines = getArray (configFile >> "CfgWeapons" >> _weapon >> _x >> "magazines");
|
||||
_weaponMagazines append _muzzleMagazines;
|
||||
};
|
||||
} count _muzzles;
|
||||
@ -64,34 +61,39 @@ if (count _weaponMagazines == 0) then {
|
||||
_ammoType = getText(configFile >> "CfgMagazines" >> _x >> "ammo");
|
||||
_weaponMagazines set [_forEachIndex, [_x, _ammoType]];
|
||||
} forEach _weaponMagazines;
|
||||
missionNamespace setVariable [format[QEGVAR(common,weaponMagazines_%1),_weapon], _weaponMagazines];
|
||||
};
|
||||
|
||||
_magazine = "";
|
||||
{
|
||||
_x params ["_magazineType", "_ammoType"];
|
||||
if (_ammoType == _ammo) exitWith {
|
||||
_magazine = _magazineType;
|
||||
private _magazine = "";
|
||||
{
|
||||
_x params ["_magazineType", "_ammoType"];
|
||||
if (_ammoType == _ammo) exitWith {
|
||||
_magazine = _magazineType;
|
||||
};
|
||||
} count _weaponMagazines;
|
||||
|
||||
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 {
|
||||
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 };
|
||||
};
|
||||
|
||||
_loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) / 5;
|
||||
TRACE_6("building cache",_weapon,_ammo,_magazine,_initSpeed,_caliber,_loudness);
|
||||
};
|
||||
} count _weaponMagazines;
|
||||
|
||||
if (_magazine == "") exitWith {};
|
||||
|
||||
_initSpeed = getNumber(configFile >> "CfgMagazines" >> _magazine >> "initSpeed");
|
||||
_ammoConfig = (configFile >> "CfgAmmo" >> _ammo);
|
||||
_caliber = getNumber(_ammoConfig >> "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 };
|
||||
GVAR(cacheAmmoLoudness) setVariable [(format ["%1%2",_weapon,_ammo]), _loudness];
|
||||
};
|
||||
_loudness = (_caliber ^ 1.25 / 10) * (_initspeed / 1000) * _audibleFireCoef / 5;
|
||||
_strength = _vehAttenuation * (_loudness - (_loudness / 50 * _distance)); // linear drop off
|
||||
|
||||
//systemChat format["%1 : %2", _strength, _initSpeed];
|
||||
//systemChat format["%1 : %2 : %3", _weapon, _magazine, _initSpeed];
|
||||
_loudness = _loudness * _audibleFireCoef;
|
||||
private _strength = _vehAttenuation * (_loudness - (_loudness / 50 * _distance)); // linear drop off
|
||||
|
||||
TRACE_1("result",_strength);
|
||||
|
||||
if (_strength < 0.01) exitWith {};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Author: commy2 and esteldunedain and Ruthberg
|
||||
* Updates and applys the current deafness. Called every 0.1 sec from a PFEH.
|
||||
* Updates and applys the current deafness. Called every 1 sec from a PFEH.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Args <ARRAY>
|
||||
@ -19,7 +19,6 @@
|
||||
//Only run if deafness or ear ringing is enabled:
|
||||
if ((!GVAR(enableCombatDeafness)) && GVAR(DisableEarRinging)) exitWith {};
|
||||
|
||||
private["_volume", "_soundTransitionTime"];
|
||||
(_this select 0) params ["_justUpdateVolume"];
|
||||
|
||||
|
||||
@ -71,7 +70,7 @@ if (!_justUpdateVolume) then {
|
||||
|
||||
if ((missionNameSpace getVariable [QGVAR(disableVolumeUpdate), false]) || {!GVAR(enableCombatDeafness)}) exitWith {};
|
||||
|
||||
_volume = GVAR(volume);
|
||||
private _volume = GVAR(volume);
|
||||
|
||||
// Earplugs reduce hearing 50%
|
||||
if ([ACE_player] call FUNC(hasEarPlugsIn)) then {
|
||||
@ -92,7 +91,7 @@ if (ACE_player getVariable ["ACE_isUnconscious", false]) then {
|
||||
_volume = _volume min GVAR(UnconsciousnessVolume);
|
||||
};
|
||||
|
||||
_soundTransitionTime = if (_justUpdateVolume) then {0.1} else {1};
|
||||
private _soundTransitionTime = if (_justUpdateVolume) then {0.1} else {1};
|
||||
|
||||
_soundTransitionTime fadeSound _volume;
|
||||
_soundTransitionTime fadeSpeech _volume;
|
||||
|
Loading…
Reference in New Issue
Block a user