From 671aa5163f0f0cd2b8e7fba127b0fec93c4958b7 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:02:07 -0300 Subject: [PATCH] Ballistics - Improve arsenal muzzle velocity stat (#10594) --- ...atTextStatement_magazineMuzzleVelocity.sqf | 50 ++++------------ ...statTextStatement_weaponMuzzleVelocity.sqf | 57 +++++++++---------- addons/ballistics/script_component.hpp | 2 + 3 files changed, 39 insertions(+), 70 deletions(-) diff --git a/addons/ballistics/functions/fnc_statTextStatement_magazineMuzzleVelocity.sqf b/addons/ballistics/functions/fnc_statTextStatement_magazineMuzzleVelocity.sqf index a57a52bba7c..994a667eb2f 100644 --- a/addons/ballistics/functions/fnc_statTextStatement_magazineMuzzleVelocity.sqf +++ b/addons/ballistics/functions/fnc_statTextStatement_magazineMuzzleVelocity.sqf @@ -4,7 +4,7 @@ * Text statement for the magazine ammo muzzle velocity stat. * * Arguments: - * 0: Type what it is here (unused) + * 0: Stats (unused) * 1: Item config path * * Return Value: @@ -13,47 +13,17 @@ * Public: No */ -params ["", "_configMagazine"]; +params ["_stats", "_configMagazine"]; -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"]; +private _magClass = configName _configMagazine; +private _weapons = [primaryWeapon EGVAR(arsenal,center), handgunWeapon EGVAR(arsenal,center)]; +private _weaponIndex = _weapons findIf {_x canAdd [_magClass, _x]}; -// we might be looking at random mags not related to our weapon -private _magIsForCurrentWeapon = (configName _configMagazine == _magazine) && {_weapon != ""}; -private _configWeapon = configNull; +// Defer to weapon stat if mag fits in the primary muzzle of an equipped weapon (except launchers) +if (_weaponIndex != -1) exitWith { + [_stats, configFile >> "CfgWeapons" >> _weapons select _weaponIndex, _configMagazine] call FUNC(statTextStatement_weaponMuzzleVelocity); +}; 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; -}; -private _abAdjustText = ""; -if ( - _magIsForCurrentWeapon && - {missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]} && - {missionNamespace getVariable [QEGVAR(advanced_ballistics,barrelLengthInfluenceEnabled), false]} // this can be on while AB is off or vice-versa -) 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] +format ["%1 m/s (%2 ft/s)", _muzzleVelocity toFixed 0, (_muzzleVelocity * METERS_TO_FEET_MULT) toFixed 0] diff --git a/addons/ballistics/functions/fnc_statTextStatement_weaponMuzzleVelocity.sqf b/addons/ballistics/functions/fnc_statTextStatement_weaponMuzzleVelocity.sqf index e11c7cf5fb6..03123f14d08 100644 --- a/addons/ballistics/functions/fnc_statTextStatement_weaponMuzzleVelocity.sqf +++ b/addons/ballistics/functions/fnc_statTextStatement_weaponMuzzleVelocity.sqf @@ -4,8 +4,9 @@ * Text statement for the weapon muzzle velocity stat. * * Arguments: - * 0: Type what it is here (unused) - * 1: Item config path + * 0: Stats (unused) + * 1: Weapon config path + * 2: Magazine config path (default: configNull) * * Return Value: * Display text @@ -13,21 +14,32 @@ * Public: No */ -params ["", "_configWeapon"]; +params ["", "_configWeapon", ["_configMagazine", configNull]]; -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 (isNull _configMagazine) then { // Get the current weapon's mag + _configMagazine = configFile >> "CfgMagazines" >> (weaponState EGVAR(arsenal,center)) select 3;; +}; -if (_magazine isEqualTo "") then { +if (isNull _configMagazine) exitWith { // Nothing in the magwell localize "str_empty"; +}; + +private _muzzleVelocity = getNumber (_configMagazine >> "initSpeed"); + +private _abAdjustText = ""; +private _useAB = missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false] && {EGVAR(advanced_ballistics,barrelLengthInfluenceEnabled)}; + +if (_useAB) 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; + }; } else { - private _configMagazine = configFile >> "CfgMagazines" >> _magazine; - private _muzzleVelocity = getNumber (_configMagazine >> "initSpeed"); private _initSpeedCoef = getNumber (_configWeapon >> "initSpeed"); if (_initSpeedCoef < 0) then { _muzzleVelocity = _muzzleVelocity * -_initSpeedCoef; @@ -35,21 +47,6 @@ if (_magazine isEqualTo "") then { if (_initSpeedCoef > 0) then { _muzzleVelocity = _initSpeedCoef; }; - - private _abAdjustText = ""; - if ( - missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false] && - {missionNamespace getVariable [QEGVAR(advanced_ballistics,barrelLengthInfluenceEnabled), false]} // this can be on while AB is off or vice-versa - ) 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] }; + +format ["%1 m/s (%2 ft/s)%3", _muzzleVelocity toFixed 0, (_muzzleVelocity * METERS_TO_FEET_MULT) toFixed 0, _abAdjustText] diff --git a/addons/ballistics/script_component.hpp b/addons/ballistics/script_component.hpp index a1b54b53b48..8cb4be327b0 100644 --- a/addons/ballistics/script_component.hpp +++ b/addons/ballistics/script_component.hpp @@ -15,3 +15,5 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" + +#define METERS_TO_FEET_MULT 3.28084