From 98e189bfb49ca411de9776e98350ca357ba9fbb1 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 4 Oct 2023 13:21:07 -0500 Subject: [PATCH] Arsenal - Always show muzzle velocity even if not configured for AB (#9457) --- ...atTextStatement_magazineMuzzleVelocity.sqf | 51 +++++++++++-------- ...statTextStatement_weaponMuzzleVelocity.sqf | 41 ++++++++------- 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/addons/ballistics/functions/fnc_statTextStatement_magazineMuzzleVelocity.sqf b/addons/ballistics/functions/fnc_statTextStatement_magazineMuzzleVelocity.sqf index 49eb43302e..04e9f4d327 100644 --- a/addons/ballistics/functions/fnc_statTextStatement_magazineMuzzleVelocity.sqf +++ b/addons/ballistics/functions/fnc_statTextStatement_magazineMuzzleVelocity.sqf @@ -13,36 +13,43 @@ * Public: No */ -params ["", "_config"]; +params ["", "_configMagazine"]; if (EGVAR(arsenal,currentLeftPanel) == 2002) then { private _primaryMag = primaryWeaponMagazine EGVAR(arsenal,center); - - [primaryWeapon EGVAR(arsenal,center), configName _config] + [primaryWeapon EGVAR(arsenal,center), _primaryMag param [0, ""]] } else { private _primaryMag = handgunMagazine EGVAR(arsenal,center); - - [handgunWeapon EGVAR(arsenal,center), configName _config] + [handgunWeapon EGVAR(arsenal,center), _primaryMag param [0, ""]] } params ["_weapon", "_magazine"]; -if (_magazine isEqualTo "") then { - localize "str_empty"; -} else { - private _weaponCfg = configFile >> "CfgWeapons" >> _weapon; - private _ammoCfg = (configFile >> "CfgAmmo" >> (getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"))); - private _barrelLength = getNumber (_weaponCfg >> "ACE_barrelLength"); - private _muzzleVelocityTable = getArray (_ammoCfg >> "ACE_muzzleVelocities"); - private _barrelLengthTable = getArray (_ammoCfg >> "ACE_barrelLengths"); +// we might be looking at random mags not related to our weapon +private _magIsForCurrentWeapon = (configName _configMagazine == _magazine) && {_weapon != ""}; +private _configWeapon = configNull; - if (_barrelLength != 0 && {count _muzzleVelocityTable > 0} && {count _barrelLengthTable > 0}) then { - private _muzzleVelocity = if (["ace_advanced_ballistics"] call EFUNC(common,isModLoaded)) then { - [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, 0] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift); - } else { - getNumber (_config >> "initSpeed") - }; +private _muzzleVelocity = getNumber (_configMagazine >> "initSpeed"); +private _initSpeedCoef = 0; +if (_magIsForCurrentWeapon) then { + _configWeapon = configFile >> "CfgWeapons" >> _weapon; + _initSpeedCoef = getNumber (_configWeapon >> "initSpeed"); +}; +if (_initSpeedCoef < 0) then { + _muzzleVelocity = _muzzleVelocity * -_initSpeedCoef; +}; +if (_initSpeedCoef > 0) then { + _muzzleVelocity = _initSpeedCoef; +}; - format ["%1 m/s (%2 ft/s)", _muzzleVelocity toFixed 0, (_muzzleVelocity * 3.28084) toFixed 0] - } else { - localize "str_empty"; +private _abAdjustText = ""; +if (_magIsForCurrentWeapon && {["ace_advanced_ballistics"] call EFUNC(common,isModLoaded)}) then { + private _configAmmo = (configFile >> "CfgAmmo" >> (getText (_configMagazine >> "ammo"))); + private _barrelLength = getNumber (_configWeapon >> "ACE_barrelLength"); + private _muzzleVelocityTable = getArray (_configAmmo >> "ACE_muzzleVelocities"); + private _barrelLengthTable = getArray (_configAmmo >> "ACE_barrelLengths"); + private _abShift = [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, 0] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift); + if (_abShift != 0) then { + _abAdjustText = " [AB]", + _muzzleVelocity = _abShift; }; }; +format ["%1 m/s (%2 ft/s)%3", _muzzleVelocity toFixed 0, (_muzzleVelocity * 3.28084) toFixed 0, _abAdjustText] diff --git a/addons/ballistics/functions/fnc_statTextStatement_weaponMuzzleVelocity.sqf b/addons/ballistics/functions/fnc_statTextStatement_weaponMuzzleVelocity.sqf index a720935c74..4f6bdd0412 100644 --- a/addons/ballistics/functions/fnc_statTextStatement_weaponMuzzleVelocity.sqf +++ b/addons/ballistics/functions/fnc_statTextStatement_weaponMuzzleVelocity.sqf @@ -13,35 +13,40 @@ * Public: No */ -params ["", "_config"]; +params ["", "_configWeapon"]; if (EGVAR(arsenal,currentLeftPanel) == 2002) then { private _primaryMag = primaryWeaponMagazine EGVAR(arsenal,center); - [primaryWeapon EGVAR(arsenal,center), _primaryMag param [0, ""]] } else { private _primaryMag = handgunMagazine EGVAR(arsenal,center); - [handgunWeapon EGVAR(arsenal,center), _primaryMag param [0, ""]] } params ["_weapon", "_magazine"]; if (_magazine isEqualTo "") then { localize "str_empty"; } else { - private _ammoCfg = (configFile >> "CfgAmmo" >> (getText (configFile >> "CfgMagazines" >> _magazine >> "ammo"))); - private _barrelLength = getNumber (_config >> "ACE_barrelLength"); - private _muzzleVelocityTable = getArray (_ammoCfg >> "ACE_muzzleVelocities"); - private _barrelLengthTable = getArray (_ammoCfg >> "ACE_barrelLengths"); - - if (_barrelLength != 0 && {count _muzzleVelocityTable > 0} && {count _barrelLengthTable > 0}) then { - private _muzzleVelocity = if (["ace_advanced_ballistics"] call EFUNC(common,isModLoaded)) then { - [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, 0] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift); - } else { - getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed") - }; - - format ["%1 m/s (%2 ft/s)", _muzzleVelocity toFixed 0, (_muzzleVelocity * 3.28084) toFixed 0] - } else { - localize "str_empty"; + private _configMagazine = configFile >> "CfgMagazines" >> _magazine; + private _muzzleVelocity = getNumber (_configMagazine >> "initSpeed"); + private _initSpeedCoef = getNumber (_configWeapon >> "initSpeed"); + if (_initSpeedCoef < 0) then { + _muzzleVelocity = _muzzleVelocity * -_initSpeedCoef; }; + if (_initSpeedCoef > 0) then { + _muzzleVelocity = _initSpeedCoef; + }; + + private _abAdjustText = ""; + if (["ace_advanced_ballistics"] call EFUNC(common,isModLoaded)) then { + private _configAmmo = (configFile >> "CfgAmmo" >> (getText (_configMagazine >> "ammo"))); + private _barrelLength = getNumber (_configWeapon >> "ACE_barrelLength"); + private _muzzleVelocityTable = getArray (_configAmmo >> "ACE_muzzleVelocities"); + private _barrelLengthTable = getArray (_configAmmo >> "ACE_barrelLengths"); + private _abShift = [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, 0] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift); + if (_abShift != 0) then { + _abAdjustText = " [AB]", + _muzzleVelocity = _abShift; + }; + }; + format ["%1 m/s (%2 ft/s)%3", _muzzleVelocity toFixed 0, (_muzzleVelocity * 3.28084) toFixed 0, _abAdjustText] };