Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework pylon loadout attribute #454

Merged
merged 8 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AUTHOR: Kex, CoxLedere, CreepPork_LV
// DATE: 07/10/2017 (DD/MM/YYYY)
// VERSION: 3.0
// DESCRIPTION: opens the "ammo" dialog for vehicles.
//
// ARGUMENTS:
// _this select 0 _vehicle (optional)
//
// RETURNS:
// nothing (procedure)
//
// Example:
// [_vehicle] call Achilles_fnc_changePylonAmmo;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
Authors:
Kex, CoxLedere, CreepPork_LV, NeilZar

DESCRIPTION:
Opens the "ammo" dialog for vehicles.

Parameters:
_this: OBJECT - Vehicle to edit

Returns:
Nothing

Examples:
(begin example)
[_vehicle] call Achilles_fnc_changePylonAmmo;
(end)
*/

params ["_plane"];
private _planeType = typeOf _plane;
if (!isClass (configFile >> "cfgVehicles" >> _planeType >> "Components" >> "TransportPylonsComponent")) exitWith {[localize "STR_AMAE_NO_DYNAMIC_LOADOUT"] call Achilles_fnc_ShowZeusErrorMessage; nil};

private _hasGunner = not isNull gunner _plane;
if (!isClass (configFile >> "cfgVehicles" >> _planeType >> "Components" >> "TransportPylonsComponent")) exitWith { [localize "STR_AMAE_NO_DYNAMIC_LOADOUT"] call Achilles_fnc_ShowZeusErrorMessage; };

private _hasGunner = !(fullCrew [_plane, "gunner", true] isEqualTo []);
private _allCurrentPylonMagazines = getPylonMagazines _plane;
private _pylon_cfgs = (configFile >> "cfgVehicles" >> _planeType >> "Components" >> "TransportPylonsComponent" >> "pylons") call BIS_fnc_returnChildren;
private _pylonCfgs = (configFile >> "cfgVehicles" >> _planeType >> "Components" >> "TransportPylonsComponent" >> "pylons") call Achilles_fnc_returnChildren;
private _entries = [];
private _addWeaponsTo = [];
if (_hasGunner) then
if (_hasGunner) then
{
_addWeaponsTo = if(_plane getVariable ["Achilles_var_changePylonAmmo_Assigned", [0]] isEqualTo []) then {0} else {1};
_addWeaponsTo = [1, 0] select (_plane getVariable ["Achilles_var_changePylonAmmo_Assigned", [0]] isEqualTo []);
_entries pushBack [localize "STR_AMAE_ASSIGN_WEAPONS", [localize "STR_AMAE_DRIVER", localize "STR_AMAE_GUNNER"], _addWeaponsTo, true];
};

private _compatibleMagazines = (_plane getCompatiblePylonMagazines 0);
{
private _pylon_cfg = _x;
private _pylonIndex = _forEachIndex + 1;
private _pylonIndex = _forEachIndex;
private _magazineNames = ["Empty"];
private _defaultIndex = 0;
{
private _mag_cfg = (configFile >> "cfgMagazines" >> _x);
_magazineNames pushBack format ["%1 (%2)", getText (_mag_cfg >> "displayName"), getText (_mag_cfg >> "DisplayNameShort")];
if (configName _mag_cfg == _allCurrentPylonMagazines select (_pylonIndex - 1)) then {_defaultIndex = _forEachIndex + 1};
} forEach (_plane getCompatiblePylonMagazines _pylonIndex);
private _magCfg = configFile >> "cfgMagazines" >> _x;
_magazineNames pushBack format ["%1 (%2)", getText (_magCfg >> "displayName"), getText (_magCfg >> "DisplayNameShort")];
if (_x == _allCurrentPylonMagazines select _pylonIndex) then { _defaultIndex = _forEachIndex + 1 };
} forEach _x;

_entries pushBack [configName _pylon_cfg, _magazineNames, _defaultIndex, true];
} forEach _pylon_cfgs;
_entries pushBack [configName (_pylonCfgs select _pylonIndex), _magazineNames, _defaultIndex, true];
} forEach _compatibleMagazines;

private _dialogResult = [localize "STR_AMAE_LOADOUT", _entries] call Ares_fnc_ShowChooseDialog;

Expand All @@ -53,25 +56,16 @@ if (_hasGunner) then
{
_addWeaponsTo = [[], [0]] select (_dialogResult select 0 == 1);
_plane setVariable ["Achilles_var_changePylonAmmo_Assigned", _addWeaponsTo, true];
_dialogResult deleteAt 0;
};

if (_hasGunner) then {_dialogResult deleteAt 0};

{
private _plane = _x;
{_plane removeWeaponTurret [getText (configFile >> "CfgMagazines" >> _x >> "pylonWeapon"),[-1]]} forEach (_plane getCompatiblePylonMagazines _forEachIndex + 1);
{_plane removeWeaponTurret [getText (configFile >> "CfgMagazines" >> _x >> "pylonWeapon"),[0]]} forEach (_plane getCompatiblePylonMagazines _forEachIndex + 1);
{_plane removeWeaponGlobal getText (configFile >> "CfgMagazines" >> _x >> "pylonWeapon")} forEach _allCurrentPylonMagazines;
{
private _magIndex = _x;
private _magIndex = _x - 1;
private _pylonIndex = _forEachIndex + 1;
private _magClassName = if (_x > 0) then {(_plane getCompatiblePylonMagazines _pylonIndex) select (_magIndex - 1)} else {""};
if (local _plane) then
{
_plane setPylonLoadOut [_pylonIndex, _magClassName, false, _addWeaponsTo];
}
else
{
[_plane, [_pylonIndex, _magClassName, false, _addWeaponsTo]] remoteExecCall ["setPylonLoadOut", _plane];
};
private _magClassName = if (_x > 0) then {(_compatibleMagazines select _forEachIndex) select _magIndex} else {""};
_plane setPylonLoadOut [_pylonIndex, _magClassName, false, _addWeaponsTo];
} forEach _dialogResult;
} forEach _curatorSelected;
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AUTHOR: Kex
// DATE: 12/26/17
// VERSION: AMAE.1.0.0
// DESCRIPTION: Similar to BIS_fnc_returnChildren, but more efficient and depth is always 0.
//
// ARGUMENTS: 0: CONFIG - Parent config.
//
// RETURNS: ARRAY - List of configs of all children
//
// Example: (configFile >> "CfgVehicles") call Achilles_fnc_returnChildren;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
Authors:
NeilZar

params [["_parent_cfg",configFile,[configFile]]];
private _cfg_list = [];
DESCRIPTION:
Similar to BIS_fnc_returnChildren, but more efficient and depth is always 0.

for "_i" from 0 to (count _parent_cfg - 1) do
{
private _child_cfg = _parent_cfg select _i;
if(isClass _child_cfg) then {_cfg_list pushBack _child_cfg};
};
_cfg_list;
Parameters:
_this: CONFIG - Parent config.

Returns:
ARRAY - List of configs of all children

Examples:
(begin example)
(configFile >> "CfgVehicles") call Achilles_fnc_returnChildren;
(end)
*/
params [["_parentCfg", configFile, [configFile]]];

configProperties [_parentCfg, "isClass _x"];