ACE3/addons/advanced_ballistics/functions/fnc_calculateAmmoTemperatureVelocityShift.sqf
2015-05-08 17:20:56 +02:00

37 lines
1.2 KiB
Plaintext

/*
* Author: Ruthberg
*
* Calculates the ammo temperature induced muzzle velocity shift
*
* Arguments:
* 0: muzzle velocity shift lookup table - m/s <ARRAY>
* 1: temperature - degrees celcius <NUMBER>
*
* Return Value:
* 0: muzzle velocity shift - m/s <NUMBER>
*
* Return value:
* None
*/
#include "script_component.hpp"
private ["_muzzleVelocityShiftTable", "_temperature", "_muzzleVelocityShift", "_temperatureIndexA", "_temperatureIndexB", "_temperatureRatio"];
_muzzleVelocityShiftTable = _this select 0;
_temperature = _this select 1;
if (count _muzzleVelocityShiftTable != 11) exitWith { 0 };
_temperatureIndexA = floor((_temperature + 15) / 5);
_temperatureIndexA = 0 max _temperatureIndexA;
_temperatureIndexA = _temperatureIndexA min 10;
_temperatureIndexB = ceil((_temperature + 15) / 5);
_temperatureIndexB = 0 max _temperatureIndexB;
_temperatureIndexB = _temperatureIndexB min 10;
_temperatureRatio = ((_temperature + 15) / 5) - floor((_temperature + 15) / 5);
_muzzleVelocityShift = (_muzzleVelocityShiftTable select _temperatureIndexA) * (1 - _temperatureRatio) + (_muzzleVelocityShiftTable select _temperatureIndexB) * _temperatureRatio;
_muzzleVelocityShift