Skip to content

Commit

Permalink
ATragMX - Utilize 'C1 vs. Distance' data in the range card output
Browse files Browse the repository at this point in the history
  • Loading branch information
ulteq committed Nov 3, 2017
1 parent e1d6532 commit 888a8aa
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 31 deletions.
1 change: 1 addition & 0 deletions addons/atragmx/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions addons/atragmx/functions/fnc_calculate_range_card.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
51 changes: 51 additions & 0 deletions addons/atragmx/functions/fnc_lookup_c1_ballistic_coefficient.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Author: Ruthberg
* Lookup the correct C1 ballistic coefficient in the c1 ballistic coefficient vs. distance interpolation table
*
* Arguments:
* Target Range <NUMBER>
*
* Return Value:
* C1 ballistic coefficient <NUMBER
*
* Example:
* call ace_atragmx_fnc_lookup_c1_ballistic_coefficient
*
* Public: No
*/
#include "script_component.hpp"

params ["_targetRange"];

private _lookupTable = [];
{
if ((_x select 1) > 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
Original file line number Diff line number Diff line change
@@ -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 <BOOL>
Expand All @@ -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];
Expand Down

0 comments on commit 888a8aa

Please sign in to comment.