2015-04-07 19:46:43 +00:00
|
|
|
/*
|
|
|
|
* Author: Ruthberg
|
|
|
|
*
|
|
|
|
* Calculates the muzzle velocity shift caused by different barrel lengths
|
|
|
|
*
|
|
|
|
* Arguments:
|
2015-05-08 15:20:56 +00:00
|
|
|
* 0: barrel length - mm
|
|
|
|
* 1: muzzle velocity lookup table - m/s <ARRAY>
|
|
|
|
* 2: barrel length lookup table - mm <ARRAY>
|
|
|
|
* 3: muzzle velocity - m/s <NUMBER>
|
2015-04-07 19:46:43 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-04-07 19:54:29 +00:00
|
|
|
* 0: muzzle velocity shift - m/s <NUMBER>
|
2015-04-07 19:46:43 +00:00
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* None
|
|
|
|
*/
|
2015-04-05 19:08:55 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-08-04 22:32:48 +00:00
|
|
|
private ["_lowerIndex", "_upperIndex", "_barrelLengthRatio", "_muzzleVelocityNew"];
|
|
|
|
params ["_barrelLength", "_muzzleVelocityTable", "_barrelLengthTable", "_muzzleVelocity"];
|
2015-04-05 19:08:55 +00:00
|
|
|
|
|
|
|
if (_barrelLength == 0) exitWith { 0 };
|
|
|
|
if (count _muzzleVelocityTable != count _barrelLengthTable) exitWith { 0 };
|
|
|
|
if (count _muzzleVelocityTable == 0 || count _barrelLengthTable == 0) exitWith { 0 };
|
|
|
|
if (count _muzzleVelocityTable == 1) exitWith { (_muzzleVelocityTable select 0) - _muzzleVelocity };
|
|
|
|
|
|
|
|
_lowerIndex = 0;
|
|
|
|
_upperIndex = (count _barrelLengthTable) - 1;
|
|
|
|
|
|
|
|
if (_barrelLength <= (_barrelLengthTable select _lowerIndex)) exitWith { (_muzzleVelocityTable select _lowerIndex) - _muzzleVelocity };
|
|
|
|
if (_barrelLength >= (_barrelLengthTable select _upperIndex)) exitWith { (_muzzleVelocityTable select _upperIndex) - _muzzleVelocity };
|
|
|
|
|
|
|
|
for "_i" from 0 to (count _barrelLengthTable) - 1 do {
|
2015-04-07 19:27:04 +00:00
|
|
|
if (_barrelLength >= _barrelLengthTable select _i) then {
|
|
|
|
_lowerIndex = _i;
|
|
|
|
};
|
2015-04-05 19:08:55 +00:00
|
|
|
};
|
|
|
|
for "_i" from (count _barrelLengthTable) - 1 to 0 step -1 do {
|
2015-04-07 19:27:04 +00:00
|
|
|
if (_barrelLength <= _barrelLengthTable select _i) then {
|
|
|
|
_upperIndex = _i;
|
|
|
|
};
|
2015-04-05 19:08:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_barrelLengthRatio = 0;
|
|
|
|
if ((_barrelLengthTable select _upperIndex) - (_barrelLengthTable select _lowerIndex) > 0) then {
|
2015-04-07 19:27:04 +00:00
|
|
|
_barrelLengthRatio = ((_barrelLengthTable select _upperIndex) - _barrelLength) / ((_barrelLengthTable select _upperIndex) - (_barrelLengthTable select _lowerIndex));
|
2015-04-05 19:08:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_muzzleVelocityNew = (_muzzleVelocityTable select _lowerIndex) + ((_muzzleVelocityTable select _upperIndex) - (_muzzleVelocityTable select _lowerIndex)) * (1 - _barrelLengthRatio);
|
|
|
|
|
|
|
|
_muzzleVelocityNew - _muzzleVelocity
|