2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-11-07 11:01:36 +00:00
|
|
|
/*
|
|
|
|
* Author: Ruthberg
|
|
|
|
* Calculates the zero angle correction for the new zero range based on current zero range and bore height (distance between bore- and sight axis)
|
|
|
|
*
|
|
|
|
* Arguments:
|
2024-03-24 16:32:28 +00:00
|
|
|
* 0: Old Zero range <NUMBER>
|
|
|
|
* 1: New Zero range <NUMBER>
|
|
|
|
* 2: Bore height <NUMBER>
|
|
|
|
* 3: Weapon <OBJECT>
|
|
|
|
* 4: Ammo <STRING>
|
|
|
|
* 5: Magazine <STRING>
|
|
|
|
* 6: Advanced Ballistics enabled? <BOOL>
|
2016-11-07 11:01:36 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* zeroAngleCorrection <NUMBER>
|
|
|
|
*
|
|
|
|
* Example:
|
2024-03-24 16:32:28 +00:00
|
|
|
* [5, 6, 7, gun, ammo, magazine, true] call ace_scopes_fnc_calculateZeroAngleCorrection
|
2016-11-07 11:01:36 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_oldZeroRange", "_newZeroRange", "_boreHeight"/*in cm*/, "_weapon", "_ammo", "_magazine", "_advancedBallistics"];
|
|
|
|
|
2024-03-24 16:32:28 +00:00
|
|
|
// When FFV from vehicles currentZeroing will report 0 so just bail
|
|
|
|
if (_oldZeroRange <= 0) exitWith { 0 };
|
|
|
|
|
2016-11-09 13:00:25 +00:00
|
|
|
private _airFriction = getNumber (configFile >> "CfgAmmo" >> _ammo >> "airFriction");
|
|
|
|
private _initSpeed = getNumber(configFile >> "CfgMagazines" >> _magazine >> "initSpeed");
|
|
|
|
private _initSpeedCoef = getNumber(configFile >> "CfgWeapons" >> _weapon >> "initSpeed");
|
2016-11-07 11:01:36 +00:00
|
|
|
if (_initSpeedCoef > 0) then {
|
|
|
|
_initSpeed = _initSpeedCoef;
|
|
|
|
};
|
|
|
|
if (_initSpeedCoef < 0) then {
|
|
|
|
_initSpeed = _initSpeed * (-1 * _initSpeedCoef);
|
|
|
|
};
|
|
|
|
|
2024-08-17 15:50:38 +00:00
|
|
|
private _vanillaZero = parseNumber (("ace" callExtension ["ballistics:replicate_vanilla_zero", [_oldZeroRange, _initSpeed, _airFriction]]) select 0);
|
2016-11-09 13:00:25 +00:00
|
|
|
|
2017-11-21 22:56:46 +00:00
|
|
|
#ifdef DISABLE_DISPERSION
|
|
|
|
_vanillaZero = 0;
|
|
|
|
#endif
|
|
|
|
|
2016-11-09 13:00:25 +00:00
|
|
|
private _trueZero = if (!_advancedBallistics) then {
|
2024-08-17 15:50:38 +00:00
|
|
|
parseNumber (("ace" callExtension ["ballistics:zero_vanilla", [_newZeroRange, _initSpeed, _airFriction, _boreHeight]]) select 0)
|
2016-11-09 13:00:25 +00:00
|
|
|
} else {
|
|
|
|
// Get Weapon and Ammo Configurations
|
|
|
|
private _AmmoCacheEntry = uiNamespace getVariable format[QEGVAR(advanced_ballistics,%1), _ammo];
|
|
|
|
if (isNil "_AmmoCacheEntry") then {
|
2024-08-17 15:50:38 +00:00
|
|
|
_AmmoCacheEntry = _ammo call EFUNC(advanced_ballistics,readAmmoDataFromConfig);
|
2016-11-09 13:00:25 +00:00
|
|
|
};
|
|
|
|
private _WeaponCacheEntry = uiNamespace getVariable format[QEGVAR(advanced_ballistics,%1), _weapon];
|
|
|
|
if (isNil "_WeaponCacheEntry") then {
|
2024-08-17 15:50:38 +00:00
|
|
|
_WeaponCacheEntry = _weapon call EFUNC(advanced_ballistics,readWeaponDataFromConfig);
|
2016-11-09 13:00:25 +00:00
|
|
|
};
|
|
|
|
|
2017-11-19 17:48:26 +00:00
|
|
|
_AmmoCacheEntry params ["_airFriction", "_caliber", "_bulletLength", "_bulletMass", "_transonicStabilityCoef", "_dragModel", "_ballisticCoefficients", "_velocityBoundaries", "_atmosphereModel", "_ammoTempMuzzleVelocityShifts", "_muzzleVelocityTable", "_barrelLengthTable", "_muzzleVelocityVariationSD"];
|
2016-11-09 13:00:25 +00:00
|
|
|
_WeaponCacheEntry params ["_barrelTwist", "_twistDirection", "_barrelLength"];
|
|
|
|
|
2016-11-07 11:01:36 +00:00
|
|
|
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,barrelLengthInfluenceEnabled), false]) then {
|
|
|
|
private _barrelVelocityShift = [_barrelLength, _muzzleVelocityTable, _barrelLengthTable, _initSpeed] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift);
|
|
|
|
_initSpeed = _initSpeed + _barrelVelocityShift;
|
|
|
|
};
|
|
|
|
|
2017-11-11 13:15:59 +00:00
|
|
|
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,ammoTemperatureEnabled), false]) then {
|
|
|
|
private _ammoTemperatureVelocityShift = ([_ammoTempMuzzleVelocityShifts, GVAR(zeroReferenceTemperature)] call EFUNC(advanced_ballistics,calculateAmmoTemperatureVelocityShift));
|
|
|
|
_initSpeed = _initSpeed + _ammoTemperatureVelocityShift;
|
|
|
|
};
|
|
|
|
|
2024-08-17 15:50:38 +00:00
|
|
|
parseNumber (
|
|
|
|
("ace" callExtension ["ballistics:zero_advanced", [
|
|
|
|
_newZeroRange,
|
|
|
|
_initSpeed,
|
|
|
|
_boreHeight,
|
|
|
|
GVAR(zeroReferenceTemperature),
|
|
|
|
GVAR(zeroReferenceBarometricPressure),
|
|
|
|
GVAR(zeroReferenceHumidity),
|
|
|
|
_ballisticCoefficients select 0,
|
|
|
|
_dragModel,
|
|
|
|
_atmosphereModel
|
|
|
|
]]) select 0
|
|
|
|
)
|
2016-11-09 13:00:25 +00:00
|
|
|
};
|
2016-11-07 11:01:36 +00:00
|
|
|
|
2016-11-09 13:00:25 +00:00
|
|
|
private _zeroAngleCorrection = _trueZero - _vanillaZero;
|
2016-11-07 11:01:36 +00:00
|
|
|
|
|
|
|
missionNamespace setVariable [format[QGVAR(%1_%2_%3_%4_%5_%6_%7), _oldZeroRange, _newZeroRange, _boreHeight, _weapon, _ammo, _magazine, _advancedBallistics], _zeroAngleCorrection];
|
|
|
|
|
|
|
|
_zeroAngleCorrection
|