2121params [" _targetRange" , " _directionOfFire" , " _inclinationAngle" , " _bank" ];
2222
2323private _weaponInfo = [] call FUNC(ballistics_getData);
24- if (_weaponInfo isEqualTo []) exitWith { [0 ,0 ,0 ] };
25- _weaponInfo params [" _scopeBaseAngle" ," _boreHeight" ," _airFriction" ," _muzzleVelocity" ," _bc" ,
26- " _dragModel" ," _atmosphereModel" ," _barrelTwist" ," _twistDirection" ," _caliber" ," _bulletLength" ," _bulletMass" ];
24+
25+ if (_weaponInfo isEqualTo []) exitWith {
26+ [0 , 0 , 0 ] // return
27+ };
28+
29+ _weaponInfo params [
30+ " _scopeBaseAngle" ,
31+ " _boreHeight" ,
32+ " _airFriction" ,
33+ " _muzzleVelocity" ,
34+ " _bc" ,
35+ " _dragModel" ,
36+ " _atmosphereModel" ,
37+ " _barrelTwist" ,
38+ " _twistDirection" ,
39+ " _caliber" ,
40+ " _bulletLength" ,
41+ " _bulletMass"
42+ ];
2743
2844private _latitude = GVAR(data) getOrDefault [" latitude" , 0 ];
2945
3046// Get Wind
3147private _windSpeed = GVAR(data) getOrDefault [" wind_speed" , 0 ];
3248private _windDirection = 22.5 * (GVAR(data) getOrDefault [" wind_dir" , 0 ]);
33- private _wind = [sin (_directionOfFire - _windDirection ) * _windSpeed , - cos (_directionOfFire - _windDirection ) * _windSpeed , 0 ];
49+ private _wind = [sin (_directionOfFire - _windDirection ), - cos (_directionOfFire - _windDirection ), 0 ] vectorMultiply _windSpeed ;
3450
3551// Get atmosphere
36- private _altitude = (getPosASL ace_player ) select 2 ;
52+ private _altitude = (getPosASL ACE_player ) select 2 ;
3753private _relativeHumidity = EGVAR(weather,currentHumidity);
3854private _temperature = _altitude call EFUNC(weather,calculateTemperatureAtHeight);
3955private _barometricPressure = _altitude call EFUNC(weather,calculateBarometricPressure);
4056
4157
42- private _bulletPos = [0 ,0 , - ( _boreHeight / 100 ) ];
58+ private _bulletPos = [0 , 0 , - _boreHeight / 100 ];
4359private _lastBulletPos = + _bulletPos ;
44- private _bulletVelocity = [0 ,cos ( _scopeBaseAngle ) * _muzzleVelocity , sin ( _scopeBaseAngle ) * _muzzleVelocity ] ;
45- private _gravity = [- sin ( _bank ) * cos (_scopeBaseAngle + _inclinationAngle ) * - GRAVITY ,
46- sin (_scopeBaseAngle + _inclinationAngle ) * - GRAVITY ,
47- cos ( _bank ) * cos (_scopeBaseAngle + _inclinationAngle ) * - GRAVITY] ;
60+ private _bulletVelocity = [0 , cos _scopeBaseAngle , sin _scopeBaseAngle ] vectorMultiply _muzzleVelocity ;
61+ private _gravity = [( - sin _bank ) * cos (_scopeBaseAngle + _inclinationAngle ),
62+ sin (_scopeBaseAngle + _inclinationAngle ),
63+ ( cos _bank ) * cos (_scopeBaseAngle + _inclinationAngle )] vectorMultiply - GRAVITY;
4864
4965private _useAB = missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false ];
66+
5067if (_useAB ) then {
5168 _bc = parseNumber ((" ace" callExtension [" ballistics:atmospheric_correction" , [_bc , _temperature , _barometricPressure , _relativeHumidity , _atmosphereModel ]]) select 0 );
5269};
5370
5471private _deltaT = 1 / 60 ;
5572private _TOF = 0 ; // Limit TOF to 5 seconds!
73+
5674while {(_TOF < 5 ) && {(_bulletPos # 1 ) < _targetRange }} do {
5775 private _trueVelocity = _bulletVelocity vectorDiff _wind ;
5876 private _trueSpeed = vectorMagnitude _trueVelocity ;
5977
6078 private _bulletAccel = if (_useAB ) then {
6179 private _drag = parseNumber ((" ace" callExtension [" ballistics:retard" , [_dragModel , _bc , _trueSpeed , _temperature ]]) select 0 );
62- (vectorNormalized _trueVelocity ) vectorMultiply ( - 1 * _drag ) ;
80+ (vectorNormalized _trueVelocity ) vectorMultiply - _drag ;
6381 } else {
6482 _trueVelocity vectorMultiply (_trueSpeed * _airFriction );
6583 };
84+
6685 _bulletAccel = _bulletAccel vectorAdd _gravity ;
6786 _lastBulletPos = _bulletPos ;
6887 _bulletPos = _bulletPos vectorAdd (_bulletVelocity vectorMultiply (_deltaT * 0.5 ));
@@ -74,27 +93,30 @@ while {(_TOF < 5) && {(_bulletPos # 1) < _targetRange}} do {
7493
7594private _tx = linearConversion [_lastBulletPos select 1 , _bulletPos select 1 , _targetRange , _lastBulletPos select 0 , _bulletPos select 0 ];
7695private _tz = linearConversion [_lastBulletPos select 1 , _bulletPos select 1 , _targetRange , _lastBulletPos select 2 , _bulletPos select 2 ];
77- private _elevation = - atan (_tz / _targetRange );
78- private _windage = - atan (_tx / _targetRange );
79-
96+ private _elevation = - atan (_tz / _targetRange );
97+ private _windage = - atan (_tx / _targetRange );
8098
8199if (_useAB && {(_bulletPos select 1 ) > 0 }) then {
82100 // Coriolis
83- private _horizontalDeflection = 0.0000729 * (_bulletPos select 1 ) * _TOF * sin ( _latitude );
84- private _horizontalCoriolis = - atan (_horizontalDeflection / (_bulletPos select 1 ));
101+ private _horizontalDeflection = 0.0000729 * (_bulletPos select 1 ) * _TOF * ( sin _latitude );
102+ private _horizontalCoriolis = - atan (_horizontalDeflection / (_bulletPos select 1 ));
85103 _windage = _windage + _horizontalCoriolis ;
104+
86105 // Eoetvoes
87- private _eoetvoesMultiplier = 2 * (0.0000729 * _muzzleVelocity / - GRAVITY) * cos ( _latitude ) * sin ( _directionOfFire );
106+ private _eoetvoesMultiplier = 2 * (0.0000729 * _muzzleVelocity / - GRAVITY) * ( cos _latitude ) * ( sin _directionOfFire );
88107 private _verticalDeflection = (_bulletPos select 2 ) * _eoetvoesMultiplier ;
89- private _verticalCoriolis = - atan (_verticalDeflection / (_bulletPos select 1 ));
108+ private _verticalCoriolis = - atan (_verticalDeflection / (_bulletPos select 1 ));
90109 _elevation = _elevation + _verticalCoriolis ;
110+
91111 // Spin drift
92- private _stabilityFactor = 1.5 ;
93- if (_caliber * _bulletLength * _bulletMass * _barrelTwist > 0 ) then {
94- _stabilityFactor = [_caliber , _bulletLength , _bulletMass , _barrelTwist , _muzzleVelocity , _temperature , _barometricPressure ] call EFUNC(advanced_ballistics,calculateStabilityFactor);
112+ private _stabilityFactor = if (_caliber * _bulletLength * _bulletMass * _barrelTwist > 0 ) then {
113+ [_caliber , _bulletLength , _bulletMass , _barrelTwist , _muzzleVelocity , _temperature , _barometricPressure ] call EFUNC(advanced_ballistics,calculateStabilityFactor)
114+ } else {
115+ 1.5
95116 };
117+
96118 private _spinDeflection = _twistDirection * 0.0254 * 1.25 * (_stabilityFactor + 1.2 ) * _TOF ^ 1.83 ;
97- private _spinDrift = - atan (_spinDeflection / (_bulletPos select 1 ));
119+ private _spinDrift = - atan (_spinDeflection / (_bulletPos select 1 ));
98120 _windage = _windage + _spinDrift ;
99121};
100122
0 commit comments