From 6b96c7fd7c3cb6e47bed7f6a460661bbe7f370e0 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 19 Sep 2015 22:27:23 +0200 Subject: [PATCH] more common code cleanup --- addons/common/functions/fnc_hasItem.sqf | 25 ++++++----- addons/common/functions/fnc_hasMagazine.sqf | 30 ++++++-------- addons/common/functions/fnc_headBugFix.sqf | 2 +- .../common/functions/fnc_inTransitionAnim.sqf | 2 +- addons/common/functions/fnc_inheritsFrom.sqf | 41 ++++++++++++------- addons/common/functions/fnc_insertionSort.sqf | 38 +++++++++-------- .../functions/fnc_interpolateFromArray.sqf | 20 +++++++-- addons/common/functions/fnc_isAutoWind.sqf | 13 +++--- addons/common/functions/fnc_isAwake.sqf | 23 ++++++----- addons/common/functions/fnc_isEOD.sqf | 2 +- addons/common/functions/fnc_isEngineer.sqf | 2 +- .../functions/fnc_isFeatureCameraActive.sqf | 5 +-- addons/common/functions/fnc_isModLoaded.sqf | 3 +- addons/common/functions/fnc_isPlayer.sqf | 2 +- 14 files changed, 119 insertions(+), 89 deletions(-) diff --git a/addons/common/functions/fnc_hasItem.sqf b/addons/common/functions/fnc_hasItem.sqf index 00c5ed5846..526f5a46f2 100644 --- a/addons/common/functions/fnc_hasItem.sqf +++ b/addons/common/functions/fnc_hasItem.sqf @@ -1,13 +1,18 @@ -/** - * fn_hasItem.sqf - * @Descr: Check if unit has item - * @Author: Glowbal +/* + * Author: Glowbal + * Check if unit has item * - * @Arguments: [unit OBJECT, item STRING (Classname of item)] - * @Return: BOOL - * @PublicAPI: true + * Arguments: + * 0: Unit + * 1: Item Classname + * + * Return Value: + * has Item + * + * Public: yes */ - #include "script_component.hpp" +#include "script_component.hpp" -// item classname in items unit -((_this select 1) in items (_this select 0)); \ No newline at end of file +params ["_unit", "_item"]; + +_item in items _unit // return diff --git a/addons/common/functions/fnc_hasMagazine.sqf b/addons/common/functions/fnc_hasMagazine.sqf index 52a5ed4cd5..27150ea5d5 100644 --- a/addons/common/functions/fnc_hasMagazine.sqf +++ b/addons/common/functions/fnc_hasMagazine.sqf @@ -1,22 +1,18 @@ -/** - * fn_hasMagazine.sqf - * @Descr: Check if given unit has a magazine of given classname - * @Author: Glowbal +/* + * Author: Glowbal + * Check if given unit has a magazine of given classname * - * @Arguments: [unit OBJECT, magazine STRING] - * @Return: BOOL True if unith as given magazine - * @PublicAPI: true + * Arguments: + * 0: Unit + * 1: Magazine Classname + * + * Return Value: + * has Magazine + * + * Public: yes */ - #include "script_component.hpp" -private ["_return"]; -PARAMS_2(_unit,_magazine); +params ["_unit", "_magazine"]; -if (_magazine != "") then { - _return = (_magazine in magazines _unit); -} else { - _return = false; -}; - -_return \ No newline at end of file +_magazine in magazines _unit // return diff --git a/addons/common/functions/fnc_headBugFix.sqf b/addons/common/functions/fnc_headBugFix.sqf index 0c02b9397a..78b1a602df 100644 --- a/addons/common/functions/fnc_headBugFix.sqf +++ b/addons/common/functions/fnc_headBugFix.sqf @@ -34,7 +34,7 @@ titleCut ["", "BLACK"]; _dummy = createVehicle ["ACE_Headbug_Fix", _pos, [], 0, "NONE"]; _dummy setDir _dir; _unit moveInAny _dummy; -sleep 0.1; +sleep 0.1; // @todo unassignVehicle _unit; _unit action ["Eject", vehicle _unit]; diff --git a/addons/common/functions/fnc_inTransitionAnim.sqf b/addons/common/functions/fnc_inTransitionAnim.sqf index 34c6c04fd8..fd90291d73 100644 --- a/addons/common/functions/fnc_inTransitionAnim.sqf +++ b/addons/common/functions/fnc_inTransitionAnim.sqf @@ -12,4 +12,4 @@ */ #include "script_component.hpp" -getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState (_this select 0) >> "looped") == 0 +getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> animationState (_this select 0) >> "looped") == 0 // return diff --git a/addons/common/functions/fnc_inheritsFrom.sqf b/addons/common/functions/fnc_inheritsFrom.sqf index 27d84b9d12..586a37847c 100644 --- a/addons/common/functions/fnc_inheritsFrom.sqf +++ b/addons/common/functions/fnc_inheritsFrom.sqf @@ -1,25 +1,36 @@ -/** - * fn_inheritsFrom.sqf - * @Descr: Checks whether a given configuration name appears in the inheritance tree of a specific configuration entry. - * @Author: Ruthberg +/* + * Author: Ruthberg + * Checks whether a given configuration name appears in the inheritance tree of a specific configuration entry. * - * @Arguments: [configEntry CONFIG, configname STRING] - * @Return: BOOL - * @PublicAPI: true + * Arguments: + * 0: configEntry (CONFIG) + * 1: configname (STING) + * + * Return Value: + * BOOLEAN + * + * Public: Yes + * + * Note: Not to be confused with the inheritsFrom scripting command. + * + * Deprecated */ - #include "script_component.hpp" - private ["_match"]; -PARAMS_2(_configEntry,_configMatch); +params ["_configEntry", "_configMatch"]; -if (configName _configEntry == _configMatch) exitWith { true }; -if (configName _configEntry == ",") exitWith { false }; +if (configName _configEntry == _configMatch) exitWith {true}; +if (configName _configEntry == ",") exitWith {false}; +private "_match"; _match = false; + while {configName _configEntry != ""} do { - if (configName _configEntry == _configMatch) exitWith { _match = true }; - _configEntry = inheritsFrom(_configEntry); + if (configName _configEntry == _configMatch) exitWith { + _match = true; + }; + + _configEntry = inheritsFrom _configEntry; }; -_match \ No newline at end of file +_match diff --git a/addons/common/functions/fnc_insertionSort.sqf b/addons/common/functions/fnc_insertionSort.sqf index bdafa70592..9f8c95e095 100644 --- a/addons/common/functions/fnc_insertionSort.sqf +++ b/addons/common/functions/fnc_insertionSort.sqf @@ -1,34 +1,38 @@ -/** - * fn_insertionSort.sqf - * @Descr: Sorts an array of numbers - * @Author: Ruthberg +/* + * Author: Ruthberg + * Sorts an array of numbers * - * @Arguments: [array ARRAY, (optional) ascending BOOL] - * @Return: sortedArray ARRAY - * @PublicAPI: true + * Arguments: + * 0: array + * 1: ascending (optional) + * + * Return Value: + * sortedArray (ARRAY) + * + * Public: Yes */ - #include "script_component.hpp" -private ["_list", "_ascending", "_tmp", "_i", "_j"]; -_list = +(_this select 0); -_ascending = true; -if (count _this > 1) then { - _ascending = _this select 1; -}; +params ["_list", ["_ascending", true]]; -for "_i" from 1 to (count _list) - 1 do { +_list = + _list; // copy array to not alter the original one + +private "_tmp"; + +for "_i" from 1 to (count _list - 1) do { _tmp = _list select _i; _j = _i; + while {_j >= 1 && {_tmp < _list select (_j - 1)}} do { _list set [_j, _list select (_j - 1)]; _j = _j - 1; }; - _list set[_j, _tmp]; + + _list set [_j, _tmp]; }; if (!_ascending) then { reverse _list; }; -_list \ No newline at end of file +_list diff --git a/addons/common/functions/fnc_interpolateFromArray.sqf b/addons/common/functions/fnc_interpolateFromArray.sqf index 2427fa47b5..5ce59bde62 100644 --- a/addons/common/functions/fnc_interpolateFromArray.sqf +++ b/addons/common/functions/fnc_interpolateFromArray.sqf @@ -1,11 +1,23 @@ -// by commy2 +/* + * Author: commy2 + * Interpolates between two set points in a curve. + * + * Arguments: + * 0: List of numbers to interpolate from + * 1: Value / index + * + * Return Value: + * Interpolation result + * + * Public: Yes + */ #include "script_component.hpp" -private ["_min", "_max"]; +params ["_array", "_value"]; -PARAMS_2(_array,_value); +private ["_min", "_max"]; _min = _array select floor _value; _max = _array select ceil _value; -_min + (_max - _min) * (_value % 1) +_min + (_max - _min) * (_value % 1) // return diff --git a/addons/common/functions/fnc_isAutoWind.sqf b/addons/common/functions/fnc_isAutoWind.sqf index 50933e40a2..04bb22a785 100644 --- a/addons/common/functions/fnc_isAutoWind.sqf +++ b/addons/common/functions/fnc_isAutoWind.sqf @@ -1,14 +1,15 @@ /* * Author: commy2 - * * Check if wind is set on auto. * - * Argument: - * None. + * Arguments + * None * - * Return value: - * This mission has automatic wind? (Bool) + * Return Value: + * This mission has automatic wind? + * + * Public: Yes */ #include "script_component.hpp" -["Mission", "Intel", "windForced"] call FUNC(getNumberFromMissionSQM) != 1 +["Mission", "Intel", "windForced"] call FUNC(getNumberFromMissionSQM) != 1 // return diff --git a/addons/common/functions/fnc_isAwake.sqf b/addons/common/functions/fnc_isAwake.sqf index c0dd59288e..f640eaa012 100644 --- a/addons/common/functions/fnc_isAwake.sqf +++ b/addons/common/functions/fnc_isAwake.sqf @@ -1,15 +1,18 @@ -/** - * fn_isAwake.sqf - * @Descr: Check if unit is awake. Will be false when death or unit is unconscious. - * @Author: Glowbal +/* + * Author: Glowbal * - * @Arguments: [unit OBJECT] - * @Return: BOOL True if unit is awake - * @PublicAPI: true + * Check if unit is awake. Will be false when death or unit is unconscious. + * + * Arguments: + * 0: Unit + * + * Return Value: + * if unit is awake + * + * Public: Yes */ - #include "script_component.hpp" -PARAMS_1(_unit); +params ["_unit"]; -(!(_unit getvariable ["ACE_isUnconscious",false]) && alive _unit && !(_unit getvariable ["ACE_isDead",false])); +!(_unit getvariable ["ACE_isUnconscious", false]) && alive _unit && !(_unit getvariable ["ACE_isDead", false]); diff --git a/addons/common/functions/fnc_isEOD.sqf b/addons/common/functions/fnc_isEOD.sqf index 6e331ea317..ee82cf2068 100644 --- a/addons/common/functions/fnc_isEOD.sqf +++ b/addons/common/functions/fnc_isEOD.sqf @@ -20,4 +20,4 @@ params ["_unit"]; -_unit getVariable ["ACE_isEOD", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "canDeactivateMines") == 1] +_unit getVariable ["ACE_isEOD", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "canDeactivateMines") == 1] // return diff --git a/addons/common/functions/fnc_isEngineer.sqf b/addons/common/functions/fnc_isEngineer.sqf index 419fb5396d..9018149c27 100644 --- a/addons/common/functions/fnc_isEngineer.sqf +++ b/addons/common/functions/fnc_isEngineer.sqf @@ -14,4 +14,4 @@ params ["_unit"]; -_unit getVariable ["ACE_isEngineer", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "engineer") == 1] +_unit getVariable ["ACE_isEngineer", getNumber (configFile >> "CfgVehicles" >> typeOf _unit >> "engineer") == 1] // return diff --git a/addons/common/functions/fnc_isFeatureCameraActive.sqf b/addons/common/functions/fnc_isFeatureCameraActive.sqf index 0b91b19e55..7d282109b2 100644 --- a/addons/common/functions/fnc_isFeatureCameraActive.sqf +++ b/addons/common/functions/fnc_isFeatureCameraActive.sqf @@ -19,9 +19,8 @@ * Example: * [] call ace_common_fnc_isFeatureCameraActive * - * Public: No + * Public: Yes */ - #include "script_component.hpp" !( @@ -32,4 +31,4 @@ {isNull (GETMVAR(BIS_fnc_camera_cam, objNull))} && // Splendid camera {isNull (GETUVAR(BIS_fnc_animViewer_cam, objNull))} && // Animation viewer camera {isNull (GETMVAR(BIS_DEBUG_CAM, objNull))} // Classic camera -) +) // return diff --git a/addons/common/functions/fnc_isModLoaded.sqf b/addons/common/functions/fnc_isModLoaded.sqf index bfdf38f49c..3628777f6c 100644 --- a/addons/common/functions/fnc_isModLoaded.sqf +++ b/addons/common/functions/fnc_isModLoaded.sqf @@ -10,7 +10,6 @@ * * Public: Yes */ - #include "script_component.hpp" -isClass (configFile >> "cfgPatches" >> _this select 0) +isClass (configFile >> "cfgPatches" >> _this select 0) // return diff --git a/addons/common/functions/fnc_isPlayer.sqf b/addons/common/functions/fnc_isPlayer.sqf index ac7d5bd786..8bea7e9771 100644 --- a/addons/common/functions/fnc_isPlayer.sqf +++ b/addons/common/functions/fnc_isPlayer.sqf @@ -16,4 +16,4 @@ params ["_unit", ["_excludeRemoteControlled", false]]; -isPlayer _unit || (!_excludeRemoteControlled && {_unit == call FUNC(player)}) +isPlayer _unit || (!_excludeRemoteControlled && {_unit == call FUNC(player)}) // return