From a98a45e5d161d73535905bfb8e53b1db0bd7197b Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 20 Sep 2015 23:18:51 +0200 Subject: [PATCH] more common code cleanup --- addons/common/functions/fnc_getAllGear.sqf | 42 ++++++++++++------- .../functions/fnc_getCaptivityStatus.sqf | 16 +++---- addons/common/functions/fnc_getChildren.sqf | 22 +++++++--- .../functions/fnc_getConfigCommander.sqf | 17 ++++---- .../common/functions/fnc_getConfigGunner.sqf | 17 ++++---- addons/common/functions/fnc_getConfigType.sqf | 13 +++--- .../functions/fnc_getConfigTypeObject.sqf | 13 +++--- addons/common/functions/fnc_getGunner.sqf | 26 ++++++------ .../functions/fnc_getTurretCommander.sqf | 30 +++++++------ .../common/functions/fnc_getTurretCopilot.sqf | 19 +++++---- .../common/functions/fnc_getTurretGunner.sqf | 19 +++++---- addons/common/functions/fnc_getTurretsFFV.sqf | 20 +++++---- .../common/functions/fnc_getTurretsOther.sqf | 20 +++++---- 13 files changed, 159 insertions(+), 115 deletions(-) diff --git a/addons/common/functions/fnc_getAllGear.sqf b/addons/common/functions/fnc_getAllGear.sqf index aa2289309e..97b28fddd6 100644 --- a/addons/common/functions/fnc_getAllGear.sqf +++ b/addons/common/functions/fnc_getAllGear.sqf @@ -1,28 +1,38 @@ /* * Author: bux578, commy2 - * * Returns an array containing all items of a given unit * - * Argument: - * 0: Unit (Object) + * Arguments: + * 0: Unit * - * Return value: - * Array with all the gear, format: - * 0: headgear (String) - * 1: goggles (String) - * 2,3: uniform (String, Array) - * 4,5: vest (String, Array) - * 6,7: backpack (String, Array) - * 8-10: rifle (String, Array, Array) - * 11-13: launcher (String, Array, Array) - * 14-16: pistol (String, Array, Array) - * 17: map, compass, watch, etc. (Array) - * 18: binocluar (String) + * Return Value: + * 0: Headgear + * 1: Goggles + * 2: Uniform + * 3: Uniform Items + * 4: Vest + * 5: Vest Items + * 6: Backback + * 7: Backpack Items + * 8: Rifle + * 9: Rifle Items + * 10: Rifle Magazines + * 11: Launcher + * 12: Launcher Items + * 13: Launcher Magazines + * 14: Handgun + * 15: Handgun Items + * 16: Handgun Magazines + * 17: Assigned Items (map, compass, watch, etc.) + * 18: Binoculars * + * Public: Yes + * + * Note: Element 17 includes the Head Mounted Display (HMD) */ #include "script_component.hpp" -PARAMS_1(_unit); +params ["_unit"]; if (isNull _unit) exitWith {[ "", diff --git a/addons/common/functions/fnc_getCaptivityStatus.sqf b/addons/common/functions/fnc_getCaptivityStatus.sqf index 50aeeced3a..36bf0ff183 100644 --- a/addons/common/functions/fnc_getCaptivityStatus.sqf +++ b/addons/common/functions/fnc_getCaptivityStatus.sqf @@ -1,25 +1,27 @@ /* * Author: commy2 - * * Return the captivity status of an unit. * - * Argument: - * 0: Unit (Object) + * Arguments: + * 0: Unit * - * Return value: - * Reasons, why the unit is a captive. An empty array is returned if the unit is not a captive (Array of Strings) + * Return Value: + * Captivity Reasons, empty if not captive + * + * Public: Yes */ #include "script_component.hpp" -private ["_captivityReasons", "_unitCaptivityStatus", "_unitCaptivityReasons"]; +params ["_unit"]; -PARAMS_1(_unit); +private ["_captivityReasons", "_unitCaptivityStatus", "_unitCaptivityReasons"]; _captivityReasons = missionNamespace getVariable ["ACE_captivityReasons", []]; _unitCaptivityStatus = [captiveNum _unit, count _captivityReasons] call FUNC(binarizeNumber); _unitCaptivityReasons = []; + { if (_unitCaptivityStatus select _forEachIndex) then { _unitCaptivityReasons pushBack _x; diff --git a/addons/common/functions/fnc_getChildren.sqf b/addons/common/functions/fnc_getChildren.sqf index d28ba7cb70..d5212dd9a5 100644 --- a/addons/common/functions/fnc_getChildren.sqf +++ b/addons/common/functions/fnc_getChildren.sqf @@ -1,10 +1,20 @@ -// by commy2 +/* + * Author: commy2 + * Obtain children of a config entry + * + * Arguments: + * 0: Unit + * + * Return Value: + * Parent Entry Class Children + * + * Public: Yes + */ #include "script_component.hpp" -private ["_classes"]; - -PARAMS_2(_name,_cfgClass); +params ["_name", "_cfgClass"]; +private "_classes"; _classes = format ["configName inheritsFrom _x == '%1'", _name] configClasses (configFile >> _cfgClass); -_classes = [_classes, {configName _this}] call FUNC(map); -_classes + +[_classes, {configName _this}] call FUNC(map) // return diff --git a/addons/common/functions/fnc_getConfigCommander.sqf b/addons/common/functions/fnc_getConfigCommander.sqf index 44f02cbeb1..bfa5fbc379 100644 --- a/addons/common/functions/fnc_getConfigCommander.sqf +++ b/addons/common/functions/fnc_getConfigCommander.sqf @@ -1,21 +1,22 @@ /* * Author: commy2 - * * Get the commander config of a vehicles turret. * - * Argument: - * 0: vehicle (Object) + * Arguments: + * 0: vehicle * - * Return value: - * Commander config (Config) + * Return Value: + * Commander config + * + * Public: Yes */ #include "script_component.hpp" -private ["_config", "_turret"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_config", "_turret"]; _config = configFile >> "CfgVehicles" >> typeOf _vehicle; _turret = [_vehicle] call FUNC(getTurretCommander); -[_config, _turret] call FUNC(getTurretConfigPath) +[_config, _turret] call FUNC(getTurretConfigPath) // return diff --git a/addons/common/functions/fnc_getConfigGunner.sqf b/addons/common/functions/fnc_getConfigGunner.sqf index a28491bfff..bc3131d798 100644 --- a/addons/common/functions/fnc_getConfigGunner.sqf +++ b/addons/common/functions/fnc_getConfigGunner.sqf @@ -1,21 +1,22 @@ /* * Author: commy2 - * * Get the gunner config of a vehicles turret. * - * Argument: - * 0: vehicle (Object) + * Arguments: + * 0: vehicle * - * Return value: - * Gunner config (Config) + * Return Value: + * Gunner config + * + * Public: Yes */ #include "script_component.hpp" -private ["_config", "_turret"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_config", "_turret"]; _config = configFile >> "CfgVehicles" >> typeOf _vehicle; _turret = [_vehicle] call FUNC(getTurretGunner); -[_config, _turret] call FUNC(getTurretConfigPath) +[_config, _turret] call FUNC(getTurretConfigPath) // return diff --git a/addons/common/functions/fnc_getConfigType.sqf b/addons/common/functions/fnc_getConfigType.sqf index b2d601c121..1496cfa2b9 100644 --- a/addons/common/functions/fnc_getConfigType.sqf +++ b/addons/common/functions/fnc_getConfigType.sqf @@ -1,17 +1,18 @@ /* * Author: commy2 + * Determins type of item. Can be CfgMagaines, CfgWeapons or CfgGlasses. * - * What kind of Cfg is the item. Works for CfgMagaines, CfgWeapons and CfgGlasses + * Arguments: + * 0: Item Classname * - * Argument: - * 0: A item's classname. (String) + * Return Value: + * Config category ("CfgWeapons", "CfgMagazines", "CfgGlasses", "") * - * Return value: - * CfgWhatever (String) + * Public: Yes */ #include "script_component.hpp" -PARAMS_1(_item); +params ["_item"]; if (isClass (configFile >> "CfgWeapons" >> _item)) exitWith {"CfgWeapons"}; diff --git a/addons/common/functions/fnc_getConfigTypeObject.sqf b/addons/common/functions/fnc_getConfigTypeObject.sqf index ef39ce22c7..6186ad6bff 100644 --- a/addons/common/functions/fnc_getConfigTypeObject.sqf +++ b/addons/common/functions/fnc_getConfigTypeObject.sqf @@ -1,17 +1,18 @@ /* * Author: commy2 + * Determins type of object. Can be CfgVehicles or CfgAmmo. * - * What kind of Cfg is the object. Works for CfgVehicles and CfgAmmo + * Arguments: + * 0: Object classname * - * Argument: - * 0: An object's classname. (String) + * Return Value: + * Config category ("CfgWeapons", "Cfgmagazines", "CfgGlasses", "") * - * Return value: - * CfgWhatever (String) + * Public: Yes */ #include "script_component.hpp" -PARAMS_1(_object); +params ["_object"]; if (isClass (configFile >> "CfgVehicles" >> _object)) exitWith {"CfgVehicles"}; diff --git a/addons/common/functions/fnc_getGunner.sqf b/addons/common/functions/fnc_getGunner.sqf index ce73019f70..dac42ce535 100644 --- a/addons/common/functions/fnc_getGunner.sqf +++ b/addons/common/functions/fnc_getGunner.sqf @@ -1,20 +1,19 @@ /* * Author: commy2 + * Returns gunner using specified weapon type in vehicle. Only works if all turrets have different weapons. * - * Get the gunner of a vehicle who uses the given weapon type. Requires every turret to have a different weapon. + * Arguments: + * 0: Vehicle + * 1: Weapon * - * Argument: - * 0: The vehicle (Object) - * 1: weapon of the vehicle (String) + * Return Value: + * Gunner * - * Return value: - * The turret gunner with this weapon (Object) + * Public: Yes */ +#include "script_component.hpp" -private ["_vehicle", "_weapon"]; - -_vehicle = _this select 0; -_weapon = _this select 1; +params ["_vehicle", "_weapon"]; // on foot if (gunner _vehicle == _vehicle && {_weapon in weapons _vehicle || {toLower _weapon in ["throw", "put"]}}) exitWith {gunner _vehicle}; @@ -27,11 +26,12 @@ _gunner = objNull; if (_weapon in (_vehicle weaponsTurret _x)) exitWith { _gunner = _vehicle turretUnit _x; }; -} forEach allTurrets [_vehicle, true]; + false +} count allTurrets [_vehicle, true]; // ensure that at least the pilot is returned if there is no gunner if (isManualFire _vehicle && {isNull _gunner}) then { - _gunner = driver _vehicle; + _gunner = driver _vehicle; }; -_gunner \ No newline at end of file +_gunner diff --git a/addons/common/functions/fnc_getTurretCommander.sqf b/addons/common/functions/fnc_getTurretCommander.sqf index 99665d03e3..e045c2d46f 100644 --- a/addons/common/functions/fnc_getTurretCommander.sqf +++ b/addons/common/functions/fnc_getTurretCommander.sqf @@ -1,30 +1,34 @@ /* * Author: commy2 - * * Get the turret index of a vehicles commander. * - * Argument: - * 0: Vehicle (Object) + * Arguments: + * 0: Vehicle * - * Return value: - * Turret index of the vehicles commander. Empty array means no observer position. (Array) + * Return Value: + * Vehicle commander turrent indecies + * + * Public: Yes */ #include "script_component.hpp" -private ["_turrets", "_turret", "_config"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_turrets", "_turret", "_config"]; _turrets = allTurrets [_vehicle, true]; _turret = []; + { - _config = configFile >> "CfgVehicles" >> typeOf _vehicle; + _config = configFile >> "CfgVehicles" >> typeOf _vehicle; - _config = [_config, _x] call FUNC(getTurretConfigPath); + _config = [_config, _x] call FUNC(getTurretConfigPath); + + if (getNumber (_config >> "primaryObserver") == 1) exitWith { + _turret = _x; + }; + false +} count _turrets; - if (getNumber (_config >> "primaryObserver") == 1) exitWith { - _turret = _x; - }; -} forEach _turrets; _turret diff --git a/addons/common/functions/fnc_getTurretCopilot.sqf b/addons/common/functions/fnc_getTurretCopilot.sqf index d496051558..94a30b7697 100644 --- a/addons/common/functions/fnc_getTurretCopilot.sqf +++ b/addons/common/functions/fnc_getTurretCopilot.sqf @@ -1,23 +1,25 @@ /* * Author: commy2 - * * Get the turret index of a vehicles copilot. * - * Argument: - * 0: Vehicle (Object) + * Arguments: + * 0: Vehicle * - * Return value: - * Turret index of the vehicles gunner. Empty array means no copilot position. (Array) + * Return Value: + * Vehicle Copilot Turret indecies + * + * Public: Yes */ #include "script_component.hpp" -private ["_turrets", "_turret", "_config"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_turrets", "_turret", "_config"]; _turrets = allTurrets [_vehicle, true]; _turret = []; + { _config = configFile >> "CfgVehicles" >> typeOf _vehicle; @@ -26,6 +28,7 @@ _turret = []; if (getNumber (_config >> "isCopilot") == 1 && {getNumber (_config >> "primaryGunner") != 1} && {getNumber (_config >> "primaryObserver") != 1}) exitWith { _turret = _x; }; -} forEach _turrets; + false +} count _turrets; _turret diff --git a/addons/common/functions/fnc_getTurretGunner.sqf b/addons/common/functions/fnc_getTurretGunner.sqf index a4bcca54dd..9a71d292bd 100644 --- a/addons/common/functions/fnc_getTurretGunner.sqf +++ b/addons/common/functions/fnc_getTurretGunner.sqf @@ -1,23 +1,25 @@ /* * Author: commy2 - * * Get the turret index of a vehicles gunner. * - * Argument: - * 0: Vehicle (Object) + * Arguments: + * 0: Vehicle * - * Return value: - * Turret index of the vehicles gunner. Empty array means no gunner position. (Array) + * Return Value: + * Vehicle Gunner Turret indecies + * + * Public: Yes */ #include "script_component.hpp" -private ["_turrets", "_turret", "_config"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_turrets", "_turret", "_config"]; _turrets = allTurrets [_vehicle, true]; _turret = []; + { _config = configFile >> "CfgVehicles" >> typeOf _vehicle; @@ -26,6 +28,7 @@ _turret = []; if (getNumber (_config >> "primaryGunner") == 1) exitWith { _turret = _x; }; -} forEach _turrets; + false +} count _turrets; _turret diff --git a/addons/common/functions/fnc_getTurretsFFV.sqf b/addons/common/functions/fnc_getTurretsFFV.sqf index 2eaa8807b0..ff7726d1be 100644 --- a/addons/common/functions/fnc_getTurretsFFV.sqf +++ b/addons/common/functions/fnc_getTurretsFFV.sqf @@ -1,23 +1,25 @@ /* * Author: commy2 - * * Get the turret indices of ffv turrets. * - * Argument: - * 0: Vehicle (Object) + * Arguments: + * 0: Vehicle * - * Return value: - * Turret index of the vehicles gunner. Empty array means no ffv turrets. (Array) + * Return Value: + * Vehicle FFV Turret indecies + * + * Public: Yes */ #include "script_component.hpp" -private ["_turrets", "_turret", "_config"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_turrets", "_turret", "_config"]; _turrets = allTurrets [_vehicle, true]; _turret = []; + { _config = configFile >> "CfgVehicles" >> typeOf _vehicle; @@ -26,5 +28,7 @@ _turret = []; if (getNumber (_config >> "isPersonTurret") == 1) then { _turret pushBack _x; }; -} forEach _turrets; + false +} count _turrets; + _turret diff --git a/addons/common/functions/fnc_getTurretsOther.sqf b/addons/common/functions/fnc_getTurretsOther.sqf index 5f373f7c9c..93ab3f2321 100644 --- a/addons/common/functions/fnc_getTurretsOther.sqf +++ b/addons/common/functions/fnc_getTurretsOther.sqf @@ -1,23 +1,25 @@ /* * Author: commy2 - * * Get the turret indices of other turrets (not gunner, commander, copilot or ffv). * - * Argument: - * 0: Vehicle (Object) + * Arguments: + * 0: Vehicle * - * Return value: - * Turret index of the vehicles gunner. Empty array means no other turrets. (Array) + * Return Value: + * Vehicle Other Turret indecies + * + * Public: Yes */ #include "script_component.hpp" -private ["_turrets", "_turret", "_config"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_turrets", "_turret", "_config"]; _turrets = allTurrets [_vehicle, true]; _turret = []; + { _config = configFile >> "CfgVehicles" >> typeOf _vehicle; @@ -30,5 +32,7 @@ _turret = []; ) then { _turret pushBack _x; }; -} forEach _turrets; + false +} count _turrets; + _turret