From 9fa6eb0651df16d916c5f021f3fb97481149384e Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 13:08:10 +0200 Subject: [PATCH] more common code cleanup --- .../fnc_getFirstObjectIntersection.sqf | 34 +++++++----- .../fnc_getFirstTerrainIntersection.sqf | 30 ++++++----- .../functions/fnc_getNumberFromMissionSQM.sqf | 18 +++---- .../functions/fnc_getNumberMagazinesIn.sqf | 28 +++++----- .../common/functions/fnc_getPitchBankYaw.sqf | 2 +- .../common/functions/fnc_getSettingData.sqf | 29 +++++----- .../functions/fnc_getStringFromMissionSQM.sqf | 26 ++++++--- .../fnc_getTargetAzimuthAndInclination.sqf | 13 ++--- .../functions/fnc_getTargetDistance.sqf | 21 ++++---- .../common/functions/fnc_getTargetObject.sqf | 19 ++++--- .../functions/fnc_getTurnedOnLights.sqf | 14 ++--- .../functions/fnc_getUavControlPosition.sqf | 42 ++++++++------- .../common/functions/fnc_getVehicleCargo.sqf | 16 +++--- .../functions/fnc_getVehicleCodriver.sqf | 16 +++--- .../common/functions/fnc_getVehicleCrew.sqf | 41 +++++++------- addons/common/functions/fnc_getVersion.sqf | 20 ++++--- .../fnc_getWeaponAzimuthAndInclination.sqf | 17 +++--- .../common/functions/fnc_getWeaponIndex.sqf | 15 +++--- .../common/functions/fnc_getWeaponModes.sqf | 24 +++++---- .../common/functions/fnc_getWeaponMuzzles.sqf | 16 +++--- .../common/functions/fnc_getWeaponState.sqf | 54 +++++++------------ addons/common/functions/fnc_getWeaponType.sqf | 26 ++++----- 22 files changed, 279 insertions(+), 242 deletions(-) diff --git a/addons/common/functions/fnc_getFirstObjectIntersection.sqf b/addons/common/functions/fnc_getFirstObjectIntersection.sqf index 3a99f244ed..1111094ed0 100644 --- a/addons/common/functions/fnc_getFirstObjectIntersection.sqf +++ b/addons/common/functions/fnc_getFirstObjectIntersection.sqf @@ -1,23 +1,31 @@ -/** - * fn_getFirstIntersection.sqf - * @Descr: Returns the the first intersection with an object between two positions - * @Author: Ruthberg +/* + * Author: Ruthberg + * Returns the the first intersection with terrain between two positions. @todo rewrite using lineIntersectsSurfaces? * - * @Arguments: [position PositionASL, position PositionASL, accuracy FLOAT] - * @Return: [intersects BOOL, intersection PositionASL] - * @PublicAPI: true + * Arguments: + * 0: PositionASL + * 1: PositionATL + * 2: Accuracy + * + * Return Value: + * 0: Intersects + * 1: Intersection Position ASL + * + * Public: Yes */ - #include "script_component.hpp" +#include "script_component.hpp" -private ["_distance", "_lower", "_upper", "_mid", "_intersections", "_result", "_dir"]; +params ["_source", "_destination", "_accuracy"]; -PARAMS_3(_source,_destination,_accuracy); +private ["_result", "_distance"]; _result = [false, [0, 0, 0]]; _distance = _source vectorDistance _destination; -if (count (lineIntersectsWith [_source, _destination]) > 0) then { +if !(lineIntersectsWith [_source, _destination] isEqualTo []) then { + private ["_lower", "_upper", "_mid", "_dir"]; + _lower = 0; _upper = 1; _mid = 0.5; @@ -27,9 +35,7 @@ if (count (lineIntersectsWith [_source, _destination]) > 0) then { while {(_upper - _lower) * _distance > _accuracy} do { _mid = _lower + (_upper - _lower) / 2; - _intersections = count (lineIntersectsWith [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))]); - - if (_intersections > 0) then { + if !(lineIntersectsWith [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))] isEqualTo []) then { _upper = _mid; } else { _lower = _mid; diff --git a/addons/common/functions/fnc_getFirstTerrainIntersection.sqf b/addons/common/functions/fnc_getFirstTerrainIntersection.sqf index 2fe8242c15..a5065413d9 100644 --- a/addons/common/functions/fnc_getFirstTerrainIntersection.sqf +++ b/addons/common/functions/fnc_getFirstTerrainIntersection.sqf @@ -1,23 +1,31 @@ -/** - * fn_getFirstIntersection.sqf - * @Descr: Returns the the first intersection with an object between two positions - * @Author: Ruthberg +/* + * Author: Ruthberg + * Returns the the first intersection with an object between two positions. @todo rewrite using lineIntersectsSurfaces? * - * @Arguments: [position PositionASL, position PositionASL, accuracy FLOAT] - * @Return: [intersects BOOL, intersection PositionASL] - * @PublicAPI: true + * Arguments: + * 0: PositionASL + * 1: PositionATL + * 2: Accuracy + * + * Return Value: + * 0: Intersects + * 1: Intersection Position ASL + * + * Public: Yes */ #include "script_component.hpp" -private ["_distance", "_lower", "_upper", "_mid", "_intersection", "_result", "_dir"]; +params ["_source", "_destination", "_accuracy"]; -PARAMS_3(_source,_destination,_accuracy); +private ["_result", "_distance"]; _result = [false, [0, 0, 0]]; _distance = _source vectorDistance _destination; if (terrainIntersectASL [_source, _destination]) then { + private ["_lower", "_upper", "_mid", "_dir"]; + _lower = 0; _upper = 1; _mid = 0.5; @@ -27,9 +35,7 @@ if (terrainIntersectASL [_source, _destination]) then { while {(_upper - _lower) * _distance > _accuracy} do { _mid = _lower + (_upper - _lower) / 2; - _intersection = terrainIntersectASL [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))]; - - if (_intersection) then { + if (terrainIntersectASL [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))]) then { _upper = _mid; } else { _lower = _mid; diff --git a/addons/common/functions/fnc_getNumberFromMissionSQM.sqf b/addons/common/functions/fnc_getNumberFromMissionSQM.sqf index 1c9fbda77d..6c381d4f54 100644 --- a/addons/common/functions/fnc_getNumberFromMissionSQM.sqf +++ b/addons/common/functions/fnc_getNumberFromMissionSQM.sqf @@ -1,18 +1,16 @@ /* * Author: commy2 - * * Get a number from the mission.sqm file. Mission has to be saved in the Editor. + * On non-existing entries, it might return 0 or the value of an entry with the same name of another calss. * - * Argument: - * 0: Path of the entry in the mission.sqm (Array) + * Arguments: + * 0: Path of the entry in the mission.sqm * - * Return value: - * Value of the entry. Note: If the entry does not exist, it might return 0 or an entry with the same name of another class! (Number) + * Return Value: + * Entry value + * + * Public: No */ #include "script_component.hpp" -private "_number"; - -_number = _this call FUNC(getStringFromMissionSQM); - -parseNumber _number; +parseNumber (_this call FUNC(getStringFromMissionSQM)) // return diff --git a/addons/common/functions/fnc_getNumberMagazinesIn.sqf b/addons/common/functions/fnc_getNumberMagazinesIn.sqf index 91921abd77..df1f7ed64b 100644 --- a/addons/common/functions/fnc_getNumberMagazinesIn.sqf +++ b/addons/common/functions/fnc_getNumberMagazinesIn.sqf @@ -1,26 +1,30 @@ -/** - * fn_getNumberMagazinesIn.sqf - * @Descr: - * @Author: Glowbal +/* + * Author: Glowbal + * Count magazines of unit. * - * @Arguments: [] - * @Return: - * @PublicAPI: true + * Arguments: + * 0: Unit + * 1: Magazine + * + * Return Value: + * Magazine amount + * + * Public: No */ - #include "script_component.hpp" -PARAMS_2(_unit,_magazine); - -private ["_return"]; +params ["_unit", "_magazine"]; +private "_return"; _return = 0; + if (_unit isKindOf "CAManBase") then { _return = {_x == _magazine} count magazines _unit; } else { { _return = _return + {_x == _magazine} count magazines _x; - } forEach (crew _unit); + false + } count crew _unit; _return = _return + ({_x == _magazine} count getMagazineCargo _unit); }; diff --git a/addons/common/functions/fnc_getPitchBankYaw.sqf b/addons/common/functions/fnc_getPitchBankYaw.sqf index 74eac376fc..89fab8d92b 100644 --- a/addons/common/functions/fnc_getPitchBankYaw.sqf +++ b/addons/common/functions/fnc_getPitchBankYaw.sqf @@ -14,6 +14,6 @@ */ #include "script_component.hpp" -private ["_vehicle"]; +params ["_vehicle"]; (_vehicle call BIS_fnc_getPitchBank) + [getDir _vehicle] diff --git a/addons/common/functions/fnc_getSettingData.sqf b/addons/common/functions/fnc_getSettingData.sqf index 40ed962a7a..de9ef40447 100644 --- a/addons/common/functions/fnc_getSettingData.sqf +++ b/addons/common/functions/fnc_getSettingData.sqf @@ -3,29 +3,32 @@ * Returns the metadata of a setting if it exists * * Arguments: - * 0: Name of the setting (String) + * 0: Setting Name * * Return Value: * Setting Data (Array) - * 0: _name - * 1: _typeName - * 2: _isClientSetable - * 3: _localizedName - * 4: _localizedDescription - * 5: _possibleValues - * 6: _isForced - * 7: _defaultValue + * 0: Name + * 1: Type Name + * 2: Is Client Settable + * 3: Localized Name + * 4: Localized Description + * 5: Possible Values + * 6: Is Forced + * 7: Default Value + * 8: Localized Category * * Public: No */ #include "script_component.hpp" -PARAMS_1(_name); +params ["_name"]; -private ["_value"]; +private "_value"; _value = []; + { - if ((_x select 0) == _name) exitWith {_value = _x}; -} forEach GVAR(settings); + if (_x select 0 == _name) exitWith {_value = _x}; + false +} count GVAR(settings); _value diff --git a/addons/common/functions/fnc_getStringFromMissionSQM.sqf b/addons/common/functions/fnc_getStringFromMissionSQM.sqf index cfb7495467..6b6a34cfb7 100644 --- a/addons/common/functions/fnc_getStringFromMissionSQM.sqf +++ b/addons/common/functions/fnc_getStringFromMissionSQM.sqf @@ -1,28 +1,34 @@ /* * Author: commy2 + * Get a string from the mission.sqm file. Mission has to be saved in the Editor. + * The string cannot contain the ; character. + * If the entry does not exist, it might return an empty string or an entry with the same name of another class! * - * Get a string from the mission.sqm file. Mission has to be saved in the Editor. The string cannot contain the ; character. + * Arguments: + * 0: Path of the entry in the mission.sqm * - * Argument: - * 0: Path of the entry in the mission.sqm (Array) + * Return Value: + * Value of the entry. * - * Return value: - * Value of the entry. Note: If the entry does not exist, it might return an empty string or an entry with the same name of another class! (String) + * Public: No */ #include "script_component.hpp" -private ["_path", "_mission", "_a", "_class", "_index", "_array", "_b", "_entry"]; +private ["_path", "_mission", "_class", "_index", "_array", "_entry"]; _path = _this; if (missionName == "") exitWith {""}; + _mission = toArray toLower loadFile "mission.sqm"; _mission resize 65536; + { if (_x < 33) then { _mission set [_forEachIndex, -1]; } } forEach _mission; + _mission = toString (_mission - [-1]); {_path set [_forEachIndex, toLower _x]} forEach _path; @@ -33,9 +39,11 @@ for "_a" from 0 to (count _path - 2) do { _index = _mission find _class; _array = toArray _mission; + for "_b" from 0 to (_index + count toArray _class - 1) do { _array set [_b, -1]; }; + _array = _array - [-1]; _mission = toString _array; @@ -43,16 +51,20 @@ for "_a" from 0 to (count _path - 2) do { _entry = format ["%1=", _path select (count _path - 1)]; _index = _mission find _entry; + if (_index == -1) exitWith {""}; _array = toArray _mission; + for "_b" from 0 to (_index + count toArray _entry - 1) do { _array set [_b, -1]; }; + _mission = toString (_array - [-1]); _index = _mission find ";"; _mission = toArray _mission; _mission resize _index; -format ["%1", toString _mission]; + +format ["%1", toString _mission] // return diff --git a/addons/common/functions/fnc_getTargetAzimuthAndInclination.sqf b/addons/common/functions/fnc_getTargetAzimuthAndInclination.sqf index 396a3ec85e..da23e600aa 100644 --- a/addons/common/functions/fnc_getTargetAzimuthAndInclination.sqf +++ b/addons/common/functions/fnc_getTargetAzimuthAndInclination.sqf @@ -1,14 +1,15 @@ /* * Author: commy2 + * Get players viewing direction and slope. * - * Get players viewing direction and slope + * Arguments: + * None * - * Argument: - * None. + * Return Value: + * 0: Azimuth + * 1: Inclination * - * Return value: - * 0: Azimuth (Number) - * 1: Inclination or 'slope' (Number) + * Public: Yes */ #include "script_component.hpp" diff --git a/addons/common/functions/fnc_getTargetDistance.sqf b/addons/common/functions/fnc_getTargetDistance.sqf index ac3c444a73..fe75268cea 100644 --- a/addons/common/functions/fnc_getTargetDistance.sqf +++ b/addons/common/functions/fnc_getTargetDistance.sqf @@ -1,21 +1,22 @@ /* * Author: commy2 - * * Get the distance to the next object the player is looking at. Used for laser distance measurements. * - * Argument: - * 0: How accurate will the measurement be? In meters. (Number) - * 1: Maximal distance to measure. (Number) - * 2: Minimal distance to measure. (optional, Number) + * Arguments: + * 0: Messurement Accuracy + * 1: Maximal messure distance + * 2: Minimal messure distance (default: nil) * - * Return value: - * Measured distance in meters. Can return maximal or minimal distance (Number) + * Return Value: + * Distance in meters + * + * Public: Yes */ #include "script_component.hpp" -private ["_position", "_laser", "_line", "_distance", "_iteration"]; +params ["_interval", "_maxDistance", "_minDistance"]; -PARAMS_3(_interval,_maxDistance,_minDistance); +private ["_position", "_laser", "_line", "_distance", "_iteration"]; _position = ATLToASL positionCameraToWorld [0, 0, 0]; _position set [2, (_position select 2) - (getTerrainHeightASL _position min 0)]; @@ -42,6 +43,6 @@ _distance = _interval * round (_distance / _interval); _distance = _distance min _maxDistance; -if !(isNil "_minDistance") then {_distance = _distance max _minDistance}; +if (!isNil "_minDistance") then {_distance = _distance max _minDistance}; _distance diff --git a/addons/common/functions/fnc_getTargetObject.sqf b/addons/common/functions/fnc_getTargetObject.sqf index 6e3db94763..adaaa3e344 100644 --- a/addons/common/functions/fnc_getTargetObject.sqf +++ b/addons/common/functions/fnc_getTargetObject.sqf @@ -1,19 +1,20 @@ /* * Author: commy2 - * * Get the nearest object the player is looking at. Used for laser designator instead of cursorTarget. * - * Argument: - * 0: Maximal distance to search. (Number) + * Arguments: + * 0: Maximum search distance * - * Return value: - * Nearest object directly in line of sight, if none objNull (Object) + * Return Value: + * Nearest object in line of sight, objNull if none are found + * + * Public: Yes */ #include "script_component.hpp" -private ["_position", "_laser", "_intersects"]; +params ["_maxDistance"]; -PARAMS_1(_maxDistance); +private ["_position", "_laser", "_intersects"]; _position = ATLToASL positionCameraToWorld [0, 0, 0]; _position set [2, (_position select 2) - (getTerrainHeightASL _position min 0)]; @@ -23,4 +24,6 @@ _laser set [2, (_laser select 2) - (getTerrainHeightASL _laser min 0)]; _intersects = lineIntersectsObjs [_position, _laser, objNull, objNull, true, 2]; -if (count _intersects == 0) then {objNull} else {_intersects select 0} +if (_intersects isEqualTo []) exitWith {objNull}; + +_intersects select 0 // return diff --git a/addons/common/functions/fnc_getTurnedOnLights.sqf b/addons/common/functions/fnc_getTurnedOnLights.sqf index b0eb201bca..0d71a3362e 100644 --- a/addons/common/functions/fnc_getTurnedOnLights.sqf +++ b/addons/common/functions/fnc_getTurnedOnLights.sqf @@ -1,21 +1,22 @@ /* * Author: commy2 - * * Returns all turned on lights of any vehicle or streetlamp. * * Arguments: - * 0: A vehicle, not the classname (Object) + * 0: Vehicle * * Return Value: - * All burning lights (Array) + * All burning lights + * + * Public: Yes */ #include "script_component.hpp" -PARAMS_1(_vehicle); +params ["_vehicle"]; if (!isLightOn _vehicle) exitWith {[]}; -private ["_reflectorsWithSelections", "_lights", "_hitpoints"]; +private ["_reflectorsWithSelections", "_lights", "_hitpoints", "_turnedOnLights"]; _reflectorsWithSelections = [[_vehicle], FUNC(getReflectorsWithSelections), uiNamespace, format [QEGVAR(cache,%1_%2), QUOTE(DFUNC(getReflectorsWithSelections)), typeOf _vehicle], 1E11] call FUNC(cachedCall); //_reflectorsWithSelections = [_vehicle] call FUNC(getReflectorsWithSelections); @@ -23,13 +24,12 @@ _reflectorsWithSelections = [[_vehicle], FUNC(getReflectorsWithSelections), uiNa _lights = _reflectorsWithSelections select 0; _hitpoints = _reflectorsWithSelections select 1; -private "_turnedOnLights"; _turnedOnLights = []; + { if (_vehicle getHit _x <= 0.9) then { _turnedOnLights pushBack (_lights select _forEachIndex); }; - } forEach _hitpoints; _turnedOnLights diff --git a/addons/common/functions/fnc_getUavControlPosition.sqf b/addons/common/functions/fnc_getUavControlPosition.sqf index ad2487c9c1..a9b5340eb2 100644 --- a/addons/common/functions/fnc_getUavControlPosition.sqf +++ b/addons/common/functions/fnc_getUavControlPosition.sqf @@ -1,32 +1,34 @@ /* -Name: FUNC(getUavControlPosition) - -Author: Pabst Mirror - -Description: - Gets the seat position of a UAV that the unit is activly controlling. - "" - not connected to anything or not activly controling - "DRIVER" - "GUNNER" - -Parameters: - 0: OBJECT - Unit - -Returns: - STRING - Position in the UAV that is currently being controled by the unit. - -Example: - [ACE_Player] call FUNC(getUavControlPosition) -*/ + * Author: PabstMirror + * Returns the seat position of a UAV that the unit is activly controling. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Position + * "" = not connected to anything or activly controling + * "DRIVER" + * "GUNNER" + * + * Example: + * [ACE_Player] call ace_common_fnc_getUavControlPosition + * + * Public: Yes + */ #include "script_component.hpp" +params ["_unit"]; + private ["_uav", "_positionArray", "_playerIndex"]; -PARAMS_1(_unit); _uav = getConnectedUAV _unit; + if (isNull _uav) exitWith {""}; + _positionArray = UAVControl _uav; _playerIndex = _positionArray find _unit; + if (_playerIndex == -1) exitWith {""}; _positionArray select (_playerIndex + 1) diff --git a/addons/common/functions/fnc_getVehicleCargo.sqf b/addons/common/functions/fnc_getVehicleCargo.sqf index 4b8ca63f5c..5be213aa68 100644 --- a/addons/common/functions/fnc_getVehicleCargo.sqf +++ b/addons/common/functions/fnc_getVehicleCargo.sqf @@ -1,19 +1,20 @@ /* * Author: commy2 - * * Get the vehicle cargo positions. Codrivers and ffv positions are not listed. * - * Argument: - * 0: Vehicle type (String) + * Arguments: + * 0: Vehicle type * - * Return value: - * Vehicle cargo positions. (Array) + * Return Value: + * Vehicle cargo positions + * + * Public: Yes */ #include "script_component.hpp" -private ["_config", "_cargo", "_codrivers", "_index"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_config", "_cargo", "_codrivers"]; _config = configFile >> "CfgVehicles" >> _vehicle; @@ -25,4 +26,5 @@ for "_index" from 0 to (getNumber (_config >> "transportSoldier") - 1) do { _cargo pushBack _index; }; }; + _cargo diff --git a/addons/common/functions/fnc_getVehicleCodriver.sqf b/addons/common/functions/fnc_getVehicleCodriver.sqf index 019c7b9971..e23cfcd0d4 100644 --- a/addons/common/functions/fnc_getVehicleCodriver.sqf +++ b/addons/common/functions/fnc_getVehicleCodriver.sqf @@ -1,19 +1,20 @@ /* * Author: commy2 - * * Get the vehicle codriver positions. * - * Argument: - * 0: Vehicle type (String) + * Arguments: + * 0: Vehicle type * - * Return value: - * Vehicle codriver positions. (Array) + * Return Value: + * Vehicle codriver positions + * + * Public: Yes */ #include "script_component.hpp" -private ["_config", "_cargo", "_codrivers", "_index"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_config", "_cargo", "_codrivers"]; _config = configFile >> "CfgVehicles" >> _vehicle; @@ -25,4 +26,5 @@ for "_index" from 0 to (getNumber (_config >> "transportSoldier") - 1) do { _cargo pushBack _index; }; }; + _cargo diff --git a/addons/common/functions/fnc_getVehicleCrew.sqf b/addons/common/functions/fnc_getVehicleCrew.sqf index 23957c31fd..58d0067b85 100644 --- a/addons/common/functions/fnc_getVehicleCrew.sqf +++ b/addons/common/functions/fnc_getVehicleCrew.sqf @@ -1,36 +1,37 @@ /* * Author: commy2 - * * Returns array of crew member objects. * - * Argument: - * 0: Vehicle (Object) - * 1: Slot types. Can contain "driver", "commander", "gunner", "turret", "cargo" and "ffv". Case sensitive (Array) + * Arguments: + * 0: Vehicle + * 1: Slot types filter (default: ["driver", "commander", "gunner", "turret", "cargo", "ffv"]) * - * Return value: - * Crew (Array) + * Return Value: + * Crew + * + * Public: Yes */ #include "script_component.hpp" -private ["_crew"]; - -PARAMS_2(_vehicle,_types); +params ["_vehicle", ["_types", ["driver", "commander", "gunner", "turret", "cargo", "ffv"]]]; +private "_crew"; _crew = []; // iterate through all crew members { - // this unit is in a ffv position. check if we search for ffv. - if (_x select 4) then { - if ("ffv" in _types) then { - _crew pushBack (_x select 0); + // this unit is in a ffv position. check if we search for ffv. + if (_x select 4) then { + if ("ffv" in _types) then { + _crew pushBack (_x select 0); + }; + } else { + // otherwise check if we search for that type. toLower, because fullCrew returns "driver" vs. "Turret". + if (toLower (_x select 1) in _types) then { + _crew pushBack (_x select 0); + }; }; - } else { - // otherwise check if we search for that type. toLower, because fullCrew returns "driver" vs. "Turret". - if (toLower (_x select 1) in _types) then { - _crew pushBack (_x select 0); - }; - }; -} forEach fullCrew _vehicle; + false +} count fullCrew _vehicle; _crew diff --git a/addons/common/functions/fnc_getVersion.sqf b/addons/common/functions/fnc_getVersion.sqf index e1bd95cdab..24773240b7 100644 --- a/addons/common/functions/fnc_getVersion.sqf +++ b/addons/common/functions/fnc_getVersion.sqf @@ -1,11 +1,15 @@ -/** - * fn_getVersion.sqf - * @Descr: Get the version number of the current ACE Build - * @Author: Glowbal +/* + * Author: Glowbal + * Get the version number of the current ACE build. * - * @Arguments: [] - * @Return: STRING String containing the version - * @PublicAPI: true + * Arguments: + * None + * + * Return Value: + * ACE Version + * + * Public: Yes */ #include "script_component.hpp" -getText (configFile >> "cfgPatches" >> "ACE_main" >> "version"); \ No newline at end of file + +getText (configFile >> "CfgPatches" >> "ACE_main" >> "version") // return diff --git a/addons/common/functions/fnc_getWeaponAzimuthAndInclination.sqf b/addons/common/functions/fnc_getWeaponAzimuthAndInclination.sqf index 03b7b1c707..09968d8e39 100644 --- a/addons/common/functions/fnc_getWeaponAzimuthAndInclination.sqf +++ b/addons/common/functions/fnc_getWeaponAzimuthAndInclination.sqf @@ -1,20 +1,21 @@ /* * Author: commy2 + * Get local players weapon direction and slope. * - * Get players weapon direction and slope + * Arguments: + * 0: Weapon name * - * Argument: - * 0: Weapon name (String) + * Return Value: + * 0: Azimuth + * 1: Inclination * - * Return value: - * 0: Azimuth (Number) - * 1: Inclination or 'slope' (Number) + * Public: Yes */ #include "script_component.hpp" -private ["_direction", "_azimuth", "_inclination"]; +params ["_weapon"]; -PARAMS_1(_weapon); +private ["_direction", "_azimuth", "_inclination"]; _direction = ACE_player weaponDirection _weapon; diff --git a/addons/common/functions/fnc_getWeaponIndex.sqf b/addons/common/functions/fnc_getWeaponIndex.sqf index b11054a5e7..0e24f190a5 100644 --- a/addons/common/functions/fnc_getWeaponIndex.sqf +++ b/addons/common/functions/fnc_getWeaponIndex.sqf @@ -1,20 +1,23 @@ /* * Author: commy2 * Get the index of the weapon. - * 0 = primary, 1 = secondary, 2 = handgun, -1 = other * - * Argument: + * Arguments: * 0: Unit * 1: Weapon * - * Return value: + * Return Value: * Weapon index + * 0 = primary + * 1 = secondary + * 2 = handgun + * -1 = other * - * Public: No + * Public: Yes */ #include "script_component.hpp" -PARAMS_2(_unit,_weapon); +params ["_unit", "_weapon"]; if (_weapon == "") exitWith {-1}; @@ -22,4 +25,4 @@ if (_weapon == "") exitWith {-1}; primaryWeapon _unit, secondaryWeapon _unit, handgunWeapon _unit -] find _weapon +] find _weapon // return diff --git a/addons/common/functions/fnc_getWeaponModes.sqf b/addons/common/functions/fnc_getWeaponModes.sqf index 83e7b7559f..a2bb9c3205 100644 --- a/addons/common/functions/fnc_getWeaponModes.sqf +++ b/addons/common/functions/fnc_getWeaponModes.sqf @@ -1,30 +1,34 @@ /* * Author: commy2 + * Get the available firing modes of a weapon. Will ignore the AI helper modes. * - * Get the available firing modes of a weapon. Will ignore the ai helper modes. + * Arguments: + * 0: Weapon * - * Argument: - * 0: A weapon in cfgWeapons (String) + * Return Value: + * Firing Modes * - * Return value: - * All firing modes (Array) + * Public: Yes */ #include "script_component.hpp" -private ["_modes"]; +params ["_weapon"]; -PARAMS_1(_weapon); +private ["_config", "_modes"]; + +_config = configFile >> "CfgWeapons" >> _weapon; _modes = []; + { - if (getNumber (configFile >> "CfgWeapons" >> _weapon >> _x >> "showToPlayer") == 1) then { + if (getNumber (_config >> _x >> "showToPlayer") == 1) then { _modes pushBack _x; }; if (_x == "this") then { _modes pushBack _weapon; }; - -} forEach getArray (configfile >> "CfgWeapons" >> _weapon >> "modes"); + false +} count getArray (_config >> "modes"); _modes diff --git a/addons/common/functions/fnc_getWeaponMuzzles.sqf b/addons/common/functions/fnc_getWeaponMuzzles.sqf index b0b7173d2f..cdfd58f238 100644 --- a/addons/common/functions/fnc_getWeaponMuzzles.sqf +++ b/addons/common/functions/fnc_getWeaponMuzzles.sqf @@ -1,20 +1,20 @@ /* * Author: commy2 - * * Get the muzzles of a weapon. * - * Argument: - * 0: A weapon in cfgWeapons (String) + * Arguments: + * 0: Weapon * - * Return value: - * All weapon muzzles (Array) + * Return Value: + * All weapon muzzles + * + * Public: Yes */ #include "script_component.hpp" -private ["_muzzles"]; - -PARAMS_1(_weapon); +params ["_weapon"]; +private "_muzzles"; _muzzles = getArray (configFile >> "CfgWeapons" >> _weapon >> "muzzles"); if ("this" in _muzzles) then { diff --git a/addons/common/functions/fnc_getWeaponState.sqf b/addons/common/functions/fnc_getWeaponState.sqf index 543f356b7e..8ee1610f4e 100644 --- a/addons/common/functions/fnc_getWeaponState.sqf +++ b/addons/common/functions/fnc_getWeaponState.sqf @@ -1,46 +1,28 @@ /* * Author: commy2 - * * Return current state of the weapon. Attachments and magazines with ammo. * - * Argument: - * 0: A unit (Object) - * 1: A weapon (String) + * Arguments: + * 0: unit + * 1: weapon * - * Return value: - * Weapon info, format: [attachments, muzzles, magazines, ammo] (Array) + * Return Value: + * 0: Attachements + * 1: Muzzles + * 2: Magazines + * 3: Ammo + * + * Public: Yes */ - #include "script_component.hpp" +#include "script_component.hpp" -PARAMS_2(_unit,_weapon); +params ["_unit", "_weapon"]; + +private ["_muzzles", "_weaponInfo"]; -private "_muzzles"; _muzzles = [_weapon] call FUNC(getWeaponMuzzles); -private "_weaponInfo"; -_weaponInfo = []; - -switch (_weapon) do { - case (primaryWeapon _unit): { - _weaponInfo pushBack primaryWeaponItems _unit; - - }; - - case (secondaryWeapon _unit): { - _weaponInfo pushBack secondaryWeaponItems _unit; - - }; - - case (handgunWeapon _unit): { - _weaponInfo pushBack handgunItems _unit; - - }; - - default { - _weaponInfo pushBack ["","","",""]; - - }; -}; +_weaponInfo = [["","","",""], primaryWeaponItems _unit, secondaryWeaponItems _unit, handgunItems _unit] select ((["", primaryWeapon _unit, secondaryWeapon _unit, handgunWeapon _unit] find _weapon) max 0); // get loaded magazines and ammo private ["_magazines", "_ammo"]; @@ -51,7 +33,8 @@ _ammo = []; { _magazines pushBack ""; _ammo pushBack 0; -} forEach _muzzles; + false +} count _muzzles; { if (_x select 2) then { @@ -63,7 +46,8 @@ _ammo = []; _ammo set [_index, _x select 1]; }; }; -} forEach magazinesAmmoFull _unit; + false +} count magazinesAmmoFull _unit; _weaponInfo append [_muzzles, _magazines, _ammo]; diff --git a/addons/common/functions/fnc_getWeaponType.sqf b/addons/common/functions/fnc_getWeaponType.sqf index c153bb2b3c..f8ee7f9fe4 100644 --- a/addons/common/functions/fnc_getWeaponType.sqf +++ b/addons/common/functions/fnc_getWeaponType.sqf @@ -1,19 +1,24 @@ /* * Author: commy2 + * Check what kind of weapon the given class name is. * - * Check what kind of weapon the given class name is. (primary, secondary or handgun) + * Arguments: + * 0: Weapons * - * Argument: - * 0: Class name of the weapon (String) + * Return Value: + * Slot index + * 1 = primary + * 2 = secondary + * 3 = handgun + * -1 = other * - * Return value: - * Slot index of the given class name, 1: primary, 2: secondary, 3: handgun, else: -1 (Number) + * Public: Yes */ #include "script_component.hpp" -private ["_type", "_index"]; +params ["_weapon"]; -PARAMS_1(_weapon); +private ["_type", "_index"]; _type = [getNumber (configFile >> "CfgWeapons" >> _weapon >> "type")] call FUNC(binarizeNumber); @@ -23,9 +28,4 @@ while {!(_type select _index) && {_index < 16}} do { _index = _index + 1; }; -switch (_index) do { - case 0 : {1}; - case 1 : {3}; - case 2 : {2}; - default {-1}; -} +[-1, 1, 3, 2] select (([0, 1, 2] find _index) + 1) // return