From 30fedc9ece2b08428f36594f444a7cddbbe3993f Mon Sep 17 00:00:00 2001 From: ulteq Date: Fri, 3 Nov 2017 21:59:33 +0100 Subject: [PATCH] ATragMX - Utilize 'C1 vs. Distance' data in the range card output --- addons/atragmx/XEH_PREP.hpp | 1 + .../functions/fnc_calculate_range_card.sqf | 5 ++ .../fnc_lookup_c1_ballistic_coefficient.sqf | 51 +++++++++++++++++++ ...c_recalculate_c1_ballistic_coefficient.sqf | 33 +----------- 4 files changed, 59 insertions(+), 31 deletions(-) create mode 100644 addons/atragmx/functions/fnc_lookup_c1_ballistic_coefficient.sqf diff --git a/addons/atragmx/XEH_PREP.hpp b/addons/atragmx/XEH_PREP.hpp index c77b7e0655..b61258c008 100644 --- a/addons/atragmx/XEH_PREP.hpp +++ b/addons/atragmx/XEH_PREP.hpp @@ -27,6 +27,7 @@ PREP(init); PREP(initGunList); PREP(insert_c1_ballistic_coefficient_data); PREP(insert_muzzle_velocity_data); +PREP(lookup_c1_ballistic_coefficient); PREP(parse_input); PREP(read_gun_list_entries_from_config); PREP(recalculate_c1_ballistic_coefficient); diff --git a/addons/atragmx/functions/fnc_calculate_range_card.sqf b/addons/atragmx/functions/fnc_calculate_range_card.sqf index 837a46079f..9201861351 100644 --- a/addons/atragmx/functions/fnc_calculate_range_card.sqf +++ b/addons/atragmx/functions/fnc_calculate_range_card.sqf @@ -27,4 +27,9 @@ _solutionInput set [ 8, round(_solutionInput select 4)]; _solutionInput set [13, _targetRange]; _solutionInput set [17, true]; +if (missionNamespace getVariable [QEGVAR(advanced_ballistics,enabled), false]) then { + private _c1 = [_targetRange] call FUNC(lookup_c1_ballistic_coefficient); + _solutionInput set [14, _c1]; +}; + private _result = _solutionInput call FUNC(calculate_solution); diff --git a/addons/atragmx/functions/fnc_lookup_c1_ballistic_coefficient.sqf b/addons/atragmx/functions/fnc_lookup_c1_ballistic_coefficient.sqf new file mode 100644 index 0000000000..d17726b1a9 --- /dev/null +++ b/addons/atragmx/functions/fnc_lookup_c1_ballistic_coefficient.sqf @@ -0,0 +1,51 @@ +/* + * Author: Ruthberg + * Lookup the correct C1 ballistic coefficient in the c1 ballistic coefficient vs. distance interpolation table + * + * Arguments: + * Target Range + * + * Return Value: + * C1 ballistic coefficient 0) then { + _lookupTable pushBack _x; + }; +} forEach (GVAR(workingMemory) select 19); + +private _lookupTableSize = count _lookupTable; +if (_lookupTableSize < 2) exitWith { (GVAR(workingMemory) select 15) }; +_lookupTable sort true; + +private _lowerIndex = -1; +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) }; +}; + +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; + +_c1 diff --git a/addons/atragmx/functions/fnc_recalculate_c1_ballistic_coefficient.sqf b/addons/atragmx/functions/fnc_recalculate_c1_ballistic_coefficient.sqf index ee67a6b93c..e8bd219159 100644 --- a/addons/atragmx/functions/fnc_recalculate_c1_ballistic_coefficient.sqf +++ b/addons/atragmx/functions/fnc_recalculate_c1_ballistic_coefficient.sqf @@ -1,6 +1,6 @@ /* * Author: Ruthberg - * Recalculates the c1 ballistic coefficient based on the c1 ballistic coefficient vs. distance interpolation input + * Recalculates the c1 ballistic coefficient based on the current target range * * Arguments: * parse input @@ -22,36 +22,7 @@ if (_parseInput) then { [] call FUNC(parse_input); }; -private _lookupTable = []; -{ - if ((_x select 1) > 0) then { - _lookupTable pushBack _x; - }; -} forEach (GVAR(workingMemory) select 19); - -private _lookupTableSize = count _lookupTable; -if (_lookupTableSize < 2) exitWith {}; -_lookupTable sort true; - -private _lowerIndex = -1; -private _upperIndex = -1; - -for "_index" from 1 to (_lookupTableSize - 1) do { - _upperIndex = _index; - _lowerIndex = _upperIndex - 1; - if (((_lookupTable select _index) select 0) >= (GVAR(targetRange) select GVAR(currentTarget))) 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 + ((GVAR(targetRange) select GVAR(currentTarget)) - _lowerDistance) * _slope; -}; -_c1 = 0.1 max _c1 min 2.0; +private _c1 = [GVAR(targetRange) select GVAR(currentTarget)] call FUNC(lookup_c1_ballistic_coefficient); if (_c1 != GVAR(workingMemory) select 15) then { GVAR(workingMemory) set [15, _c1];