2015-04-07 19:46:43 +00:00
|
|
|
/*
|
|
|
|
* Author: Ruthberg
|
|
|
|
*
|
|
|
|
* Calculates the muzzle velocity shift caused by different barrel lengths
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: ammo - classname <string>
|
|
|
|
* 0: weapon - classname <string>
|
2015-04-07 19:54:29 +00:00
|
|
|
* 1: 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"
|
|
|
|
|
|
|
|
private ["_ammo", "_weapon", "_barrelLength", "_muzzleVelocityTable", "_barrelLengthTable", "_muzzleVelocity", "_lowerIndex", "_upperIndex", "_barrelLengthRatio", "_muzzleVelocityNew"];
|
|
|
|
_ammo = _this select 0;
|
|
|
|
_weapon = _this select 1;
|
|
|
|
_muzzleVelocity = _this select 2;
|
|
|
|
|
|
|
|
_barrelLength = getNumber(configFile >> "cfgWeapons" >> _weapon >> "ACE_barrelLength");
|
|
|
|
|
|
|
|
if (_barrelLength == 0) exitWith { 0 };
|
|
|
|
|
|
|
|
_muzzleVelocityTable = [];
|
|
|
|
_barrelLengthTable = [];
|
|
|
|
|
|
|
|
if (isArray(configFile >> "cfgAmmo" >> _ammo >> "ACE_muzzleVelocities")) then {
|
2015-04-07 19:27:04 +00:00
|
|
|
_muzzleVelocityTable = getArray(configFile >> "cfgAmmo" >> _ammo >> "ACE_muzzleVelocities");
|
2015-04-05 19:08:55 +00:00
|
|
|
};
|
|
|
|
if (isArray(configFile >> "cfgAmmo" >> _ammo >> "ACE_barrelLengths")) then {
|
2015-04-07 19:27:04 +00:00
|
|
|
_barrelLengthTable = getArray(configFile >> "cfgAmmo" >> _ammo >> "ACE_barrelLengths");
|
2015-04-05 19:08:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|