Skip to content

Commit 74d271f

Browse files
authored
Improve pylon turret functionality by using getAllPylonsInfo (#531)
1 parent 98eb99f commit 74d271f

File tree

6 files changed

+14
-40
lines changed

6 files changed

+14
-40
lines changed

addons/common/functions/fnc_exportMissionSQF.sqf

+3-5
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,11 @@ private _fnc_processVehicle = {
271271
_outputObjects pushBack ["{%1 addMagazineTurret _x} forEach %2;", _varName, _turretMagazines];
272272

273273
{
274-
private _pylonIndex = _forEachIndex + 1;
275-
private _turretPath = [_vehicle, _forEachIndex] call FUNC(getPylonTurret);
276-
private _ammoCount = _vehicle ammoOnPylon _pylonIndex;
274+
_x params ["_pylonIndex", "", "_turretPath", "_magazine", "_ammoCount"];
277275

278-
_outputObjects pushBack ["%1 setPylonLoadOut [%2, %3, false, %4];", _varName, _pylonIndex, str _x, _turretPath];
276+
_outputObjects pushBack ["%1 setPylonLoadOut [%2, %3, false, %4];", _varName, _pylonIndex, str _magazine, _turretPath];
279277
_outputObjects pushBack ["%1 setAmmoOnPylon [%2, %3];", _varName, _pylonIndex, _ammoCount];
280-
} forEach _pylonMagazines;
278+
} forEach getAllPylonsInfo _vehicle;
281279

282280
{
283281
_x params ["_unit", "_role", "_cargoIndex", "_turretPath"];

addons/common/functions/fnc_getPylonTurret.sqf

+1-30
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/*
33
* Author: mharis001
44
* Returns the turret path that owns the given pylon.
5-
* Will return the config defined turret if the owner is ambiguous.
65
*
76
* Arguments:
87
* 0: Vehicle <OBJECT>
@@ -19,32 +18,4 @@
1918

2019
params ["_vehicle", "_pylonIndex"];
2120

22-
// Get the pylon magazine and current ammo for the given pylon index
23-
private _pylonMagazine = getPylonMagazines _vehicle select _pylonIndex;
24-
private _pylonAmmo = _vehicle ammoOnPylon (_pylonIndex + 1);
25-
26-
// Get turret paths for magazines of the same type and current ammo count
27-
private _turretPaths = [];
28-
29-
{
30-
_x params ["_magazine", "_turretPath", "_ammoCount"];
31-
32-
if (_magazine == _pylonMagazine && {_ammoCount == _pylonAmmo}) then {
33-
// Pylons uses [] for driver turret instead of the normal [-1]
34-
if (_turretPath isEqualTo [-1]) then {
35-
_turretPath = [];
36-
};
37-
38-
_turretPaths pushBackUnique _turretPath;
39-
};
40-
} forEach magazinesAllTurrets _vehicle;
41-
42-
// Exit with the matched turret path if only one was found
43-
if (count _turretPaths == 1) exitWith {
44-
_turretPaths select 0
45-
};
46-
47-
// More than one turret path or none were found, situation is ambiguous
48-
// Return the config defined turret path for this pylon
49-
private _pylonConfig = configOf _vehicle >> "Components" >> "TransportPylonsComponent" >> "Pylons";
50-
getArray (configProperties [_pylonConfig, "isClass _x"] select _pylonIndex >> "turret")
21+
getAllPylonsInfo _vehicle param [_pylonIndex, []] param [2, [-1]]

addons/pylons/functions/fnc_configure.sqf

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ private _controls = [];
5454
private _mirroredIndex = getNumber (_x >> "mirroredMissilePos") - 1;
5555
private _defaultTurretPath = getArray (_x >> "turret");
5656

57+
// Pylon config can use [] as the driver turret path
58+
if (_defaultTurretPath isEqualTo []) then {
59+
_defaultTurretPath = [-1];
60+
};
61+
5762
private _ctrlCombo = _display ctrlCreate ["ctrlCombo", -1];
5863
_ctrlCombo ctrlSetPosition [_posX, _posY, GRID_W(82/3), GRID_H(5)];
5964
_ctrlCombo ctrlCommit 0;

addons/pylons/functions/fnc_handleConfirm.sqf

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ private _pylonLoadout = [];
3434
_x params ["_ctrlCombo", "_ctrlTurret"];
3535

3636
private _magazine = _ctrlCombo lbData lbCurSel _ctrlCombo;
37-
private _turretPath = _ctrlTurret getVariable [QGVAR(turretPath), []];
37+
private _turretPath = _ctrlTurret getVariable [QGVAR(turretPath), [-1]];
3838

3939
private _pylonWeapon = configName (_cfgWeapons >> getText (_cfgMagazines >> _magazine >> "pylonWeapon"));
4040

41-
if (_turretPath isEqualTo []) then {
41+
if (_turretPath isEqualTo [-1]) then {
4242
_driverWeapons pushBackUnique _pylonWeapon;
4343
} else {
4444
_gunnerWeapons pushBackUnique _pylonWeapon;

addons/pylons/functions/fnc_handleMagazineSelect.sqf

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if (cbChecked (_display displayCtrl IDC_MIRROR)) then {
4040
{
4141
_x params ["_ctrlComboMirrored", "", "_mirroredIndex"];
4242

43-
if (_mirroredIndex == _pylonIndex) then {
43+
if (_mirroredIndex == _pylonIndex) exitWith {
4444
_ctrlComboMirrored lbSetCurSel _selectedIndex;
4545
};
4646
} forEach (_display getVariable QGVAR(controls));

addons/pylons/functions/fnc_handleTurretButton.sqf

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private _turretPath = _ctrlTurret getVariable QGVAR(turretPath);
2222

2323
// Toggle between driver and gunner turret if required
2424
if (_toggle) then {
25-
_turretPath = [[], [0]] select (_turretPath isEqualTo []);
25+
_turretPath = [[-1], [0]] select (_turretPath isEqualTo [-1]);
2626
_ctrlTurret setVariable [QGVAR(turretPath), _turretPath];
2727

2828
private _display = ctrlParent _ctrlTurret;
@@ -43,7 +43,7 @@ if (_toggle) then {
4343
};
4444

4545
// Update the button's icon and tooltip
46-
if (_turretPath isEqualTo []) then {
46+
if (_turretPath isEqualTo [-1]) then {
4747
_ctrlTurret ctrlSetText ICON_DRIVER;
4848
_ctrlTurret ctrlSetTooltip localize "STR_Driver";
4949
} else {

0 commit comments

Comments
 (0)