Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion addons/advanced_ballistics/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
Expand Down
66 changes: 21 additions & 45 deletions addons/advanced_ballistics/RscTitles.hpp
Original file line number Diff line number Diff line change
@@ -1,54 +1,30 @@
class RscTitles {
class RscTurretDial {
idd=-1;
onLoad="with uiNameSpace do { RscTurretDial = _this select 0 };";
movingEnable=0;
duration=5;
fadeIn="false";
fadeOut="false";
class controls {
class RscTurretDial {
idc=132949;
type=0;
style=128;
font="TahomaB";
colorBackground[]={0,0,0,0.8};
colorText[]={1,1,1,1};
x="SafeZoneX + 0.0025";
y="SafeZoneY + 0.0025";
w=0.10;
h=0.05;
sizeEx=0.03;
text="";
};
};
};

class RscProtractor {
idd=-1;
onLoad="with uiNameSpace do { RscProtractor = _this select 0 };";
movingEnable=0;
duration=60;
fadeIn="false";
fadeOut="false";
idd = -1;
onLoad = QUOTE(uiNamespace setVariable [ARR_2(QQGVAR(rscProtractor),_this select 0)]);
movingEnable = 0;
duration = 1e10;
fadeIn = "false";
fadeOut = "false";
class controls {
class RscProtractorBase {
idc=132950;
type=0;
style=48;
font="TahomaB";
colorBackground[]={0,0,0,0};
colorText[]={1,1,1,1};
x="SafeZoneX + 0.001";
y="SafeZoneY + 0.001";
w=0.2;
h=0.2*4/3;
size=0.034;
sizeEx=0.027;
text="";
idc = 132950;
type = 0;
style = 48;
font = "TahomaB";
colorBackground[] = {0, 0, 0, 0};
colorText[] = {1, 1, 1, 1};
x = "SafeZoneX + 0.001";
y = "SafeZoneY + 0.001";
w = 0.2;
h = 0.2*4/3;
size = 0.034;
sizeEx = 0.027;
text = QPATHTOF(UI\protractor.paa);
};
class RscProtractorMarker: RscProtractorBase {
idc=132951;
idc = 132951;
text = QPATHTOF(UI\protractor_marker.paa);
};
};
};
Expand Down
1 change: 0 additions & 1 deletion addons/advanced_ballistics/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

PREP(calculateAmmoTemperatureVelocityShift);
PREP(calculateAtmosphericCorrection);
PREP(calculateBarrelLengthVelocityShift);
Expand Down
12 changes: 4 additions & 8 deletions addons/advanced_ballistics/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
#include "script_component.hpp"

#include "initKeybinds.inc.sqf"

GVAR(Protractor) = false;
GVAR(ProtractorStart) = CBA_missionTime;
GVAR(protractor) = false;
GVAR(allBullets) = createHashMap;
GVAR(currentGrid) = 0;

if (!hasInterface) exitWith {};

#include "initKeybinds.inc.sqf"

["CBA_settingsInitialized", {
//If not enabled, dont't add PFEH
// If not enabled, dont't add PFH
if (!GVAR(enabled)) exitWith {};

//Run the terrain processor
// Run the terrain processor
[] call FUNC(initializeTerrainExtension);

// Register fire event handler
["ace_firedPlayer", LINKFUNC(handleFired)] call CBA_fnc_addEventHandler;
["ace_firedPlayerNonLocal", LINKFUNC(handleFired)] call CBA_fnc_addEventHandler;

// Register Perframe Handler
// Register PFH
[LINKFUNC(handleFirePFH), GVAR(simulationInterval)] call CBA_fnc_addPerFrameHandler;
}] call CBA_fnc_addEventHandler;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
#include "..\script_component.hpp"
/*
* Author: Ruthberg
*
* Calculates the ammo temperature induced muzzle velocity shift
* Calculates the ammo temperature induced muzzle velocity shift.
*
* Arguments:
* 0: muzzle velocity shift lookup table - m/s <ARRAY>
* 1: temperature - degrees celcius <NUMBER>
* 0: Muzzle velocity shift lookup table - m/s <ARRAY>
* 1: Temperature - °C <NUMBER>
*
* Return Value:
* muzzle velocity shift - m/s <NUMBER>
* Muzzle velocity shift - m/s <NUMBER>
*
* Example:
* [[], 5] call ace_advanced_ballistics_fnc_calculateAmmoTemperatureVelocityShift
* [[-27.20, -26.44, -23.76, -21.00, -17.54, -13.10, -7.95, -1.62, 6.24, 15.48, 27.75], 5] call ace_advanced_ballistics_fnc_calculateAmmoTemperatureVelocityShift
*
* Public: No
*/

params ["_muzzleVelocityShiftTable", "_temperature"];

// Check if muzzleVelocityShiftTable is less than 11 Entrys
if ((count _muzzleVelocityShiftTable) < 11) exitWith {0};
if (count _muzzleVelocityShiftTable < 11) exitWith {
0 // return
};

private _muzzleVelocityShiftTableUpperLimit = _muzzleVelocityShiftTable select 10;
if (isNil "_muzzleVelocityShiftTableUpperLimit") exitWith {0};

if (isNil "_muzzleVelocityShiftTableUpperLimit") exitWith {
0 // return
};

// Find exact data index required for given temperature
private _temperatureIndexFunction = 0 max ((_temperature + 15) / 5) min 10;

// Lower and upper data index used for interpolation
private _temperatureIndexA = floor(_temperatureIndexFunction);
private _temperatureIndexB = ceil(_temperatureIndexFunction);
private _temperatureIndexA = floor _temperatureIndexFunction;
private _temperatureIndexB = ceil _temperatureIndexFunction;

linearConversion [_temperatureIndexA, _temperatureIndexB, _temperatureIndexFunction, _muzzleVelocityShiftTable select _temperatureIndexA, _muzzleVelocityShiftTable select _temperatureIndexB, true] // Return
linearConversion [_temperatureIndexA, _temperatureIndexB, _temperatureIndexFunction, _muzzleVelocityShiftTable select _temperatureIndexA, _muzzleVelocityShiftTable select _temperatureIndexB, true] // return
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
#include "..\script_component.hpp"
/*
* Author: Ruthberg
*
* Calculates the atmospherically corrected ballistic coefficient
* Calculates the atmospherically corrected ballistic coefficient.
*
* Arguments:
* 0: ballistic coefficient - G1-G7 <NUMBER>
* 1: temperature - degrees celcius <NUMBER>
* 2: pressure - hPa <NUMBER>
* 3: relativeHumidity - value between 0.0 and 1.0 <NUMBER>
* 4: atmosphereModel - ICAO or ASM <STRING>
* 0: Ballistic coefficient - G1-G7 <NUMBER>
* 1: Temperature - °C <NUMBER>
* 2: Pressure - hPa <NUMBER>
* 3: Relative humidity - value between 0 and 1 <NUMBER>
* 4: Atmospheric model - "ICAO" or "ASM" <STRING>
*
* Return Value:
* corrected ballistic coefficient <NUMBER>
* Corrected ballistic coefficient <NUMBER>
*
* Example:
* [2, 5, 5, 0.5, "ASM"] call ace_advanced_ballistics_fnc_calculateAtmosphericCorrection
* [0.151, 5, 1013.25, 0.5, "ICAO"] call ace_advanced_ballistics_fnc_calculateAtmosphericCorrection
*
* Public: No
*/

params ["_ballisticCoefficient", "_temperature"/*in C*/, "_pressure"/*in hPa*/, "_relativeHumidity"/*as ratio 0-1*/, "_atmosphereModel"/*"ICAO" or "ASM"*/];
params ["_ballisticCoefficient", "_temperature", "_pressure", "_relativeHumidity", "_atmosphereModel"];

private _airDensity = [_temperature, _pressure, _relativeHumidity] call EFUNC(weather,calculateAirDensity);

if (_atmosphereModel == "ICAO") then {
(STD_AIR_DENSITY_ICAO / _airDensity) * _ballisticCoefficient
} else {
(STD_AIR_DENSITY_ASM / _airDensity) * _ballisticCoefficient
};
([STD_AIR_DENSITY_ASM, STD_AIR_DENSITY_ICAO] select (_atmosphereModel == "ICAO")) / _airDensity * _ballisticCoefficient // return
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#include "..\script_component.hpp"
/*
* Author: Ruthberg, MikeMatrix, joko // Jonas
*
* Calculates the muzzle velocity shift caused by different barrel lengths
* Calculates the muzzle velocity shift caused by different barrel lengths.
*
* Arguments:
* 0: barrel length - mm <NUMBER>
* 1: muzzle velocity lookup table - m/s <ARRAY>
* 2: barrel length lookup table - mm <ARRAY>
* 3: muzzle velocity - m/s <NUMBER>
* 0: Barrel length - mm <NUMBER>
* 1: Muzzle velocity lookup table - m/s <ARRAY>
* 2: Barrel length lookup table - mm <ARRAY>
* 3: Reference muzzle velocity - m/s <NUMBER>
*
* Return Value:
* muzzle velocity shift - m/s <NUMBER>
* Muzzle velocity shift - m/s <NUMBER>
*
* Example:
* [5, [0,5], [0,5], 5] call ace_advanced_ballistics_fnc_calculateBarrelLengthVelocityShift
* [508, [624, 816, 832, 838], [190.5, 368.3, 457.2, 508.0], 0] call ace_advanced_ballistics_fnc_calculateBarrelLengthVelocityShift
*
* Public: No
*/
Expand All @@ -23,23 +22,36 @@ params ["_barrelLength", "_muzzleVelocityTable", "_barrelLengthTable", "_muzzleV
TRACE_4("params",_barrelLength,_muzzleVelocityTable,_barrelLengthTable,_muzzleVelocity);

// If barrel length is not defined, then there is no point in calculating muzzle velocity
if (_barrelLength == 0) exitWith { 0 };
if (_barrelLength == 0) exitWith {
0 // return
};

private _muzzleVelocityTableCount = count _muzzleVelocityTable;
private _barrelLengthTableCount = count _barrelLengthTable;

// Exit if tables are different sizes, have no elements or have only one element
if (_muzzleVelocityTableCount != _barrelLengthTableCount || _muzzleVelocityTableCount == 0) exitWith { 0 };
if (_muzzleVelocityTableCount == 1) exitWith { (_muzzleVelocityTable select 0) - _muzzleVelocity };
if (_muzzleVelocityTableCount != count _barrelLengthTable || _muzzleVelocityTableCount == 0) exitWith {
0 // return
};

if (_muzzleVelocityTableCount == 1) exitWith {
(_muzzleVelocityTable select 0) - _muzzleVelocity // return
};

private _index = _barrelLengthTable find _barrelLength;

// If we have the precise barrel length value, return result immediately
if (_barrelLength in _barrelLengthTable) exitWith {
(_muzzleVelocityTable select (_barrelLengthTable find _barrelLength)) - _muzzleVelocity
if (_index != -1) exitWith {
(_muzzleVelocityTable select _index) - _muzzleVelocity // return
};

// Limit values to lower and upper bound of data we have available
if (_barrelLength <= (_barrelLengthTable select 0)) exitWith { (_muzzleVelocityTable select 0) - _muzzleVelocity };
if (_barrelLength >= (_barrelLengthTable select _barrelLengthTableCount - 1)) exitWith { (_muzzleVelocityTable select _barrelLengthTableCount - 1) - _muzzleVelocity };
if (_barrelLength <= (_barrelLengthTable select 0)) exitWith {
(_muzzleVelocityTable select 0) - _muzzleVelocity // return
};

if (_barrelLength >= (_barrelLengthTable select -1)) exitWith {
(_muzzleVelocityTable select -1) - _muzzleVelocity // return
};

private _upperDataIndex = 0;
private _lowerDataIndex = 1;
Expand All @@ -52,4 +64,4 @@ private _lowerDataIndex = 1;
};
} forEach _barrelLengthTable;

(linearConversion [_barrelLengthTable select _lowerDataIndex, _barrelLengthTable select _upperDataIndex, _barrelLength, _muzzleVelocityTable select _lowerDataIndex, _muzzleVelocityTable select _upperDataIndex]) - _muzzleVelocity // Return
(linearConversion [_barrelLengthTable select _lowerDataIndex, _barrelLengthTable select _upperDataIndex, _barrelLength, _muzzleVelocityTable select _lowerDataIndex, _muzzleVelocityTable select _upperDataIndex]) - _muzzleVelocity // return
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#include "..\script_component.hpp"
/*
* Author: Ruthberg
*
* Calculates the retardation of the bullet
* Calculates the retardation of the bullet.
*
* Arguments:
* 0: drag model - integer 1-7 <NUMBER>
* 1: drag coefficient - bc <NUMBER>
* 2: velocity - m/s <NUMBER>
* 0: Drag model - integer 1-7 <NUMBER>
* 1: Drag coefficient - bc <NUMBER>
* 2: Velocity - m/s <NUMBER>
*
* Return Value:
* retardation - m/(s^2) <NUMBER>
* Retardation - m/(s^2) <NUMBER>
*
* Example:
* [5, 20, 10] call ace_advanced_ballistics_fnc_calculateRetardation
* [7, 0.151, 878] call ace_advanced_ballistics_fnc_calculateRetardation
*
* Public: No
*/
Expand All @@ -22,6 +21,7 @@

private ["_A", "_M"];
params ["_dragModel", "_dragCoefficient", "_velocity"];

_velocity = _velocity * 3.2808399;

switch _dragModel do {
Expand Down Expand Up @@ -129,7 +129,7 @@ switch _dragModel do {
};

if (!isNil "_A" && !isNil "_M" && _velocity > 0 && _velocity < 10000) then {
(_A * (_velocity ^ _M) / _dragCoefficient) / 3.2808399
(_A * (_velocity ^ _M) / _dragCoefficient) / 3.2808399 // return
} else {
0
0 // return
};
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#include "..\script_component.hpp"
/*
* Author: Ruthberg
*
* Calculates the stability factor of a bullet
* Calculates the stability factor of a bullet.
*
* Arguments:
* 0: caliber - mm <NUMBER>
* 1: bullet length - mm <NUMBER>
* 2: bullet mass - grams <NUMBER>
* 3: barrel twist - mm <NUMBER>
* 4: muzzle velocity shift - m/s <NUMBER>
* 5: temperature - degrees celcius <NUMBER>
* 6: barometric Pressure - hPA <NUMBER>
* 0: Caliber - mm <NUMBER>
* 1: Bullet length - mm <NUMBER>
* 2: Bullet mass - grams <NUMBER>
* 3: Barrel twist - mm <NUMBER>
* 4: Muzzle velocity shift - m/s <NUMBER>
* 5: Temperature - °C <NUMBER>
* 6: Barometric pressure - hPA <NUMBER>
*
* Return Value:
* stability factor <NUMBER>
* Stability factor <NUMBER>
*
* Example:
* [1, 2, 3, 4, 5, 6, 7] call ace_advanced_ballistics_fnc_calculateStabilityFactor
* [6, 23, 4, 177.8, -23.76, 0, 1013.25] call ace_advanced_ballistics_fnc_calculateStabilityFactor
*
* Public: No
*/
Expand All @@ -30,8 +29,4 @@ private _length = _bulletLength / _caliber;

private _stabilityFactor = 7587000 * _bulletMass / (_twist^2 * _caliber^3 * _length * (1 + _length^2));

if (_muzzleVelocity > 341.376) then {
(_stabilityFactor * (_muzzleVelocity / 853.44) ^ (1/3)) * KELVIN(_temperature) / KELVIN(15) * 1013.25 / _barometricPressure
} else {
(_stabilityFactor * (_muzzleVelocity / 341.376) ^ (1/3)) * KELVIN(_temperature) / KELVIN(15) * 1013.25 / _barometricPressure
};
(_stabilityFactor * (_muzzleVelocity / ([341.376, 853.44] select (_muzzleVelocity > 341.376))) ^ (1/3)) * KELVIN(_temperature) / KELVIN(15) * 1013.25 / _barometricPressure // return
Loading