diff --git a/addons/rangecard/CfgVehicles.hpp b/addons/rangecard/CfgVehicles.hpp index e7df7014093..7abc8d979b0 100644 --- a/addons/rangecard/CfgVehicles.hpp +++ b/addons/rangecard/CfgVehicles.hpp @@ -34,7 +34,7 @@ class CfgVehicles { class GVAR(makeCopy) { displayName = CSTRING(CopyRangeCard); condition = QUOTE(call FUNC(canShow) && !GVAR(RangeCardOpened)); - statement = QUOTE(GVAR(ammoClassCopy) = GVAR(ammoClass); GVAR(magazineClassCopy) = GVAR(magazineClass); GVAR(weaponClassCopy) = GVAR(ammoClass);); + statement = QUOTE(GVAR(zeroRangeCopy)=GVAR(zeroRange); GVAR(boreHeightCopy)=GVAR(boreHeight); GVAR(ammoClassCopy)=GVAR(ammoClass); GVAR(magazineClassCopy)=GVAR(magazineClass); GVAR(weaponClassCopy)=GVAR(weaponClass);); showDisabled = 0; priority = 0.1; icon = QPATHTOF(UI\RangeCard_Icon.paa); diff --git a/addons/rangecard/XEH_postInit.sqf b/addons/rangecard/XEH_postInit.sqf index 55005fd0a80..9e60821fc1b 100644 --- a/addons/rangecard/XEH_postInit.sqf +++ b/addons/rangecard/XEH_postInit.sqf @@ -7,11 +7,13 @@ GVAR(RangeCardOpened) = false; GVAR(controls) = []; GVAR(zeroRange) = 100; +GVAR(boreHeight) = 3.81; GVAR(ammoClass) = "B_65x39_Caseless"; GVAR(magazineClass) = "30Rnd_65x39_caseless_mag"; GVAR(weaponClass) = "arifle_MXM_F"; GVAR(zeroRangeCopy) = 100; +GVAR(boreHeightCopy) = 3.81; GVAR(ammoClassCopy) = "";//"ACE_762x51_Ball_M118LR"; GVAR(magazineClassCopy) = "";//"ACE_20Rnd_762x51_M118LR_Mag"; GVAR(weaponClassCopy) = "";//srifle_DMR_06_olive_F"; diff --git a/addons/rangecard/functions/fnc_openRangeCard.sqf b/addons/rangecard/functions/fnc_openRangeCard.sqf index e73cdebd2a6..4a9945e5137 100644 --- a/addons/rangecard/functions/fnc_openRangeCard.sqf +++ b/addons/rangecard/functions/fnc_openRangeCard.sqf @@ -23,7 +23,7 @@ if (_this) then { createDialog "ACE_RangeCard_Dialog"; - [GVAR(zeroRangeCopy), GVAR(ammoClassCopy), GVAR(magazineClassCopy), GVAR(weaponClassCopy)] call FUNC(updateRangeCard); + [GVAR(zeroRangeCopy), GVAR(boreHeightCopy), GVAR(ammoClassCopy), GVAR(magazineClassCopy), GVAR(weaponClassCopy)] call FUNC(updateRangeCard); }; } else { if (ACE_player call FUNC(updateClassNames)) then { @@ -31,6 +31,6 @@ if (_this) then { createDialog "ACE_RangeCard_Dialog"; - [GVAR(zeroRange), GVAR(ammoClass), GVAR(magazineClass), GVAR(weaponClass)] call FUNC(updateRangeCard); + [GVAR(zeroRange), GVAR(boreHeight), GVAR(ammoClass), GVAR(magazineClass), GVAR(weaponClass)] call FUNC(updateRangeCard); }; }; diff --git a/addons/rangecard/functions/fnc_updateClassNames.sqf b/addons/rangecard/functions/fnc_updateClassNames.sqf index be9256650a9..12f9c5c2e85 100644 --- a/addons/rangecard/functions/fnc_updateClassNames.sqf +++ b/addons/rangecard/functions/fnc_updateClassNames.sqf @@ -38,11 +38,13 @@ if (_ammoClass == "") exitWith { (GVAR(ammoClass) != "" && GVAR(magazineClass) ! if (_unit == ACE_player) then { GVAR(zeroRange) = [_unit] call EFUNC(scopes,getCurrentZeroRange); + GVAR(boreHeight) = [_unit, 0] call EFUNC(scopes,getBoreHeight); GVAR(ammoClass) = _ammoClass; GVAR(magazineClass) = _magazineClass; GVAR(weaponClass) = _weaponClass; } else { GVAR(zeroRangeCopy) = [_unit] call EFUNC(scopes,getCurrentZeroRange); + GVAR(boreHeightCopy) = [_unit, 0] call EFUNC(scopes,getBoreHeight); GVAR(ammoClassCopy) = _ammoClass; GVAR(magazineClassCopy) = _magazineClass; GVAR(weaponClassCopy) = _weaponClass; diff --git a/addons/rangecard/functions/fnc_updateRangeCard.sqf b/addons/rangecard/functions/fnc_updateRangeCard.sqf index 23a63641c54..e62a5ee4187 100644 --- a/addons/rangecard/functions/fnc_updateRangeCard.sqf +++ b/addons/rangecard/functions/fnc_updateRangeCard.sqf @@ -4,9 +4,10 @@ * * Arguments: * 0: zero range - * 1: ammo class - * 2: magazine class - * 3: weapon class + * 1: bore height + * 2: ammo class + * 3: magazine class + * 4: weapon class * * Return Value: * Nothing @@ -21,9 +22,9 @@ disableSerialization; #define __dsp (uiNamespace getVariable "RangleCard_Display") -private ["_airFriction", "_ammoConfig", "_atmosphereModel", "_transonicStabilityCoef", "_barrelLength", "_barrelTwist", "_bc", "_boreHeight", "_cacheEntry", "_column", "_control", "_dragModel", "_i", "_muzzleVelocity", "_offset", "_row", "_weaponConfig", "_initSpeed", "_initSpeedCoef"]; +private ["_airFriction", "_ammoConfig", "_atmosphereModel", "_transonicStabilityCoef", "_barrelLength", "_barrelTwist", "_bc", "_cacheEntry", "_column", "_control", "_dragModel", "_i", "_muzzleVelocity", "_offset", "_row", "_weaponConfig", "_initSpeed", "_initSpeedCoef"]; -params ["_zeroRange", "_ammoClass", "_magazineClass", "_weaponClass"]; +params ["_zeroRange", "_boreHeight", "_ammoClass", "_magazineClass", "_weaponClass"]; if (_ammoClass == "" || _magazineClass == "" || _weaponClass == "") exitWith {}; @@ -106,7 +107,6 @@ if (count (_ammoConfig select 6) > 0) then { _transonicStabilityCoef = _ammoConfig select 4; _dragModel = _ammoConfig select 5; _atmosphereModel = _ammoConfig select 8; -_boreHeight = 3.81; private _useABConfig = (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]); if (_bc == 0) then { @@ -157,7 +157,7 @@ if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) t ctrlSetText [77004 , ""]; }; -_cacheEntry = missionNamespace getVariable format[QGVAR(%1_%2_%3_%4), _zeroRange, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]]; +_cacheEntry = missionNamespace getVariable format[QGVAR(%1_%2_%3_%4_%5), _zeroRange, _boreHeight, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]]; if (isNil {_cacheEntry}) then { private _scopeBaseAngle = if (!_useABConfig) then { private _zeroAngle = "ace_advanced_ballistics" callExtension format ["zeroAngleVanilla:%1:%2:%3:%4", _zeroRange, _muzzleVelocity, _airFriction, _boreHeight]; @@ -192,7 +192,7 @@ if (isNil {_cacheEntry}) then { }; }; - missionNamespace setVariable [format[QGVAR(%1_%2_%3_%4), _zeroRange, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]], [GVAR(rangeCardDataElevation), GVAR(rangeCardDataWindage), GVAR(rangeCardDataLead), GVAR(rangeCardDataMVs), GVAR(lastValidRow)]]; + missionNamespace setVariable [format[QGVAR(%1_%2_%3_%4_%5), _zeroRange, _boreHeight, _ammoClass, _weaponClass, missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]], [GVAR(rangeCardDataElevation), GVAR(rangeCardDataWindage), GVAR(rangeCardDataLead), GVAR(rangeCardDataMVs), GVAR(lastValidRow)]]; } else { GVAR(rangeCardDataElevation) = _cacheEntry select 0; GVAR(rangeCardDataWindage) = _cacheEntry select 1; @@ -243,7 +243,7 @@ for "_column" from 0 to 8 do { if (_useABConfig) then { ctrlSetText [770020, "For best results keep ammunition at ambient air temperature. Tables calculated for the above listed barrel"]; - ctrlSetText [770021, "and load with optic mounted 1.5'' above line of bore."]; + ctrlSetText [770021, format["and load with optic mounted %1'' above line of bore.", round((_boreHeight / 2.54) * 10) / 10]]; } else { ctrlSetText [770020, ""]; ctrlSetText [770021, ""]; diff --git a/addons/scopes/XEH_PREP.hpp b/addons/scopes/XEH_PREP.hpp index 8d791966508..a8489fe5855 100644 --- a/addons/scopes/XEH_PREP.hpp +++ b/addons/scopes/XEH_PREP.hpp @@ -5,6 +5,7 @@ PREP(applyScopeAdjustment); PREP(calculateZeroAngleCorrection); PREP(canAdjustZero); PREP(firedEH); +PREP(getBoreHeight); PREP(getCurrentZeroRange); PREP(getOptics); PREP(initModuleSettings); diff --git a/addons/scopes/functions/fnc_getBoreHeight.sqf b/addons/scopes/functions/fnc_getBoreHeight.sqf new file mode 100644 index 00000000000..fb061e5d469 --- /dev/null +++ b/addons/scopes/functions/fnc_getBoreHeight.sqf @@ -0,0 +1,57 @@ +/* + * Author: Ruthberg + * Gets the bore height of the weapon & optic combination with the given weapon index + * + * Arguments: + * 0: Unit + * 1: Weapon index + * + * Return Value: + * bore height + * + * Example: + * [player] call ace_scopes_fnc_getBoreHeight + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_player", "_weaponIndex"]; + +if (_weaponIndex < 0 || {_weaponIndex > 2}) exitWith { 0 }; + +private _weaponClass = [primaryWeapon _player, secondaryWeapon _player, handgunWeapon _player] select _weaponIndex; +private _opticsClass = ([_player] call FUNC(getOptics)) select _weaponIndex; + +if (_opticsClass == "") then { _opticsClass = _weaponClass; }; + +// Determine rail height above bore +private _railHeightAboveBore = 0; +private _weaponConfig = configFile >> "CfgWeapons" >> _weaponClass; +if (isNumber (_weaponConfig >> "ACE_RailHeightAboveBore")) then { + _railHeightAboveBore = getNumber(_weaponConfig >> "ACE_RailHeightAboveBore"); +} else { + switch (_weaponIndex) do { + case 0: { _railHeightAboveBore = 2.0; }; // Rifle + case 2: { _railHeightAboveBore = 0.7; }; // Pistol + }; +}; +// Determine scope height above rail +private _scopeHeightAboveRail = 0; +private _opticConfig = configFile >> "CfgWeapons" >> _opticsClass; +if (isNumber (_opticConfig >> "ACE_ScopeHeightAboveRail")) then { + _scopeHeightAboveRail = getNumber(_opticConfig >> "ACE_ScopeHeightAboveRail"); +} else { + switch (getNumber(_opticConfig >> "ItemInfo" >> "opticType")) do { + case 1: { _scopeHeightAboveRail = 3.0; }; // RCO or similar + case 2: { _scopeHeightAboveRail = 4.0; }; // High power scope + default { + switch (_weaponIndex) do { + case 0: { _scopeHeightAboveRail = 0.5; }; // Rifle iron sights + case 2: { _scopeHeightAboveRail = 0.3; }; // Pistol iron sights + }; + }; + }; +}; + +(_railHeightAboveBore + _scopeHeightAboveRail) diff --git a/addons/scopes/functions/fnc_getCurrentZeroRange.sqf b/addons/scopes/functions/fnc_getCurrentZeroRange.sqf index a82bd0714e2..7af8d2e3e93 100644 --- a/addons/scopes/functions/fnc_getCurrentZeroRange.sqf +++ b/addons/scopes/functions/fnc_getCurrentZeroRange.sqf @@ -6,10 +6,10 @@ * 0: Unit * * Return Value: - * current zero range + * current zero range * * Example: - * _unit call ace_scopes_fnc_getCurrentZeroRange + * [player] call ace_scopes_fnc_getCurrentZeroRange * * Public: No */ diff --git a/addons/scopes/functions/fnc_inventoryCheck.sqf b/addons/scopes/functions/fnc_inventoryCheck.sqf index bb68b6ee172..2af9c56ec03 100644 --- a/addons/scopes/functions/fnc_inventoryCheck.sqf +++ b/addons/scopes/functions/fnc_inventoryCheck.sqf @@ -69,35 +69,8 @@ private _newGuns = [primaryWeapon _player, secondaryWeapon _player, handgunWeapo _adjustment set [_forEachIndex, [0, 0, 0]]; _updateAdjustment = true; }; - // Determine rail height above bore - private _railHeightAboveBore = 0; - private _weaponConfig = configFile >> "CfgWeapons" >> (_newGuns select _x); - if (isNumber (_weaponConfig >> "ACE_RailHeightAboveBore")) then { - _railHeightAboveBore = getNumber(_weaponConfig >> "ACE_RailHeightAboveBore"); - } else { - switch (_x) do { - case 0: { _railHeightAboveBore = 2.0; }; // Rifle - case 2: { _railHeightAboveBore = 0.7; }; // Pistol - }; - }; - // Determine scope height above rail - private _scopeHeightAboveRail = 0; - private _opticConfig = configFile >> "CfgWeapons" >> (_newOptics select _x); - if (isNumber (_opticConfig >> "ACE_ScopeHeightAboveRail")) then { - _scopeHeightAboveRail = getNumber(_opticConfig >> "ACE_ScopeHeightAboveRail"); - } else { - switch (getNumber(_opticConfig >> "ItemInfo" >> "opticType")) do { - case 1: { _scopeHeightAboveRail = 3.0; }; // RCO or similar - case 2: { _scopeHeightAboveRail = 4.0; }; // High power scope - default { - switch (_x) do { - case 0: { _scopeHeightAboveRail = 0.5; }; // Rifle iron sights - case 2: { _scopeHeightAboveRail = 0.3; }; // Pistol iron sights - }; - }; - }; - }; - GVAR(boreHeight) set [_x, _railHeightAboveBore + _scopeHeightAboveRail]; + + GVAR(boreHeight) set [_x, [_player, _x] call FUNC(getBoreHeight)]; if ((_newOptics select _x) == "") then { // Check if the weapon comes with an integrated optic