From 2fef7bc4bc3aa38a0f9708c46b1a2d8753b4c53a Mon Sep 17 00:00:00 2001 From: NeilZar Date: Tue, 12 Feb 2019 22:23:48 +0100 Subject: [PATCH 1/6] A bunch of performance improvement --- .../changeAttributes/fn_changePylonAmmo.sqf | 53 ++++++------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf index 055b57fd..fc90ce78 100644 --- a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf +++ b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf @@ -16,32 +16,25 @@ 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 _allCurrentPylonMagazines = getPylonMagazines _plane; -private _pylon_cfgs = (configFile >> "cfgVehicles" >> _planeType >> "Components" >> "TransportPylonsComponent" >> "pylons") call BIS_fnc_returnChildren; +private _pylonCfgs = configProperties [configFile >> "cfgVehicles" >> _planeType >> "Components" >> "TransportPylonsComponent" >> "pylons", "isClass _x"]; +private _pylonTurrets = _pylonCfgs apply { getArray (_x >> "turret") }; private _entries = []; -private _addWeaponsTo = []; -if (_hasGunner) then -{ - _addWeaponsTo = if(_plane getVariable ["Achilles_var_changePylonAmmo_Assigned", [0]] isEqualTo []) then {0} else {1}; - _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; @@ -49,29 +42,13 @@ if (_dialogResult isEqualTo []) exitWith {}; private _curatorSelected = ["vehicle"] call Achilles_fnc_getCuratorSelected; _curatorSelected = _curatorSelected select {_x isKindOf _planeType}; -if (_hasGunner) then -{ - _addWeaponsTo = [[], [0]] select (_dialogResult select 0 == 1); - _plane setVariable ["Achilles_var_changePylonAmmo_Assigned", _addWeaponsTo, true]; -}; - -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, _pylonTurrets select _forEachIndex]; } forEach _dialogResult; } forEach _curatorSelected; From 564ddf6805cb254240c5049720e642f0ecbae103 Mon Sep 17 00:00:00 2001 From: NeilZar Date: Tue, 12 Feb 2019 23:04:33 +0100 Subject: [PATCH 2/6] Re-add gunner stuff --- .../changeAttributes/fn_changePylonAmmo.sqf | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf index fc90ce78..a693ccd1 100644 --- a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf +++ b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf @@ -18,10 +18,17 @@ params ["_plane"]; private _planeType = typeOf _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 _pylonCfgs = configProperties [configFile >> "cfgVehicles" >> _planeType >> "Components" >> "TransportPylonsComponent" >> "pylons", "isClass _x"]; -private _pylonTurrets = _pylonCfgs apply { getArray (_x >> "turret") }; private _entries = []; +private _addWeaponsTo = []; +if (_hasGunner) then +{ + _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 _pylonIndex = _forEachIndex; @@ -42,6 +49,13 @@ if (_dialogResult isEqualTo []) exitWith {}; private _curatorSelected = ["vehicle"] call Achilles_fnc_getCuratorSelected; _curatorSelected = _curatorSelected select {_x isKindOf _planeType}; +if (_hasGunner) then +{ + _addWeaponsTo = [[], [0]] select (_dialogResult select 0 == 1); + _plane setVariable ["Achilles_var_changePylonAmmo_Assigned", _addWeaponsTo, true]; + _dialogResult deleteAt 0 +}; + { private _plane = _x; {_plane removeWeaponGlobal getText (configFile >> "CfgMagazines" >> _x >> "pylonWeapon")} forEach _allCurrentPylonMagazines; @@ -49,6 +63,6 @@ _curatorSelected = _curatorSelected select {_x isKindOf _planeType}; private _magIndex = _x - 1; private _pylonIndex = _forEachIndex + 1; private _magClassName = if (_x > 0) then {(_compatibleMagazines select _forEachIndex) select _magIndex} else {""}; - _plane setPylonLoadOut [_pylonIndex, _magClassName, false, _pylonTurrets select _forEachIndex]; + _plane setPylonLoadOut [_pylonIndex, _magClassName, false, _addWeaponsTo]; } forEach _dialogResult; } forEach _curatorSelected; From 3b287b9529ecfce23dfc7de1978dc6b5f449e582 Mon Sep 17 00:00:00 2001 From: NeilZar Date: Tue, 12 Feb 2019 23:07:41 +0100 Subject: [PATCH 3/6] Edit header --- .../changeAttributes/fn_changePylonAmmo.sqf | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf index a693ccd1..0cb6771f 100644 --- a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf +++ b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf @@ -1,18 +1,21 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// 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: + none + + Examples: + (begin example) + [_vehicle] call Achilles_fnc_changePylonAmmo; + (end) +*/ params ["_plane"]; private _planeType = typeOf _plane; @@ -53,7 +56,7 @@ if (_hasGunner) then { _addWeaponsTo = [[], [0]] select (_dialogResult select 0 == 1); _plane setVariable ["Achilles_var_changePylonAmmo_Assigned", _addWeaponsTo, true]; - _dialogResult deleteAt 0 + _dialogResult deleteAt 0 }; { From 1f48eb3135a066cd589aefbdfabc25a63ab58c3b Mon Sep 17 00:00:00 2001 From: NeilZar Date: Wed, 13 Feb 2019 13:04:42 +0100 Subject: [PATCH 4/6] review stuff --- .../functions/changeAttributes/fn_changePylonAmmo.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf index 0cb6771f..dddcf991 100644 --- a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf +++ b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf @@ -56,7 +56,7 @@ if (_hasGunner) then { _addWeaponsTo = [[], [0]] select (_dialogResult select 0 == 1); _plane setVariable ["Achilles_var_changePylonAmmo_Assigned", _addWeaponsTo, true]; - _dialogResult deleteAt 0 + _dialogResult deleteAt 0; }; { From 78678849fe2ed54a25c1ae309b21ca917b73dcda Mon Sep 17 00:00:00 2001 From: NeilZar Date: Sat, 16 Feb 2019 17:51:27 +0100 Subject: [PATCH 5/6] It is nothing --- .../functions/changeAttributes/fn_changePylonAmmo.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf index dddcf991..dad69972 100644 --- a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf +++ b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf @@ -9,7 +9,7 @@ _this: OBJECT - Vehicle to edit Returns: - none + Nothing Examples: (begin example) From 376155f48d32759c79ca6b67e0d58c0a1b56a25c Mon Sep 17 00:00:00 2001 From: NeilZar Date: Thu, 7 Mar 2019 16:52:39 +0100 Subject: [PATCH 6/6] Address reviews --- .../changeAttributes/fn_changePylonAmmo.sqf | 2 +- .../functions/common/fn_returnChildren.sqf | 39 +++++++++---------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf index dad69972..7f867dba 100644 --- a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf +++ b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/changeAttributes/fn_changePylonAmmo.sqf @@ -23,7 +23,7 @@ if (!isClass (configFile >> "cfgVehicles" >> _planeType >> "Components" >> "Tran private _hasGunner = !(fullCrew [_plane, "gunner", true] isEqualTo []); private _allCurrentPylonMagazines = getPylonMagazines _plane; -private _pylonCfgs = configProperties [configFile >> "cfgVehicles" >> _planeType >> "Components" >> "TransportPylonsComponent" >> "pylons", "isClass _x"]; +private _pylonCfgs = (configFile >> "cfgVehicles" >> _planeType >> "Components" >> "TransportPylonsComponent" >> "pylons") call Achilles_fnc_returnChildren; private _entries = []; private _addWeaponsTo = []; if (_hasGunner) then diff --git a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/common/fn_returnChildren.sqf b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/common/fn_returnChildren.sqf index da0d480a..7ddd300a 100644 --- a/@AresModAchillesExpansion/addons/functions_f_achilles/functions/common/fn_returnChildren.sqf +++ b/@AresModAchillesExpansion/addons/functions_f_achilles/functions/common/fn_returnChildren.sqf @@ -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"];