From 156609aab2da32025f9de7bb2391b35babc6b99d Mon Sep 17 00:00:00 2001 From: jokoho48 Date: Sun, 9 Aug 2015 05:18:26 +0200 Subject: [PATCH] Code cleanup of Disarming module --- addons/disarming/XEH_postInit.sqf | 4 +- .../disarming/functions/fnc_canBeDisarmed.sqf | 9 +++-- .../functions/fnc_canPlayerDisarmUnit.sqf | 5 ++- .../functions/fnc_disarmDropItems.sqf | 11 +++--- .../functions/fnc_eventCallerFinish.sqf | 3 +- .../functions/fnc_eventTargetFinish.sqf | 3 +- .../functions/fnc_eventTargetStart.sqf | 7 ++-- .../functions/fnc_getAllGearContainer.sqf | 15 +++++--- .../functions/fnc_getAllGearUnit.sqf | 5 ++- .../functions/fnc_openDisarmDialog.sqf | 38 +++++++------------ .../functions/fnc_showItemsInListbox.sqf | 34 ++++++++++------- .../functions/fnc_verifyMagazinesMoved.sqf | 3 +- 12 files changed, 71 insertions(+), 66 deletions(-) diff --git a/addons/disarming/XEH_postInit.sqf b/addons/disarming/XEH_postInit.sqf index 7315ef1785..ef17e6e96a 100644 --- a/addons/disarming/XEH_postInit.sqf +++ b/addons/disarming/XEH_postInit.sqf @@ -1,4 +1,4 @@ #include "script_component.hpp" -["DisarmDropItems", {_this call FUNC(eventTargetStart)}] call EFUNC(common,addEventHandler); -["DisarmDebugCallback", {_this call FUNC(eventCallerFinish)}] call EFUNC(common,addEventHandler); +["DisarmDropItems", FUNC(eventTargetStart)] call EFUNC(common,addEventHandler); +["DisarmDebugCallback", FUNC(eventCallerFinish)] call EFUNC(common,addEventHandler); diff --git a/addons/disarming/functions/fnc_canBeDisarmed.sqf b/addons/disarming/functions/fnc_canBeDisarmed.sqf index 25ec884919..9be20db7f4 100644 --- a/addons/disarming/functions/fnc_canBeDisarmed.sqf +++ b/addons/disarming/functions/fnc_canBeDisarmed.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Checks the conditions for being able to disarm a unit * * Arguments: @@ -15,17 +16,17 @@ */ #include "script_component.hpp" -PARAMS_1(_target); - private ["_animationStateCfgMoves", "_putDownAnim"]; +params ["_target"]; + //Check animationState for putDown anim //This ensures the unit doesn't have to actualy do any animation to drop something //This should always be true for the 3 possible status effects that allow disarming _animationStateCfgMoves = getText (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState _target) >> "actions"); -if (_animationStateCfgMoves == "") exitWith {false}; +if (_animationStateCfgMoves == "") exitWith { false }; _putDownAnim = getText (configFile >> "CfgMovesBasic" >> "Actions" >> _animationStateCfgMoves >> "PutDown"); -if (_putDownAnim != "") exitWith {false}; +if (_putDownAnim != "") exitWith { false }; (alive _target) && diff --git a/addons/disarming/functions/fnc_canPlayerDisarmUnit.sqf b/addons/disarming/functions/fnc_canPlayerDisarmUnit.sqf index ec9e975ec2..34f1a10d32 100644 --- a/addons/disarming/functions/fnc_canPlayerDisarmUnit.sqf +++ b/addons/disarming/functions/fnc_canPlayerDisarmUnit.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Checks the conditions for being able to disarm a unit * * Arguments: @@ -16,7 +17,7 @@ */ #include "script_component.hpp" -PARAMS_2(_player,_target); +params ["_player", "_target"]; -([_target] call FUNC(canBeDisarmed)) && +([_target] call FUNC(canBeDisarmed)) && {([_player, _target, []] call EFUNC(common,canInteractWith))} diff --git a/addons/disarming/functions/fnc_disarmDropItems.sqf b/addons/disarming/functions/fnc_disarmDropItems.sqf index 5422fd00a6..567199e6cf 100644 --- a/addons/disarming/functions/fnc_disarmDropItems.sqf +++ b/addons/disarming/functions/fnc_disarmDropItems.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Makes a unit drop items * * Arguments: @@ -22,13 +23,11 @@ private ["_fncSumArray", "_return", "_holder", "_dropPos", "_targetMagazinesStart", "_holderMagazinesStart", "_xClassname", "_xAmmo", "_targetMagazinesEnd", "_holderMagazinesEnd", "_holderItemsStart", "_targetItemsStart", "_addToCrateClassnames", "_addToCrateCount", "_index", "_holderItemsEnd", "_targetItemsEnd", "_holderIsEmpty"]; - -PARAMS_3(_caller,_target,_listOfItemsToRemove); -DEFAULT_PARAM(3,_doNotDropAmmo,false); //By default units drop all weapon mags when dropping a weapon +params ["_caller", "_target", "_listOfItemsToRemove", ["_doNotDropAmmo", false, [false]]]; //By default units drop all weapon mags when dropping a weapon _fncSumArray = { _return = 0; - {_return = _return + _x;} forEach (_this select 0); + {_return = _return + _x;} count (_this select 0); _return }; @@ -48,7 +47,7 @@ if (!_doNotDropAmmo) then { if ((_x getVariable [QGVAR(disarmUnit), objNull]) == _target) exitWith { _holder = _x; }; - } forEach ((getpos _target) nearObjects [DISARM_CONTAINER, 3]); + } count ((getpos _target) nearObjects [DISARM_CONTAINER, 3]); }; //Create a new weapon holder @@ -124,7 +123,7 @@ _addToCrateCount = []; _addToCrateCount pushBack 1; }; }; -} forEach _targetItemsStart; +} count _targetItemsStart; //Add the items to the holder (combined to reduce addItemCargoGlobal calls) { diff --git a/addons/disarming/functions/fnc_eventCallerFinish.sqf b/addons/disarming/functions/fnc_eventCallerFinish.sqf index d95be98d5f..bc48a26b70 100644 --- a/addons/disarming/functions/fnc_eventCallerFinish.sqf +++ b/addons/disarming/functions/fnc_eventCallerFinish.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Recieves a possible error code from FUNC(eventTargetFinish) * * Arguments: @@ -17,7 +18,7 @@ */ #include "script_component.hpp" -PARAMS_3(_caller,_target,_errorMsg); +params ["_caller", "_target", "_errorMsg"]; if (_caller != ACE_player) exitWith {}; diff --git a/addons/disarming/functions/fnc_eventTargetFinish.sqf b/addons/disarming/functions/fnc_eventTargetFinish.sqf index d702a554a5..b9fb461356 100644 --- a/addons/disarming/functions/fnc_eventTargetFinish.sqf +++ b/addons/disarming/functions/fnc_eventTargetFinish.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * After FUNC(disarmDropItems) has completed, passing a possible error code. * Passes that error back to orginal caller. * @@ -18,7 +19,7 @@ */ #include "script_component.hpp" -PARAMS_3(_caller,_target,_errorMsg); +params ["_caller", "_target", "_errorMsg"]; if (_errorMsg != "") then { diag_log text format ["[ACE_Disarming] %1 - eventTargetFinish: %2", ACE_time, _this]; diff --git a/addons/disarming/functions/fnc_eventTargetStart.sqf b/addons/disarming/functions/fnc_eventTargetStart.sqf index 316ec2b656..771365d602 100644 --- a/addons/disarming/functions/fnc_eventTargetStart.sqf +++ b/addons/disarming/functions/fnc_eventTargetStart.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Disarm Event Handler, Starting func, called on the target. * If target has to remove uniform/vest, this will add all uniform/vest items to the drop list. * @@ -18,7 +19,7 @@ */ #include "script_component.hpp" -PARAMS_3(_caller,_target,_listOfObjectsToRemove); +params ["_caller", "_target", "_listOfObjectsToRemove"]; private "_itemsToAdd"; @@ -30,12 +31,12 @@ _itemsToAdd = []; if (_x == (vest _target)) then { _itemsToAdd = _itemsToAdd + (vestItems _target); }; -} forEach _listOfObjectsToRemove; +} count _listOfObjectsToRemove; { if (!(_x in _listOfObjectsToRemove)) then { _listOfObjectsToRemove pushBack _x; }; -} forEach _itemsToAdd; +} count _itemsToAdd; [_caller, _target, _listOfObjectsToRemove] call FUNC(disarmDropItems); diff --git a/addons/disarming/functions/fnc_getAllGearContainer.sqf b/addons/disarming/functions/fnc_getAllGearContainer.sqf index c5b2c445ab..89901ee983 100644 --- a/addons/disarming/functions/fnc_getAllGearContainer.sqf +++ b/addons/disarming/functions/fnc_getAllGearContainer.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Helper function to get all gear of a container * * Arguments: @@ -15,15 +16,17 @@ */ #include "script_component.hpp" -PARAMS_1(_target); +params ["_target"]; private ["_allGear"]; -_allGear = [[],[]]; +_items = []; +_counts = []; { - (_allGear select 0) append (_x select 0); - (_allGear select 1) append (_x select 1); -} forEach [(getWeaponCargo _target), (getItemCargo _target), (getMagazineCargo _target), (getBackpackCargo _target)]; + _x params ["_item", "_count"]; + _item append _item; + _count append _count; +} count [(getWeaponCargo _target), (getItemCargo _target), (getMagazineCargo _target), (getBackpackCargo _target)]; -_allGear +[_items,_counts] // Return diff --git a/addons/disarming/functions/fnc_getAllGearUnit.sqf b/addons/disarming/functions/fnc_getAllGearUnit.sqf index 99d4b2d7f2..4eb45f94f2 100644 --- a/addons/disarming/functions/fnc_getAllGearUnit.sqf +++ b/addons/disarming/functions/fnc_getAllGearUnit.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Helper function to get all gear of a unit. * * Arguments: @@ -15,7 +16,7 @@ */ #include "script_component.hpp" -PARAMS_1(_target); +params ["_target"]; private ["_allItems", "_classnamesCount", "_index", "_uniqueClassnames"]; @@ -49,6 +50,6 @@ _classnamesCount = []; _uniqueClassnames pushBack _x; _classnamesCount pushBack 1; }; -} forEach _allItems; +} count _allItems; [_uniqueClassnames, _classnamesCount] diff --git a/addons/disarming/functions/fnc_openDisarmDialog.sqf b/addons/disarming/functions/fnc_openDisarmDialog.sqf index 88e0e81be8..c2a3a6396e 100644 --- a/addons/disarming/functions/fnc_openDisarmDialog.sqf +++ b/addons/disarming/functions/fnc_openDisarmDialog.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Opens the disarm dialog (allowing a person to remove items) * * Arguments: @@ -15,21 +16,9 @@ * Public: No */ #include "script_component.hpp" - -#define TEXTURES_RANKS [ \ - "", \ - "\A3\Ui_f\data\GUI\Cfg\Ranks\private_gs.paa", \ - "\A3\Ui_f\data\GUI\Cfg\Ranks\corporal_gs.paa", \ - "\A3\Ui_f\data\GUI\Cfg\Ranks\sergeant_gs.paa", \ - "\A3\Ui_f\data\GUI\Cfg\Ranks\lieutenant_gs.paa", \ - "\A3\Ui_f\data\GUI\Cfg\Ranks\captain_gs.paa", \ - "\A3\Ui_f\data\GUI\Cfg\Ranks\major_gs.paa", \ - "\A3\Ui_f\data\GUI\Cfg\Ranks\colonel_gs.paa" \ - ] - -PARAMS_2(_caller,_target); +params ["_caller", "_target"]; private "_display"; - +#define DEFUALTPATH "\A3\Ui_f\data\GUI\Cfg\Ranks\%1_gs.paa" //Sanity Checks if (_caller != ACE_player) exitwith {ERROR("Player isn't caller?");}; if (!([_player, _target] call FUNC(canPlayerDisarmUnit))) exitWith {ERROR("Can't Disarm Unit");}; @@ -47,8 +36,8 @@ GVAR(disarmTarget) = _target; //Setup Drop Event (on right pannel) (_display displayCtrl 632) ctrlAddEventHandler ["LBDrop", { if (isNull GVAR(disarmTarget)) exitWith {}; - PARAMS_5(_ctrl,_xPos,_yPos,_idc,_itemInfo); - EXPLODE_3_PVT((_itemInfo select 0),_displayText,_value,_data); + params ["_ctrl", "_xPos", "_yPos", "_idc", "_itemInfo"]; + (_itemInfo select 0) params ["_displayText", "_value", "_data"]; if (isNull GVAR(disarmTarget)) exitWith {ERROR("disarmTarget is null");}; @@ -60,18 +49,18 @@ GVAR(disarmTarget) = _target; //Setup PFEH [{ - private ["_groundContainer", "_targetContainer", "_playerName", "_rankPicture", "_rankIndex", "_targetUniqueItems", "_holderUniqueItems", "_holder"]; + private ["_groundContainer", "_targetContainer", "_playerName", "_icon", "_rankPicture", "_targetUniqueItems", "_holderUniqueItems", "_holder"]; disableSerialization; - EXPLODE_2_PVT(_this,_args,_pfID); - EXPLODE_3_PVT(_args,_player,_target,_display); + params ["_args", "_idPFH"]; + _args params ["_player", "_target", "_display"]; if ((!([_player, _target] call FUNC(canPlayerDisarmUnit))) || {isNull _display} || {_player != ACE_player}) then { - [_pfID] call CBA_fnc_removePerFrameHandler; + [_idPFH] call CBA_fnc_removePerFrameHandler; GVAR(disarmTarget) = objNull; - if (!isNull _display) then {closeDialog 0;}; //close dialog if still open + if (!isNull _display) then { closeDialog 0; }; //close dialog if still open } else { _groundContainer = _display displayCtrl 632; @@ -80,8 +69,9 @@ GVAR(disarmTarget) = _target; _rankPicture = _display displayCtrl 1203; //Show rank and name (just like BIS's inventory) - _rankIndex = ((["PRIVATE", "CORPORAL", "SERGEANT", "LIEUTENANT", "CAPTAIN", "MAJOR", "COLONEL"] find (rank _target)) + 1); - _rankPicture ctrlSetText (TEXTURES_RANKS select _rankIndex); + _icon = format [DEFUALTPATH, toLower (rank _target)]; + if (_icon isEqualTo DEFUALTPATH) then {_icon = ""}; + _rankPicture ctrlSetText _icon; _playerName ctrlSetText ([GVAR(disarmTarget)] call EFUNC(common,getName)); //Clear both inventory lists: @@ -98,7 +88,7 @@ GVAR(disarmTarget) = _target; if ((_x getVariable [QGVAR(disarmUnit), objNull]) == _target) exitWith { _holder = _x; }; - } forEach ((getpos _target) nearObjects [DISARM_CONTAINER, 3]); + } count ((getpos _target) nearObjects [DISARM_CONTAINER, 3]); //If a holder exists, show it's inventory if (!isNull _holder) then { diff --git a/addons/disarming/functions/fnc_showItemsInListbox.sqf b/addons/disarming/functions/fnc_showItemsInListbox.sqf index b36e53e820..f675012ee3 100644 --- a/addons/disarming/functions/fnc_showItemsInListbox.sqf +++ b/addons/disarming/functions/fnc_showItemsInListbox.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Shows a list of inventory items in a listBox control. * * Arguments: @@ -17,11 +18,12 @@ #include "script_component.hpp" disableSerialization; -PARAMS_2(_listBoxCtrl,_itemsCountArray); - private ["_classname", "_count", "_displayName", "_picture"]; +params ["_listBoxCtrl", "_itemsCountArray"]; + { + private "_configPath"; _displayName = ""; _picture = ""; @@ -31,21 +33,25 @@ private ["_classname", "_count", "_displayName", "_picture"]; if ((_classname != DUMMY_ITEM) && {_classname != "ACE_FakePrimaryWeapon"}) then { //Don't show the dummy potato or fake weapon switch (true) do { - case (isClass (configFile >> "CfgWeapons" >> _classname)): { - _displayName = getText (configFile >> "CfgWeapons" >> _classname >> "displayName"); - _picture = getText (configFile >> "CfgWeapons" >> _classname >> "picture"); + case (isClass (configFile >> "CfgWeapons" >> _classname)): { + _configPath = (configFile >> "CfgWeapons"); + _displayName = getText (_configPath >> _classname >> "displayName"); + _picture = getText (_configPath >> _classname >> "picture"); }; - case (isClass (configFile >> "CfgMagazines" >> _classname)): { - _displayName = getText (configFile >> "CfgMagazines" >> _classname >> "displayName"); - _picture = getText (configFile >> "CfgMagazines" >> _classname >> "picture"); + case (isClass (configFile >> "CfgMagazines" >> _classname)): { + _configPath = (configFile >> "CfgMagazines"); + _displayName = getText (_configPath >> _classname >> "displayName"); + _picture = getText (_configPath >> _classname >> "picture"); }; - case (isClass (configFile >> "CfgVehicles" >> _classname)): { - _displayName = getText (configFile >> "CfgVehicles" >> _classname >> "displayName"); - _picture = getText (configFile >> "CfgVehicles" >> _classname >> "picture"); + case (isClass (configFile >> "CfgVehicles" >> _classname)): { + _configPath = (configFile >> "CfgVehicles"); + _displayName = getText (_configPath >> _classname >> "displayName"); + _picture = getText (_configPath >> _classname >> "picture"); }; - case (isClass (configFile >> "CfgGlasses" >> _classname)): { - _displayName = getText (configFile >> "CfgGlasses" >> _classname >> "displayName"); - _picture = getText (configFile >> "CfgGlasses" >> _classname >> "picture"); + case (isClass (configFile >> "CfgGlasses" >> _classname)): { + _configPath = (configFile >> "CfgGlasses"); + _displayName = getText (_configPath >> _classname >> "displayName"); + _picture = getText (_configPath >> _classname >> "picture"); }; default { ERROR(format ["[%1] - bad classname", _classname]); diff --git a/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf b/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf index e1753f390a..36ed87fcd1 100644 --- a/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf +++ b/addons/disarming/functions/fnc_verifyMagazinesMoved.sqf @@ -1,5 +1,6 @@ /* * Author: PabstMirror + * * Verifies magazines moved with exact ammo counts preserved. * Arrays will be in format from magazinesAmmo/magazinesAmmoCargo * e.g.: [["30Rnd_65x39_caseless_mag",15], ["30Rnd_65x39_caseless_mag",30]] @@ -36,6 +37,6 @@ _problem = false; _index = _beginingArray find _x; if (_index == -1) exitWith {_problem = true;}; _beginingArray deleteAt _index; -} forEach (_endA + _endB); +} count (_endA + _endB); (!_problem) && {_beginingArray isEqualTo []}