ACE3/addons/artillerytables/functions/fnc_rangeTableOpen.sqf
PabstMirror 8e3fd45500
Artillery rangletables (universal) (#6853)
* Initial

* Update artillerytables.cpp

* Pass by value, remove c17 features

* Tweak accuracy

* SQF work

- improve compat with a3 mlrs with remote cam (animationSourcePhase)
- handle non [0] turrets (rhs prp)
- add config entries
- use vectorCos to fix fp error (thanks commy)

* Support per mag air friction

* tweak friction

* Integrate with mk6

* more acos fixes

* Handle invalid memPointGunOptic (CUP_BM21_Base)

* Cleanup

* cleanup/tweaks

* Update checkConfigs.sqf

* Finish cleanup of ace_mk6mortar

* Update stringtable.xml

* fix bwc for ACE_RangeTable_82mm

* Update fnc_rangeTableCanUse.sqf

* build 32dll, fix some headers

* strncpy and move testing to seperate file

* Move to sub-category

* Update for ACE_Extensions changes and add warning to ace_common

* Update stringtable.xml

* Update addons/common/functions/fnc_checkFiles.sqf

Co-Authored-By: jonpas <jonpas33@gmail.com>

* Update stringtable.xml

* Update stringtable.xml

* test extension.yml update logical operator

* Revert "test extension.yml update logical operator"

This reverts commit b1871724ad.

* more guess and test
2019-12-17 10:14:45 -06:00

88 lines
3.8 KiB
Plaintext

#include "script_component.hpp"
/*
* Author: PabstMirror
* Opens the rangetable and fills the charge listbox.
*
* Arguments:
* 0: Weapon configname <STRING>
* 1: Elevation Min (Deg) <NUMBER>
* 2: Elevation Max (Deg) <NUMBER>
* 3: Advanced Corrections Enabled <BOOL>
*
* Return Value:
* None
*
* Example:
* ["mortar_155mm_AMOS", -5, 80, true] call ace_artillerytables_fnc_rangeTableOpen
*
* Public: No
*/
params ["_weaponName", "_elevMin", "_elevMax", "_advCorrection"];
TRACE_4("rangeTableOpen",_weaponName,_elevMin,_elevMax,_advCorrection);
BEGIN_COUNTER(rangeTableOpen);
createDialog QGVAR(rangeTableDialog);
private _dialog = uiNamespace getVariable [QGVAR(rangeTableDialog), displayNull];
if (isNull _dialog) exitWith{ERROR("Dialog failed to open");};
private _ctrlChargeList = _dialog displayCtrl IDC_CHARGELIST;
_dialog setVariable [QGVAR(elevMin),_elevMin];
_dialog setVariable [QGVAR(elevMax),_elevMax];
_dialog setVariable [QGVAR(advCorrection),_advCorrection];
TRACE_2("created dialog",_dialog,_ctrlChargeList);
// Get Mags:
private _mags = [_weaponName] call CBA_fnc_compatibleMagazines;
if (_mags isEqualTo []) exitWith {WARNING_1("No Mags",_weaponName);};
private _magCfg = configFile >> "CfgMagazines";
private _magParamsArray = [];
_mags = _mags apply {
private _initSpeed = getNumber (_magCfg >> _x >> "initSpeed");
_magParamsArray pushBackUnique _initSpeed;
private _airFriction = 0;
if (_advCorrection) then {
_airFriction = if (isNumber (_magCfg >> _x >> QGVAR(airFriction))) then { getNumber (_magCfg >> _x >> QGVAR(airFriction)) } else { DEFAULT_AIR_FRICTION };
};
_magParamsArray pushBackUnique _airFriction;
[getText (_magCfg >> _x >> "displayNameShort"), getText (_magCfg >> _x >> "displayName"), _initSpeed, _airFriction]
};
TRACE_2("",_magParamsArray,_mags);
if ((count _magParamsArray) == 2) then { // test if all magazines share the parameters
_mags = [["", "All Magazines", (_mags select 0) select 2, (_mags select 0) select 3]]; // simplify
};
// Get Firemodes:
private _fireModes = getArray (configFile >> "CfgWeapons" >> _weaponName >> "modes");
_fireModes = (_fireModes apply {configFile >> "CfgWeapons" >> _weaponName >> _x}) select {1 == getNumber (_x >> "showToPlayer")};
_fireModes = _fireModes apply {[getNumber (_x >> "artilleryCharge"), configName _x]};
_fireModes sort true;
private _allSameCharge = ((count _fireModes) == 1) && {((_fireModes select 0) select 0) == 1};
TRACE_2("",_allSameCharge,_fireModes);
GVAR(magModeData) = [];
{
_x params ["_xDisplayNameShort", "_xDisplayName", "_xInitSpeed", "_xAirFriction"];
if (_allSameCharge) then {
_ctrlChargeList lbAdd format ["%1", _xDisplayNameShort];
_ctrlChargeList lbSetTooltip [count GVAR(magModeData), format ["%1\n%2 m/s\n%3", _xDisplayName, _xInitSpeed toFixed 1, _xAirFriction]];
GVAR(magModeData) pushBack [_xInitSpeed, _xAirFriction];
} else {
{
_x params ["_xModeCharge"];
_ctrlChargeList lbAdd format ["[Charge %1] %2", _forEachIndex, _xDisplayNameShort]; // forEachIndex is from firemodes
_ctrlChargeList lbSetTooltip [count GVAR(magModeData), format ["%1\n%2 m/s\n%3", _xDisplayName, (_xInitSpeed * _xModeCharge) toFixed 1, _xAirFriction]];
GVAR(magModeData) pushBack [_xInitSpeed * _xModeCharge, _xAirFriction];
} forEach _fireModes;
};
} forEach _mags;
if (isNil QGVAR(lastElevationMode)) then {GVAR(lastElevationMode) = true;};
if (isNil QGVAR(lastTablePage)) then {GVAR(lastTablePage) = 0;};
if ((GVAR(lastTablePage) >= (count GVAR(magModeData))) || {GVAR(lastTablePage) < 0}) then { GVAR(lastTablePage) = 0; };
END_COUNTER(rangeTableOpen);
TRACE_2("trigger update",GVAR(lastElevationMode),GVAR(lastTablePage));
_ctrlChargeList lbSetCurSel GVAR(lastTablePage); // triggers call to FUNC(rangeTableUpdate)