diff --git a/addons/atragmx/functions/fnc_lookup_c1_ballistic_coefficient.sqf b/addons/atragmx/functions/fnc_lookup_c1_ballistic_coefficient.sqf index d17726b1a9..43b6da006f 100644 --- a/addons/atragmx/functions/fnc_lookup_c1_ballistic_coefficient.sqf +++ b/addons/atragmx/functions/fnc_lookup_c1_ballistic_coefficient.sqf @@ -28,24 +28,16 @@ private _lookupTableSize = count _lookupTable; if (_lookupTableSize < 2) exitWith { (GVAR(workingMemory) select 15) }; _lookupTable sort true; -private _lowerIndex = -1; -private _upperIndex = -1; +private _lowerIndex = 0; +private _upperIndex = 1; for "_index" from 1 to (_lookupTableSize - 1) do { _upperIndex = _index; _lowerIndex = _upperIndex - 1; - if (((_lookupTable select _index) select 0) >= _targetRange) exitWith { (GVAR(workingMemory) select 15) }; + if (((_lookupTable select _index) select 0) >= _targetRange) exitWith {}; }; -private _lowerDistance = (_lookupTable select _lowerIndex) select 0; -private _upperDistance = (_lookupTable select _upperIndex) select 0; -private _lowerC1 = (_lookupTable select _lowerIndex) select 1; -private _upperC1 = (_lookupTable select _upperIndex) select 1; -private _c1 = _lowerC1; -if (_lowerDistance != _upperDistance) then { - private _slope = (_upperC1 - _lowerC1) / (_upperDistance - _lowerDistance); - _c1 = _lowerC1 + (_targetRange - _lowerDistance) * _slope; -}; -_c1 = 0.1 max _c1 min 2.0; +(_lookupTable select _lowerIndex) params ["_lowerDistance", "_lowerC1"]; +(_lookupTable select _upperIndex) params ["_upperDistance", "_upperC1"]; -_c1 +(0.1 max (linearConversion [_lowerDistance, _upperDistance, _targetRange, _lowerC1, _upperC1]) min 2.0) diff --git a/addons/atragmx/functions/fnc_recalculate_muzzle_velocity.sqf b/addons/atragmx/functions/fnc_recalculate_muzzle_velocity.sqf index e4e3cd70c6..aa1ab6d23f 100644 --- a/addons/atragmx/functions/fnc_recalculate_muzzle_velocity.sqf +++ b/addons/atragmx/functions/fnc_recalculate_muzzle_velocity.sqf @@ -33,24 +33,19 @@ private _lookupTableSize = count _lookupTable; if (_lookupTableSize < 2) exitWith {}; _lookupTable sort true; -private _lowerIndex = -1; -private _upperIndex = -1; +private _lowerIndex = 0; +private _upperIndex = 1; + for "_index" from 1 to (_lookupTableSize - 1) do { _upperIndex = _index; _lowerIndex = _upperIndex - 1; if (((_lookupTable select _index) select 0) >= GVAR(temperature)) exitWith {}; }; -private _lowerTemperature = (_lookupTable select _lowerIndex) select 0; -private _upperTemperature = (_lookupTable select _upperIndex) select 0; -private _lowerMuzzleVelocity = (_lookupTable select _lowerIndex) select 1; -private _upperMuzzleVelocity = (_lookupTable select _upperIndex) select 1; -private _muzzleVelocity = _lowerMuzzleVelocity; -if (_lowerTemperature != _upperTemperature) then { - private _slope = (_upperMuzzleVelocity - _lowerMuzzleVelocity) / (_upperTemperature - _lowerTemperature); - _muzzleVelocity = _lowerMuzzleVelocity + (GVAR(temperature) - _lowerTemperature) * _slope; -}; -_muzzleVelocity = 100 max _muzzleVelocity min 1400; +(_lookupTable select _lowerIndex) params ["_lowerDistance", "_lowerMuzzleVelocity"]; +(_lookupTable select _upperIndex) params ["_upperDistance", "_upperMuzzleVelocity"]; + +_muzzleVelocity = 100 max (linearConversion [_lowerDistance, _upperDistance, GVAR(temperature), _lowerMuzzleVelocity, _upperMuzzleVelocity]) min 1400; if (_muzzleVelocity != GVAR(workingMemory) select 1) then { GVAR(workingMemory) set [1, _muzzleVelocity];