Skip to content

Commit

Permalink
Ballistics - Respect Advanced Ballistics settings for displaying muzz…
Browse files Browse the repository at this point in the history
…le velocities (#9682)

Co-authored-by: johnb432 <[email protected]>
  • Loading branch information
LinkIsGrim and johnb432 authored Jan 7, 2024
1 parent b588070 commit e9cb274
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ if (_initSpeedCoef > 0) then {
};

private _abAdjustText = "";
if (_magIsForCurrentWeapon && {["ace_advanced_ballistics"] call EFUNC(common,isModLoaded)}) then {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ if (_magazine isEqualTo "") then {
};

private _abAdjustText = "";
if (["ace_advanced_ballistics"] call EFUNC(common,isModLoaded)) then {
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");
Expand Down
25 changes: 21 additions & 4 deletions addons/kestrel4500/functions/fnc_collectData.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* Public: No
*/

#define TEMPERATURE_SLOT_INDEX 5

private _playerDir = getDir ACE_player;
private _playerAltitude = (getPosASL ACE_player) select 2;
private _temperature = _playerAltitude call EFUNC(weather,calculateTemperatureAtHeight);
Expand All @@ -41,17 +43,18 @@ if (isNil QGVAR(MIN) || isNil QGVAR(MAX)) then {
[0, _playerDir] call FUNC(updateMemory);

if (GVAR(MinAvgMaxMode) == 1) then {
private _useAB = missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false];
{
GVAR(ENTRIES) set [_x, (GVAR(ENTRIES) select _x) + 1];
} count [2, 3, 4];
} forEach [2, 3, 4];

// Wind SPD
private _windSpeed = call FUNC(measureWindSpeed);
[2, _windSpeed] call FUNC(updateMemory);

// CROSSWIND
private _crosswind = 0;
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then {
if (_useAB) then {
_crosswind = abs(sin(GVAR(RefHeading) - _playerDir) * _windSpeed);
} else {
_crosswind = abs(sin(GVAR(RefHeading)) * _windSpeed);
Expand All @@ -60,7 +63,7 @@ if (GVAR(MinAvgMaxMode) == 1) then {

// HEADWIND
private _headwind = 0;
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then {
if (_useAB) then {
_headwind = cos(GVAR(RefHeading) - _playerDir) * _windSpeed;
} else {
_headwind = cos(GVAR(RefHeading)) * _windSpeed;
Expand All @@ -74,4 +77,18 @@ if (GVAR(MinAvgMaxMode) == 1) then {
GVAR(TOTAL) set [4, (GVAR(TOTAL) select 4) + _headwind];
};

{ _x call FUNC(updateMemory); true } count [[5, _temperature],[6, _chill],[7, _humidity],[8, _heatIndex],[9, _dewPoint],[10, _wetBulb],[11, _barometricPressure],[12, _altitude],[13, _densityAltitude]];
private _data = [
_temperature,
_chill,
_humidity,
_heatIndex,
_dewPoint,
_wetBulb,
_barometricPressure,
_altitude,
_densityAltitude
];

{
[TEMPERATURE_SLOT_INDEX + _forEachIndex, _x] call FUNC(updateMemory);
} forEach _data;
5 changes: 3 additions & 2 deletions addons/rangecard/functions/fnc_calculateRangeCard.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ private _bulletSpeed = 0;
private _gravity = [0, sin(_scopeBaseAngle) * -GRAVITY, cos(_scopeBaseAngle) * -GRAVITY];
private _deltaT = 1 / _simSteps;
private _speedOfSound = 0;
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then {
private _isABenabled = missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false];
if (_isABenabled) then {
_speedOfSound = _temperature call EFUNC(weather,calculateSpeedOfSound);
};

Expand All @@ -68,7 +69,7 @@ if (_useABConfig) then {
};

private _airFrictionCoef = 1;
if (!_useABConfig && (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false])) then {
if (!_useABConfig && _isABenabled) then {
private _airDensity = [_temperature, _barometricPressure, _relativeHumidity] call EFUNC(weather,calculateAirDensity);
_airFrictionCoef = _airDensity / 1.22498;
};
Expand Down
39 changes: 22 additions & 17 deletions addons/rangecard/functions/fnc_updateRangeCard.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ private _transonicStabilityCoef = _ammoConfig select 4;
private _dragModel = _ammoConfig select 5;
private _atmosphereModel = _ammoConfig select 8;

private _useABConfig = (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]);
if (_bc == 0) then {
_useABConfig = false;
};

if (_barrelLength > 0 && _useABConfig) then {
private _isABenabled = (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) && (_bc != 0);
private _useBarrelLengthInfluence = (
_isABenabled &&
{missionNamespace getVariable [QEGVAR(advanced_ballistics,barrelLengthInfluenceEnabled), false]}
);
private _useAmmoTemperatureInfluence = (
_isABenabled &&
{missionNamespace getVariable [QEGVAR(advanced_ballistics,ammoTemperatureEnabled), false]}
);

if (_barrelLength > 0 && _useBarrelLengthInfluence) then {
_muzzleVelocity = [_barrelLength, _ammoConfig select 10, _ammoConfig select 11, 0] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift);
} else {
private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "initSpeed");
Expand All @@ -128,15 +133,15 @@ if (_barrelLength > 0 && _useABConfig) then {

ctrlSetText [770000, format["%1'' - %2 gr (%3)", round((_ammoConfig select 1) * 39.3700787) / 1000, round((_ammoConfig select 3) * 15.4323584), _ammoClass]];
if (_barrelLength > 0) then {
if (_useABConfig && _barrelTwist > 0) then {
if (_useBarrelLengthInfluence && _barrelTwist > 0) then {
ctrlSetText [770002, format["Barrel: %1'' 1:%2'' twist", round(2 * _barrelLength * 0.0393700787) / 2, round(_barrelTwist * 0.0393700787)]];
} else {
ctrlSetText [770002, format["Barrel: %1''", round(2 * _barrelLength * 0.0393700787) / 2]];
};
};

lnbAddRow [770100, ["4mps Wind(MRADs)", "1mps LEAD(MRADs)"]];
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then {
if (_isABenabled) then {
lnbAddRow [770100, ["Air/Ammo Temp", "Air/Ammo Temp"]];

lnbAddRow [770200, ["-15°C", " -5°C", " 5°C", " 10°C", " 15°C", " 20°C", " 25°C", " 30°C", " 35°C"]];
Expand All @@ -145,38 +150,38 @@ if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) t

ctrlSetText [77003, format["%1m ZERO", round(_zeroRange)]];

if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then {
if (_isABenabled) then {
ctrlSetText [770001, format["Drop Tables for B.P.: %1mb; Corrected for MVV at Air/Ammo Temperatures -15-35 °C", round(EGVAR(scopes,zeroReferenceBarometricPressure) * 100) / 100]];
ctrlSetText [77004 , format["B.P.: %1mb", round(EGVAR(scopes,zeroReferenceBarometricPressure) * 100) / 100]];
} else {
ctrlSetText [770001, ""];
ctrlSetText [77004 , ""];
};

private _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 _cacheEntry = missionNamespace getVariable format [QGVAR(%1_%2_%3_%4_%5_%6_%7), _zeroRange, _boreHeight, _ammoClass, _weaponClass, _isABenabled, _useBarrelLengthInfluence, _useAmmoTemperatureInfluence];
if (isNil "_cacheEntry") then {
private _scopeBaseAngle = if (!_isABenabled) then {
private _zeroAngle = "ace_advanced_ballistics" callExtension format ["calcZero:%1:%2:%3:%4", _zeroRange, _muzzleVelocity, _airFriction, _boreHeight];
(parseNumber _zeroAngle)
} else {
private _zeroAngle = "ace_advanced_ballistics" callExtension format ["calcZeroAB:%1:%2:%3:%4:%5:%6:%7:%8:%9", _zeroRange, _muzzleVelocity, _boreHeight, EGVAR(scopes,zeroReferenceTemperature), EGVAR(scopes,zeroReferenceBarometricPressure), EGVAR(scopes,zeroReferenceHumidity), _bc, _dragModel, _atmosphereModel];
(parseNumber _zeroAngle)
};
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false] && missionNamespace getVariable [QEGVAR(advanced_ballistics,ammoTemperatureEnabled), false]) then {
if (_useAmmoTemperatureInfluence) then {
{
private _mvShift = [_ammoConfig select 9, _x] call EFUNC(advanced_ballistics,calculateAmmoTemperatureVelocityShift);
private _mv = _muzzleVelocity + _mvShift;

[_scopeBaseAngle,_boreHeight,_airFriction,_mv,_x,EGVAR(scopes,zeroReferenceBarometricPressure),EGVAR(scopes,zeroReferenceHumidity),200,4,1,GVAR(rangeCardEndRange),_bc,_dragModel,_atmosphereModel,_transonicStabilityCoef,_forEachIndex,_useABConfig] call FUNC(calculateRangeCard);
[_scopeBaseAngle,_boreHeight,_airFriction,_mv,_x,EGVAR(scopes,zeroReferenceBarometricPressure),EGVAR(scopes,zeroReferenceHumidity),200,4,1,GVAR(rangeCardEndRange),_bc,_dragModel,_atmosphereModel,_transonicStabilityCoef,_forEachIndex,_isABenabled] call FUNC(calculateRangeCard);
} forEach [-15, -5, 5, 10, 15, 20, 25, 30, 35];
} else {
[_scopeBaseAngle,_boreHeight,_airFriction,_muzzleVelocity,15,EGVAR(scopes,zeroReferenceBarometricPressure),EGVAR(scopes,zeroReferenceHumidity),200,4,1,GVAR(rangeCardEndRange),_bc,_dragModel,_atmosphereModel,_transonicStabilityCoef,3,_useABConfig] call FUNC(calculateRangeCard);
[_scopeBaseAngle,_boreHeight,_airFriction,_muzzleVelocity,15,EGVAR(scopes,zeroReferenceBarometricPressure),EGVAR(scopes,zeroReferenceHumidity),200,4,1,GVAR(rangeCardEndRange),_bc,_dragModel,_atmosphereModel,_transonicStabilityCoef,3,_isABenabled] call FUNC(calculateRangeCard);
};

for "_i" from 0 to 9 do {
GVAR(lastValidRow) pushBack count (GVAR(rangeCardDataElevation) select _i);
while {count (GVAR(rangeCardDataElevation) select _i) < 50} do {
if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then {
if (_isABenabled) then {
(GVAR(rangeCardDataElevation) select _i) pushBack "###";
(GVAR(rangeCardDataWindage) select _i) pushBack "##";
(GVAR(rangeCardDataLead) select _i) pushBack "##";
Expand All @@ -188,7 +193,7 @@ if (isNil {_cacheEntry}) then {
};
};

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)]];
missionNamespace setVariable [format [QGVAR(%1_%2_%3_%4_%5_%6_%7), _zeroRange, _boreHeight, _ammoClass, _weaponClass, _isABenabled, _useBarrelLengthInfluence, _useAmmoTemperatureInfluence], [GVAR(rangeCardDataElevation), GVAR(rangeCardDataWindage), GVAR(rangeCardDataLead), GVAR(rangeCardDataMVs), GVAR(lastValidRow)]];
} else {
GVAR(rangeCardDataElevation) = _cacheEntry select 0;
GVAR(rangeCardDataWindage) = _cacheEntry select 1;
Expand Down
9 changes: 7 additions & 2 deletions addons/xm157/functions/fnc_ballistics_getData.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ private _key = format ["weaponInfoCache-%1-%2-%3",_weaponClass,_magazineClass,_a
private _weaponInfo = GVAR(data) getOrDefault [_key, []];
if ((_weaponInfo isEqualTo []) && {_magazineClass != ""}) then {
TRACE_3("new weapon/mag",_weaponClass,_magazineClass,_ammoClass);
private _useABConfig = (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]);

private _zeroRange = 100;
private _boreHeight = [_unit, 0] call EFUNC(scopes,getBoreHeight);
Expand All @@ -35,8 +34,14 @@ if ((_weaponInfo isEqualTo []) && {_magazineClass != ""}) then {
_weaponConfig params ["_barrelTwist", "_twistDirection", "_barrelLength"];
private _bc = if (_ballisticCoefficients isEqualTo []) then { 0 } else { _ballisticCoefficients # 0 };

private _useAB = (
missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false] &&
{missionNamespace getVariable [QEGVAR(advanced_ballistics,barrelLengthInfluenceEnabled), false]} &&
{_bc != 0}
);

// Get Muzzle Velocity
private _muzzleVelocity = if (_barrelLength > 0 && _useABConfig && {_bc != 0}) then {
private _muzzleVelocity = if (_barrelLength > 0 && _useAB) then {
[_barrelLength, _muzzleVelocityTable, _barrelLengthTable, 0] call EFUNC(advanced_ballistics,calculateBarrelLengthVelocityShift)
} else {
private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazineClass >> "initSpeed");
Expand Down

0 comments on commit e9cb274

Please sign in to comment.