From 0633b807fa805fbf76eacc584859d0a3ac50d8d9 Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Wed, 10 Oct 2018 03:21:46 +0200 Subject: [PATCH] Some Refactoring (#6607) * SwitchUnits * tacticalLadder * vehiclelock * vector * Typo, thanks circleCI * Fix stuff * Fix animate loop --- addons/switchunits/functions/fnc_handleMapClick.sqf | 13 ++++--------- addons/switchunits/functions/fnc_initPlayer.sqf | 5 +---- addons/switchunits/functions/fnc_markAiOnMap.sqf | 2 +- addons/switchunits/functions/fnc_nearestPlayers.sqf | 10 +--------- .../switchunits/functions/fnc_startSwitchUnits.sqf | 8 ++++---- .../tacticalladder/functions/fnc_cancelTLdeploy.sqf | 3 +-- .../tacticalladder/functions/fnc_isLadderEmpty.sqf | 10 ++-------- addons/vector/functions/fnc_clearDisplay.sqf | 4 ++-- addons/vector/functions/fnc_dataTransfer.sqf | 4 ++-- addons/vector/functions/fnc_getFallOfShot.sqf | 10 ++++------ addons/vector/functions/fnc_getHeightDistance.sqf | 3 +-- .../functions/fnc_getRelativeAzimuthDistance.sqf | 9 +++------ addons/vector/functions/fnc_getRelativeDistance.sqf | 10 +++------- addons/vector/functions/fnc_illuminate.sqf | 4 ++-- addons/vector/functions/fnc_nextMode.sqf | 4 ++-- addons/vector/functions/fnc_onKeyDown.sqf | 2 +- addons/vehiclelock/XEH_postInit.sqf | 2 +- .../vehiclelock/functions/fnc_hasKeyForVehicle.sqf | 12 ++++-------- addons/vehiclelock/functions/fnc_lockpick.sqf | 8 ++++---- addons/vehiclelock/functions/fnc_moduleSync.sqf | 11 ++++------- .../vehiclelock/functions/fnc_onOpenInventory.sqf | 13 ++++++------- 21 files changed, 53 insertions(+), 94 deletions(-) diff --git a/addons/switchunits/functions/fnc_handleMapClick.sqf b/addons/switchunits/functions/fnc_handleMapClick.sqf index 4e8a527445..73f48c1fc0 100644 --- a/addons/switchunits/functions/fnc_handleMapClick.sqf +++ b/addons/switchunits/functions/fnc_handleMapClick.sqf @@ -21,16 +21,11 @@ params ["_faction", "_pos"]; _faction params ["", "_sides"]; -private _sideNearest = []; +private _nearestObjects = nearestObjects [_pos, ["Man"], 15]; -{ - if ([_x] call FUNC(isValidAi) && (side group _x in _sides)) then { - _sideNearest pushBack _x; - }; - nil -} count (nearestObjects [_pos, ["Man"], 15]); +private _nearestValidUnitIndex = _nearestObjects findIf {(side group _x in _sides) && {[_x] call FUNC(isValidAi)}}; -if (count _sideNearest > 0) then { - [_sideNearest select 0] call FUNC(switchUnit); +if (_nearestValidUnitIndex != -1) then { + [_nearestObjects select _nearestValidUnitIndex] call FUNC(switchUnit); openMap false; }; diff --git a/addons/switchunits/functions/fnc_initPlayer.sqf b/addons/switchunits/functions/fnc_initPlayer.sqf index e4d663f746..5fe6d5be6e 100644 --- a/addons/switchunits/functions/fnc_initPlayer.sqf +++ b/addons/switchunits/functions/fnc_initPlayer.sqf @@ -32,12 +32,9 @@ if (vehicle _playerUnit == _playerUnit) then { removeAllWeapons _playerUnit; removeGoggles _playerUnit; removeHeadgear _playerUnit; - removeVest _playerUnit; removeAllAssignedItems _playerUnit; - clearAllItemsFromBackpack _playerUnit; - removeBackpack _playerUnit; + removeAllContainers _playerUnit; _playerUnit linkItem "ItemMap"; - removeUniform _playerUnit; [_playerUnit, "forceWalk", "ACE_SwitchUnits", true] call EFUNC(common,statusEffect_set); diff --git a/addons/switchunits/functions/fnc_markAiOnMap.sqf b/addons/switchunits/functions/fnc_markAiOnMap.sqf index 5dc1017c48..6c2eb0b0d9 100644 --- a/addons/switchunits/functions/fnc_markAiOnMap.sqf +++ b/addons/switchunits/functions/fnc_markAiOnMap.sqf @@ -36,7 +36,7 @@ GVAR(AllMarkerNames) = []; // create markers { - if (([_x] call FUNC(isValidAi) && (side group _x in _sides)) || (_x getVariable [QGVAR(IsPlayerControlled), false])) then { + if ((_x getVariable [QGVAR(IsPlayerControlled), false]) || {(side group _x in _sides) && {[_x] call FUNC(isValidAi)}}) then { private _markerName = str _x; diff --git a/addons/switchunits/functions/fnc_nearestPlayers.sqf b/addons/switchunits/functions/fnc_nearestPlayers.sqf index 9f60c1a6b7..1d649d0843 100644 --- a/addons/switchunits/functions/fnc_nearestPlayers.sqf +++ b/addons/switchunits/functions/fnc_nearestPlayers.sqf @@ -18,12 +18,4 @@ params ["_position", "_radius"]; -private _nearestPlayers = []; - -{ - if ([_x] call EFUNC(common,isPlayer) && {alive _x}) then { - _nearestPlayers pushBack _x; - }; -} forEach (nearestObjects [_position, ["Man"], _radius]); - -_nearestPlayers + (nearestObjects [_position, ["Man"], _radius]) select {alive _x && {[_x] call EFUNC(common,isPlayer)}}; diff --git a/addons/switchunits/functions/fnc_startSwitchUnits.sqf b/addons/switchunits/functions/fnc_startSwitchUnits.sqf index 759ae3cbf4..f5cc4c1330 100644 --- a/addons/switchunits/functions/fnc_startSwitchUnits.sqf +++ b/addons/switchunits/functions/fnc_startSwitchUnits.sqf @@ -20,10 +20,10 @@ params ["_player"]; if (GVAR(EnableSwitchUnits)) then { private _sides = []; - if(GVAR(SwitchToWest)) then {_sides pushBack west;}; - if(GVAR(SwitchToEast)) then {_sides pushBack east;}; - if(GVAR(SwitchToIndependent)) then {_sides pushBack independent;}; - if(GVAR(SwitchToCivilian)) then {_sides pushBack civilian;}; + if (GVAR(SwitchToWest)) then {_sides pushBack west;}; + if (GVAR(SwitchToEast)) then {_sides pushBack east;}; + if (GVAR(SwitchToIndependent)) then {_sides pushBack independent;}; + if (GVAR(SwitchToCivilian)) then {_sides pushBack civilian;}; if (_player getVariable ["ACE_CanSwitchUnits", false]) then { [_player, _sides] call FUNC(initPlayer); diff --git a/addons/tacticalladder/functions/fnc_cancelTLdeploy.sqf b/addons/tacticalladder/functions/fnc_cancelTLdeploy.sqf index dac503a828..f8e2ce9f3a 100644 --- a/addons/tacticalladder/functions/fnc_cancelTLdeploy.sqf +++ b/addons/tacticalladder/functions/fnc_cancelTLdeploy.sqf @@ -32,8 +32,7 @@ GVAR(ladder) animate ["rotate", 0]; { GVAR(ladder) animate [_x, 0]; - true -} count __ANIMS; +} forEach __ANIMS; //Don't "optimize" this to a count. See #6607 // remove mouse buttons and hint call EFUNC(interaction,hideMouseHint); diff --git a/addons/tacticalladder/functions/fnc_isLadderEmpty.sqf b/addons/tacticalladder/functions/fnc_isLadderEmpty.sqf index 47c646ef29..5af9ecaafd 100644 --- a/addons/tacticalladder/functions/fnc_isLadderEmpty.sqf +++ b/addons/tacticalladder/functions/fnc_isLadderEmpty.sqf @@ -20,12 +20,6 @@ params ["_ladder"]; private _unitsNearLadder = nearestObjects [_ladder, ["CAManBase"], 4]; TRACE_1("Near Ladder",_unitsNearLadder); -private _ladderEmpty = true; -{ - if (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState _x >> "ACE_isLadder") == 1) exitWith { - _ladderEmpty = false; - TRACE_1("On Ladder",_x); - }; -} forEach _unitsNearLadder; +private _CfgAnimationStates = configFile >> "CfgMovesMaleSdr" >> "States"; -_ladderEmpty +(_unitsNearLadder findIf {getNumber (_CfgAnimationStates >> animationState _x >> "ACE_isLadder") == 1}) == -1 diff --git a/addons/vector/functions/fnc_clearDisplay.sqf b/addons/vector/functions/fnc_clearDisplay.sqf index b54a3f534f..8d4578a2da 100644 --- a/addons/vector/functions/fnc_clearDisplay.sqf +++ b/addons/vector/functions/fnc_clearDisplay.sqf @@ -4,13 +4,13 @@ * Clears the vectors control items. * * Arguments: - * 0: String + * 0: "azimuth" or "distance" * * Return Value: * None * * Example: - * [5] call ace_vector_fnc_clearDisplay + * ["azimuth"] call ace_vector_fnc_clearDisplay * * Public: No */ diff --git a/addons/vector/functions/fnc_dataTransfer.sqf b/addons/vector/functions/fnc_dataTransfer.sqf index a1ee95df0c..b50a823be9 100644 --- a/addons/vector/functions/fnc_dataTransfer.sqf +++ b/addons/vector/functions/fnc_dataTransfer.sqf @@ -17,7 +17,7 @@ private _distance = call FUNC(getDistance); private _direction = call FUNC(getDirection); -private _azimuth = _direction select 0; -private _inclination = _direction select 1; +_direction params ["_azimuth", "_inclination"]; + //Send Data to connected GPS [QGVAR(rangefinderData), [_distance, _azimuth, _inclination]] call CBA_fnc_localEvent; diff --git a/addons/vector/functions/fnc_getFallOfShot.sqf b/addons/vector/functions/fnc_getFallOfShot.sqf index 8ff1f38332..7fbaa6ad98 100644 --- a/addons/vector/functions/fnc_getFallOfShot.sqf +++ b/addons/vector/functions/fnc_getFallOfShot.sqf @@ -15,14 +15,12 @@ * Public: No */ -private _distanceP1 = GVAR(pData) select 0; -private _directionP1 = GVAR(pData) select 1; -private _azimuthP1 = _directionP1 select 0; -private _inclinationP1 = _directionP1 select 1; + +GVAR(pData) params ["_distanceP1", "_directionP1"]; +_directionP1 params ["_azimuthP1", "_inclinationP1"]; private _distanceP2 = call FUNC(getDistance); private _directionP2 = call FUNC(getDirection); -private _azimuthP2 = _directionP2 select 0; -private _inclinationP2 = _directionP2 select 1; +_directionP2 params ["_azimuthP2", "_inclinationP2"]; private _abscissa = _distanceP1 * sin (_azimuthP1 - _azimuthP2); private _ordinate = _distanceP1 * cos (_inclinationP1 - _inclinationP2) - _distanceP2 * cos (_azimuthP1 - _azimuthP2); diff --git a/addons/vector/functions/fnc_getHeightDistance.sqf b/addons/vector/functions/fnc_getHeightDistance.sqf index 768436677c..00bd888cdf 100644 --- a/addons/vector/functions/fnc_getHeightDistance.sqf +++ b/addons/vector/functions/fnc_getHeightDistance.sqf @@ -18,8 +18,7 @@ private _distance = call FUNC(getDistance); private _direction = call FUNC(getDirection); -private _azimuth = _direction select 0; -private _inclination = _direction select 1; +_direction params ["_azimuth", "_inclination"]; if (_distance < -999) exitWith { [-1000, -1000] // return diff --git a/addons/vector/functions/fnc_getRelativeAzimuthDistance.sqf b/addons/vector/functions/fnc_getRelativeAzimuthDistance.sqf index 2abcd8238d..33d9a07dc0 100644 --- a/addons/vector/functions/fnc_getRelativeAzimuthDistance.sqf +++ b/addons/vector/functions/fnc_getRelativeAzimuthDistance.sqf @@ -15,15 +15,12 @@ * Public: No */ -private _distanceP1 = GVAR(pData) select 0; -private _directionP1 = GVAR(pData) select 1; -private _azimuthP1 = _directionP1 select 0; -private _inclinationP1 = _directionP1 select 1; +GVAR(pData) params ["_distanceP1", "_directionP1"]; +_directionP1 params ["_azimuthP1", "_inclinationP1"]; private _distanceP2 = call FUNC(getDistance); private _directionP2 = call FUNC(getDirection); -private _azimuthP2 = _directionP2 select 0; -private _inclinationP2 = _directionP2 select 1; +_directionP2 params ["_azimuthP2", "_inclinationP2"]; private _relDirection = sqrt ((_azimuthP1 - _azimuthP2) ^ 2 + (_inclinationP1 - _inclinationP2) ^ 2); private _relDistance = sqrt (_distanceP1 ^ 2 + _distanceP2 ^ 2 - 2 * _distanceP1 * _distanceP2 * cos _relDirection); diff --git a/addons/vector/functions/fnc_getRelativeDistance.sqf b/addons/vector/functions/fnc_getRelativeDistance.sqf index 71abfda53d..bbe9ca1672 100644 --- a/addons/vector/functions/fnc_getRelativeDistance.sqf +++ b/addons/vector/functions/fnc_getRelativeDistance.sqf @@ -15,15 +15,11 @@ * Public: No */ -private _distanceP1 = GVAR(pData) select 0; -private _directionP1 = GVAR(pData) select 1; -private _azimuthP1 = _directionP1 select 0; -private _inclinationP1 = _directionP1 select 1; - +GVAR(pData) params ["_distanceP1", "_directionP1"]; +_directionP1 params ["_azimuthP1", "_inclinationP1"]; private _distanceP2 = call FUNC(getDistance); private _directionP2 = call FUNC(getDirection); -private _azimuthP2 = _directionP2 select 0; -private _inclinationP2 = _directionP2 select 1; +_directionP2 params ["_azimuthP2", "_inclinationP2"]; private _relDirection = sqrt ((_azimuthP1 - _azimuthP2) ^ 2 + (_inclinationP1 - _inclinationP2) ^ 2); diff --git a/addons/vector/functions/fnc_illuminate.sqf b/addons/vector/functions/fnc_illuminate.sqf index 18535d2861..999fc5c29a 100644 --- a/addons/vector/functions/fnc_illuminate.sqf +++ b/addons/vector/functions/fnc_illuminate.sqf @@ -4,13 +4,13 @@ * * * Arguments: - * 0: String + * 0: Enable illumination * * Return Value: * None * * Example: - * ["5"] call ace_vector_fnc_illuminate + * [true] call ace_vector_fnc_illuminate * * Public: No */ diff --git a/addons/vector/functions/fnc_nextMode.sqf b/addons/vector/functions/fnc_nextMode.sqf index 74250ca1f2..cd00b4977d 100644 --- a/addons/vector/functions/fnc_nextMode.sqf +++ b/addons/vector/functions/fnc_nextMode.sqf @@ -4,13 +4,13 @@ * * * Arguments: - * 0: String + * 0: Name of mode ("settings", "config") * * Return Value: * Array * * Example: - * ["5"] call ace_vector_fnc_nextMode + * ["settings"] call ace_vector_fnc_nextMode * * Public: No */ diff --git a/addons/vector/functions/fnc_onKeyDown.sqf b/addons/vector/functions/fnc_onKeyDown.sqf index 6a58ff96fc..a9c6b90b2d 100644 --- a/addons/vector/functions/fnc_onKeyDown.sqf +++ b/addons/vector/functions/fnc_onKeyDown.sqf @@ -10,7 +10,7 @@ * None * * Example: - * ["5"] call ace_vector_fnc_onKeyDown + * ["azimuth"] call ace_vector_fnc_onKeyDown * * Public: No */ diff --git a/addons/vehiclelock/XEH_postInit.sqf b/addons/vehiclelock/XEH_postInit.sqf index 3888a6e87a..a50168dd92 100644 --- a/addons/vehiclelock/XEH_postInit.sqf +++ b/addons/vehiclelock/XEH_postInit.sqf @@ -10,6 +10,6 @@ if (!hasInterface) exitwith {}; TRACE_1("SettingsInitialized eh",GVAR(LockVehicleInventory)); if (GVAR(LockVehicleInventory)) then { - ["CAManBase", "InventoryOpened", {_this call FUNC(onOpenInventory);}] call CBA_fnc_addClassEventHandler; + ["CAManBase", "InventoryOpened", {_this call FUNC(onOpenInventory)}] call CBA_fnc_addClassEventHandler; }; }] call CBA_fnc_addEventHandler; diff --git a/addons/vehiclelock/functions/fnc_hasKeyForVehicle.sqf b/addons/vehiclelock/functions/fnc_hasKeyForVehicle.sqf index 149ece1f95..bda8f67b65 100644 --- a/addons/vehiclelock/functions/fnc_hasKeyForVehicle.sqf +++ b/addons/vehiclelock/functions/fnc_hasKeyForVehicle.sqf @@ -22,20 +22,16 @@ TRACE_2("params",_unit,_veh); if (isNull _unit) exitWith {ERROR("null unit"); false}; if (isNull _veh) exitWith {ERROR("null vehicle"); false}; -private _returnValue = false; - //Master can open anything "no matter what" private _items = _unit call EFUNC(common,uniqueItems); -if ("ACE_key_master" in _items) then {_returnValue = true}; +if ("ACE_key_master" in _items) exitWith {true}; //Check side key private _sideKeyName = [_veh] call FUNC(getVehicleSideKey); -if (_sideKeyName in _items) then {_returnValue = true}; +if (_sideKeyName in _items) exitWith {true}; //Check custom keys private _customKeys = _veh getVariable [QGVAR(customKeys), []]; -{ - if (_x in (magazinesDetail _unit)) then {_returnValue = true;}; -} forEach _customKeys; +private _magazines = magazinesDetail _unit; -_returnValue +(_customKeys findIf {_x in _magazines}) != -1 diff --git a/addons/vehiclelock/functions/fnc_lockpick.sqf b/addons/vehiclelock/functions/fnc_lockpick.sqf index 66ed89fa6f..f106216c89 100644 --- a/addons/vehiclelock/functions/fnc_lockpick.sqf +++ b/addons/vehiclelock/functions/fnc_lockpick.sqf @@ -32,11 +32,11 @@ if ((locked _veh) == 0) exitWith {false}; //need lockpick item if !("ACE_key_lockpick" in (_unit call EFUNC(common,uniqueItems))) exitWith {false}; -private _vehLockpickStrenth = _veh getVariable[QGVAR(lockpickStrength), GVAR(DefaultLockpickStrength)]; -if (!(_vehLockpickStrenth isEqualType 0)) exitWith {ERROR("ACE_vehicleLock_LockpickStrength invalid"); false}; +private _vehLockpickStrength = _veh getVariable[QGVAR(lockpickStrength), GVAR(DefaultLockpickStrength)]; +if (!(_vehLockpickStrength isEqualType 0)) exitWith {ERROR("ACE_vehicleLock_LockpickStrength invalid"); false}; //-1 indicates unpickable lock -if (_vehLockpickStrenth < 0) exitWith {false}; +if (_vehLockpickStrength < 0) exitWith {false}; //Condition check for progressBar private _condition = { @@ -53,7 +53,7 @@ switch (_funcType) do { _returnValue = !([_unit, _veh] call FUNC(hasKeyForVehicle)) && {(locked _veh) in [2, 3]}; }; case "startLockpick": { - [_vehLockpickStrenth, [_unit, _veh, "finishLockpick"], {(_this select 0) call FUNC(lockpick)}, {}, (localize LSTRING(Action_LockpickInUse)), _condition, ["isNotInside", "isNotSwimming"]] call EFUNC(common,progressBar); + [_vehLockpickStrength, [_unit, _veh, "finishLockpick"], {(_this select 0) call FUNC(lockpick)}, {}, (localize LSTRING(Action_LockpickInUse)), _condition, ["isNotInside", "isNotSwimming"]] call EFUNC(common,progressBar); }; case "finishLockpick": { [QGVAR(setVehicleLock), [_veh, false], [_veh]] call CBA_fnc_targetEvent; diff --git a/addons/vehiclelock/functions/fnc_moduleSync.sqf b/addons/vehiclelock/functions/fnc_moduleSync.sqf index f65ad5399d..75fef647d1 100644 --- a/addons/vehiclelock/functions/fnc_moduleSync.sqf +++ b/addons/vehiclelock/functions/fnc_moduleSync.sqf @@ -27,14 +27,11 @@ if !(_activated) exitWith {WARNING("Vehicle Lock Sync Module - placed but not ac [{ params ["_syncedObjects"]; - private _listOfVehicles = []; - { - if ((_x isKindOf "Car") || (_x isKindOf "Tank") || (_x isKindOf "Helicopter")) then { - _listOfVehicles pushBack _x; - }; - } forEach _syncedObjects; + private _listOfVehicles = _syncedObjects select { + (_x isKindOf "Car") || {(_x isKindOf "Tank") || {_x isKindOf "Helicopter"}} + }; - if ((count _listOfVehicles) == 0) exitWith { //Verbose error for mission makers (only shows on server) + if (_listOfVehicles isEqualTo []) exitWith { //Verbose error for mission makers (only shows on server) ["ACE_VehicleLock_fnc_moduleSync: no vehicles synced"] call BIS_fnc_error; }; diff --git a/addons/vehiclelock/functions/fnc_onOpenInventory.sqf b/addons/vehiclelock/functions/fnc_onOpenInventory.sqf index 836cccc21d..92cbe0144d 100644 --- a/addons/vehiclelock/functions/fnc_onOpenInventory.sqf +++ b/addons/vehiclelock/functions/fnc_onOpenInventory.sqf @@ -20,13 +20,13 @@ params ["_unit", "_container"]; TRACE_2("params",_unit,_container); //Only check for player: -if (_unit != ace_player) exitWith {}; +if (_unit != ACE_player) exitWith {}; if (GVAR(LockVehicleInventory) && //if setting not enabled - {(vehicle ace_player) == ace_player} && //Player dismounted - {(_container isKindOf "Car") || (_container isKindOf "Tank") || (_container isKindOf "Helicopter")} && //container is a lockable veh + {(vehicle ACE_player) == ACE_player} && //Player dismounted + {(_container isKindOf "Car") || {(_container isKindOf "Tank") || {_container isKindOf "Helicopter"}}} && //container is a lockable veh {(locked _container) in [2,3]} && //Vehicle is locked - {!([ace_player, _container] call FUNC(hasKeyForVehicle))} //player doesn't have key + {!([ACE_player, _container] call FUNC(hasKeyForVehicle))} //player doesn't have key ) then { //Give feedback that vehicle is locked playSound "ACE_Sound_Click"; @@ -41,8 +41,7 @@ if (GVAR(LockVehicleInventory) && //if setting not enabled (findDisplay 602) closeDisplay 0; [{ TRACE_1("Opening Player Inventory", _this); - ACE_player action ["Gear", objNull] + ACE_player action ["Gear", objNull]; }, []] call CBA_fnc_execNextFrame; - }, - []] call CBA_fnc_waitUntilAndExecute; + }, []] call CBA_fnc_waitUntilAndExecute; };