mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
e2ac18a05d
* advanced_ballistics * advanced_fatigue * advanced_throwing * ai * aircraft * arsenal * atragmx * attach * backpacks * ballistics * captives * cargo * chemlights * common * concertina_wire * cookoff * dagr * disarming * disposable * dogtags * dragging * explosives * fastroping * fcs * finger * frag * gestures * gforces * goggles * grenades * gunbag * hearing * hitreactions * huntir * interact_menu * interaction * inventory * kestrel4500 * laser * laserpointer * logistics_uavbattery * logistics_wirecutter * magazinerepack * map * map_gestures * maptools * markers * medical * medical_ai * medical_blood * medical_menu * microdagr * minedetector * missileguidance * missionmodules * mk6mortar * modules * movement * nametags * nightvision * nlaw * optics * optionsmenu * overheating * overpressure * parachute * pylons * quickmount * rangecard * rearm * recoil * refuel * reload * reloadlaunchers * repair * respawn * safemode * sandbag * scopes * slideshow * spectator * spottingscope * switchunits * tacticalladder * tagging * trenches * tripod * ui * vector * vehiclelock * vehicles * viewdistance * weaponselect * weather * winddeflection * yardage450 * zeus * arsenal defines.hpp * optionals * DEBUG_MODE_FULL 1 * DEBUG_MODE_FULL 2 * Manual fixes * Add SQF Validator check for #include after block comment * explosives fnc_openTimerUI * fix uniqueItems
56 lines
2.3 KiB
Plaintext
56 lines
2.3 KiB
Plaintext
#include "script_component.hpp"
|
|
/*
|
|
* Author: Ruthberg, MikeMatrix, joko // Jonas
|
|
*
|
|
* 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>
|
|
*
|
|
* Return Value:
|
|
* muzzle velocity shift - m/s <NUMBER>
|
|
*
|
|
* Example:
|
|
* [5, [0,5], [0,5], 5] call ace_advanced_ballistics_fnc_calculateBarrelLengthVelocityShift
|
|
*
|
|
* Public: No
|
|
*/
|
|
|
|
params ["_barrelLength", "_muzzleVelocityTable", "_barrelLengthTable", "_muzzleVelocity"];
|
|
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 };
|
|
|
|
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 we have the precise barrel length value, return result immediately
|
|
if (_barrelLength in _barrelLengthTable) exitWith {
|
|
(_muzzleVelocityTable select (_barrelLengthTable find _barrelLength)) - _muzzleVelocity
|
|
};
|
|
|
|
// 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 };
|
|
|
|
private _upperDataIndex = 0;
|
|
private _lowerDataIndex = 1;
|
|
|
|
// Find closest bordering values for barrel length
|
|
{
|
|
if (_barrelLength <= _x) exitWith {
|
|
_upperDataIndex = _forEachIndex;
|
|
_lowerDataIndex = _upperDataIndex - 1;
|
|
};
|
|
} forEach _barrelLengthTable;
|
|
|
|
(linearConversion [_barrelLengthTable select _lowerDataIndex, _barrelLengthTable select _upperDataIndex, _barrelLength, _muzzleVelocityTable select _lowerDataIndex, _muzzleVelocityTable select _upperDataIndex]) - _muzzleVelocity // Return
|