From b0704e486ff05885b2580a7b05c0c37165b2d883 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 18 Sep 2015 13:09:40 +0200 Subject: [PATCH 1/3] more common cleanup --- addons/common/functions/fnc_cachedCall.sqf | 26 +++++------ .../common/functions/fnc_canGetInPosition.sqf | 26 +++++------ addons/common/functions/fnc_canInteract.sqf | 23 ++++++---- .../common/functions/fnc_canInteractWith.sqf | 25 +++-------- addons/common/functions/fnc_canUseWeapon.sqf | 21 ++++++--- .../fnc_changeProjectileDirection.sqf | 29 +++++------- addons/common/functions/fnc_checkFiles.sqf | 28 +++++++----- addons/common/functions/fnc_checkPBOs.sqf | 45 +++++++++---------- addons/common/functions/fnc_claim.sqf | 13 +++--- 9 files changed, 113 insertions(+), 123 deletions(-) diff --git a/addons/common/functions/fnc_cachedCall.sqf b/addons/common/functions/fnc_cachedCall.sqf index e093f44393..e1e0e16118 100644 --- a/addons/common/functions/fnc_cachedCall.sqf +++ b/addons/common/functions/fnc_cachedCall.sqf @@ -1,5 +1,5 @@ /* - * Author: esteldunedain and Jaynus + * Author: esteldunedain, Jaynus * Returns the result of the function and caches it up to a given ACE_time or event * * Arguments: @@ -8,7 +8,7 @@ * 2: Namespace to store the cache on * 3: Cache uid * 4: Max duration of the cache - * 5: Event that clears the cache (Optional) + * 5: Event that clears the cache (default: nil) * * Return Value: * Result of the function @@ -17,33 +17,31 @@ */ #include "script_component.hpp" -PARAMS_5(_params,_function,_namespace,_uid,_duration); +params ["_params", "_function", "_namespace", "_uid", "_duration", "_event"]; -//IGNORE_PRIVATE_WARNING("_eventName"); - -if (((_namespace getVariable [_uid, [-99999]]) select 0) < ACE_diagTime) then { +if ((_namespace getVariable [_uid, [-99999]]) select 0 < ACE_diagTime) then { _namespace setVariable [_uid, [ACE_diagTime + _duration, _params call _function]]; // Does the cache needs to be cleared on an event? - if (count _this > 5) then { - private ["_event","_varName","_cacheList"]; - _event = _this select 5; - _varName = format [QGVAR(clearCache_%1),_event]; + if (!isNil "_event") then { + private ["_varName", "_cacheList"]; + + _varName = format [QGVAR(clearCache_%1), _event]; _cacheList = missionNamespace getVariable _varName; // If there was no EH to clear these caches, add one - if (isNil {_cacheList}) then { + if (isNil "_cacheList") then { _cacheList = []; missionNamespace setVariable [_varName, _cacheList]; [_event, { - private ["_varName","_cacheList"]; + private ["_varName", "_cacheList"]; // _eventName is defined on the function that calls the event #ifdef DEBUG_MODE_FULL ACE_LOGINFO_1("Clear cached variables on event: %1",_eventName); #endif // Get the list of caches to clear - _varName = format [QGVAR(clearCache_%1),_eventName]; + _varName = format [QGVAR(clearCache_%1), _eventName]; _cacheList = missionNamespace getVariable [_varName, []]; // Erase all the cached results { @@ -57,11 +55,13 @@ if (((_namespace getVariable [_uid, [-99999]]) select 0) < ACE_diagTime) then { // Add this cache to the list of the event _cacheList pushBack [_namespace, _uid]; }; + #ifdef DEBUG_MODE_FULL ACE_LOGINFO_2("Calculated result: %1 %2",_namespace,_uid); } else { ACE_LOGINFO_2("Cached result: %1 %2",_namespace,_uid); #endif + }; (_namespace getVariable _uid) select 1 diff --git a/addons/common/functions/fnc_canGetInPosition.sqf b/addons/common/functions/fnc_canGetInPosition.sqf index 2c84f11b4d..1ea1eeb5a6 100644 --- a/addons/common/functions/fnc_canGetInPosition.sqf +++ b/addons/common/functions/fnc_canGetInPosition.sqf @@ -4,32 +4,26 @@ * Is the unit able to enter the vehicle in the given position? * * Arguments: - * 0: Unit to enter the vehicle (Object) - * 1: The vehicle to be entered (Object) - * 2: Position. Can be "Driver", "Pilot", "Gunner", "Commander", "Copilot", "Turret", "FFV", "Codriver" or "Cargo" (String) - * 3: Check current distance to vehicles memory point? (Bool, optional default: false) + * 0: Unit to enter the vehicle + * 1: The vehicle to be entered + * 2: Position. Can be "Driver", "Pilot", "Gunner", "Commander", "Copilot", "Turret", "FFV", "Codriver" or "Cargo" + * 3: Check current distance to vehicles memory point? (default: false) * 4: Index. "Turret", "FFV", "Codriver" and "Cargo" support this optional parameter. Which position should be taken. - * Note: This index is diffrent from Armas "cargoIndex". (Number, optional default: next free index) + * Note: This index is diffrent from Armas "cargoIndex". (default: next free index) * * Return Value: - * Nothing + * None + * + * Public: No */ #include "script_component.hpp" #define CANGETINDRIVER (isNull (driver _vehicle) || {!alive driver _vehicle}) && {!lockedDriver _vehicle} && {getNumber (_config >> "isUav") != 1} #define CANGETINTURRETINDEX (isNull (_vehicle turretUnit _turret) || {!alive (_vehicle turretUnit _turret)}) && {!(_vehicle lockedTurret _turret)} && {getNumber (_config >> "isUav") != 1} -private ["_position", "_checkDistance", "_index"]; +params ["_unit", "_vehicle", "_position", ["_checkDistance",false], ["_index",-1]]; -_this resize 5; - -PARAMS_2(_unit,_vehicle); -_position = toLower (_this select 2); -_checkDistance = _this select 3; -_index = _this select 4; // optional, please don't use - -if (isNil "_checkDistance") then {_checkDistance = false}; -if (isNil "_index") then {_index = -1}; +_position = toLower _position; // general if (!alive _vehicle || {locked _vehicle > 1}) exitWith {false}; diff --git a/addons/common/functions/fnc_canInteract.sqf b/addons/common/functions/fnc_canInteract.sqf index 4b3e22f646..d2ae7e1ffb 100644 --- a/addons/common/functions/fnc_canInteract.sqf +++ b/addons/common/functions/fnc_canInteract.sqf @@ -1,14 +1,19 @@ -/** - * fn_canInteract.sqf - * @Descr: Check if unit can interact with enviroment. Unit has to be awake and not be in arrested state. - * @Author: Glowbal +/* + * Author: Glowbal + * Check if unit can interact with enviroment. Unit has to be awake and not be in arrested state. * - * @Arguments: [unit OBJECT] - * @Return: BOOL True if unit can interact with enviroment. - * @PublicAPI: true + * Arguments: + * 0: Unit that try to Interact + * + * Return Value: + * Can interact with enviroment + * + * Public: No + * + * Deprecated */ #include "script_component.hpp" -PARAMS_1(_unit); +params ["_unit"]; -(((_unit getvariable [QGVAR(canInteract),0]) < 1) && ([_unit] call FUNC(isAwake)) && !([_unit] call FUNC(isArrested))) \ No newline at end of file +(_unit getvariable [QGVAR(canInteract),0]) < 1 && [_unit] call FUNC(isAwake) && !([_unit] call FUNC(isArrested)) diff --git a/addons/common/functions/fnc_canInteractWith.sqf b/addons/common/functions/fnc_canInteractWith.sqf index 1a6e766855..2fa0ca26e0 100644 --- a/addons/common/functions/fnc_canInteractWith.sqf +++ b/addons/common/functions/fnc_canInteractWith.sqf @@ -5,45 +5,34 @@ * Arguments: * 0: The player. * 1: The interaction target. objNull to ignore. - * 2: Exceptions. What general conditions are to skip? (Optional) + * 2: Exceptions. What general conditions are to skip? (default: []) * * Return Value: * Unit can interact? * - * Public: No + * Public: Yes */ #include "script_component.hpp" -private ["_exceptions"]; +params ["_unit", "_target", ["_exceptions", []]]; -PARAMS_2(_unit,_target); - -_exceptions = if (count _this > 2) then { - _this select 2; -} else { - []; -}; +private ["_exceptions", "_owner"]; _exceptions = [_exceptions, {toLower _this}] call FUNC(map); -// exit if the target is not free to interact -private "_owner"; _owner = _target getVariable [QGVAR(owner), objNull]; +// exit if the target is not free to interact if (!isNull _owner && {_unit != _owner}) exitWith {false}; // check general conditions - -private ["_conditions", "_conditionNames", "_conditionFuncs"]; +private ["_conditions", "_canInteract"]; _conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]]; -_conditionNames = _conditions select 0; -_conditionFuncs = _conditions select 1; +_conditions params ["_conditionNames", "_conditionFuncs"]; -private "_canInteract"; _canInteract = true; - { if (!(_x in _exceptions) && {!([_unit, _target] call (_conditionFuncs select _forEachIndex))}) exitWith { _canInteract = false; diff --git a/addons/common/functions/fnc_canUseWeapon.sqf b/addons/common/functions/fnc_canUseWeapon.sqf index ed478a4470..31aaba17a2 100644 --- a/addons/common/functions/fnc_canUseWeapon.sqf +++ b/addons/common/functions/fnc_canUseWeapon.sqf @@ -1,14 +1,23 @@ -// by commy2 +/* + * Author: commy2 + * Check if the unit can use a Weapon. + * Returns true if the unit is on foot or in a FFV position. + * + * Arguments: + * 0: The Unit + * + * Return Value: + * Can the Unit use Weapons + * + * Public: Yes + */ #include "script_component.hpp" -// returns true if the unit is on foot or in a ffv position - -private ["_config"]; - -PARAMS_1(_unit); +params ["_unit"]; if (_unit == vehicle _unit) exitWith {true}; +private "_config"; _config = configFile >> "CfgMovesMaleSdr" >> "States" >> animationState _unit; isClass _config diff --git a/addons/common/functions/fnc_changeProjectileDirection.sqf b/addons/common/functions/fnc_changeProjectileDirection.sqf index 5a65ccff41..e8e71291d0 100644 --- a/addons/common/functions/fnc_changeProjectileDirection.sqf +++ b/addons/common/functions/fnc_changeProjectileDirection.sqf @@ -1,30 +1,25 @@ /* * Author: commy2 - * * Adjust a projectiles velocity and dir + up vector. * - * Argument: - * 0: Projectile (Object, CfgAmmo) - * 1: Adjust azimuth this much. (Number) - * 2: Adjust inclination this much. (Number) - * 3: Adjust projectile speed this much. In m/s. (Number, optional default: 0 m/s) + * Arguments: + * 0: Projectile + * 1: Adjust azimuth this much. + * 2: Adjust inclination this much. + * 3: Adjust projectile speed this much. In m/s. (optional: 0) * - * Return value: - * None. + * Return Value: + * None + * + * Public: No */ #include "script_component.hpp" -private ["_adjustSpeed", "_vdir", "_dir", "_up", "_vup", "_vel", "_vlat"]; +params ["_projectile", "_adjustDir", "_adjustUp", ["_adjustSpeed",0]]; -PARAMS_3(_projectile,_adjustDir,_adjustUp); +//["CPD", [_fnc_scriptNameParent, _adjustDir, _adjustUp, _adjustSpeed], nil, false] call FUNC(log); -_adjustSpeed = if (count _this > 3) then { - _this select 3 -} else { - 0 -}; - -["CPD", [_fnc_scriptNameParent, _adjustDir, _adjustUp, _adjustSpeed], nil, false] call FUNC(log); +private ["_vdir", "_dir", "_up", "_vlat", "_vup", "_vel"]; // get old direction vector _vdir = vectorNormalized velocity _projectile; diff --git a/addons/common/functions/fnc_checkFiles.sqf b/addons/common/functions/fnc_checkFiles.sqf index e80d18e5b1..2c8976f042 100644 --- a/addons/common/functions/fnc_checkFiles.sqf +++ b/addons/common/functions/fnc_checkFiles.sqf @@ -1,13 +1,14 @@ /* * Author: commy2 - * * Compares version numbers of PBOs and DLLs. * - * Argument: - * None. + * Arguments: + * None * - * Return value: - * None. + * Return Value: + * None + * + * Public: No */ #include "script_component.hpp" @@ -36,13 +37,17 @@ _addons = [_addons, {_this find "ace_" == 0}] call FUNC(filter); ["[ACE] ERROR", _errorMsg, {findDisplay 46 closeDisplay 0}] call FUNC(errorMessage); }; }; -} forEach _addons; + false +} count _addons; /////////////// // check dlls /////////////// { - if (_x callExtension "version" == "") then { + private "_versionEx"; + _versionEx = _x callExtension "version"; + + if (_versionEx == "") then { private "_errorMsg"; _errorMsg = format ["Extension %1.dll not installed.", _x]; @@ -53,9 +58,10 @@ _addons = [_addons, {_this find "ace_" == 0}] call FUNC(filter); }; } else { // Print the current extension version - ACE_LOGINFO_2("Extension version: %1: %2",_x,(_x callExtension "version")); + ACE_LOGINFO_2("Extension version: %1: %2",_x,_versionEx); }; -} forEach getArray (configFile >> "ACE_Extensions" >> "extensions"); + false +} count getArray (configFile >> "ACE_Extensions" >> "extensions"); /////////////// // check server version/addons @@ -75,9 +81,7 @@ if (isMultiplayer) then { [{ if (isNil QGVAR(ServerVersion) || isNil QGVAR(ServerAddons)) exitWith {}; - private ["_version","_addons"]; - _version = (_this select 0) select 0; - _addons = (_this select 0) select 1; + (_this select 0) params ["_version", "_addons"]; if (_version != GVAR(ServerVersion)) then { private "_errorMsg"; diff --git a/addons/common/functions/fnc_checkPBOs.sqf b/addons/common/functions/fnc_checkPBOs.sqf index d1441ffd83..4c923899a1 100644 --- a/addons/common/functions/fnc_checkPBOs.sqf +++ b/addons/common/functions/fnc_checkPBOs.sqf @@ -5,22 +5,20 @@ * * Arguments: * 0: Mode - * 0: Warn once - * 1: Warn permanently - * 2: Kick - * 1: Check all PBOs? (Optional - default: false) - * 2: Whitelist (Optinal - default: "[]") + * 0 = Warn once + * 1 = Warn permanently + * 2 = Kick + * 1: Check all PBOs? (default: false) + * 2: Whitelist (default: "[]") * - * Return value: + * Return Value: * None + * + * Public: Yes */ #include "script_component.hpp" -private ["_mode", "_checkAll", "_whitelist"]; - -_mode = _this select 0; -_checkAll = if (count _this > 1) then {_this select 1} else {false}; -_whitelist = if (count _this > 2) then {_this select 2} else {"[]"}; +params ["_mode", ["_checkAll", false], ["_whitelist", "[]"]]; _whitelist = [_whitelist, {toLower _this}] call FUNC(map); @@ -30,22 +28,17 @@ ACE_Version_Whitelist = _whitelist; if (!_checkAll) exitWith {}; //ACE is checked by FUNC(checkFiles) if (!isServer) then { - [_mode, _checkAll, _whitelist] spawn { - private ["_missingAddon", "_missingAddonServer", "_oldVersionClient", "_oldVersionServer", "_text", "_error", "_rscLayer", "_ctrlHint"]; - PARAMS_3(_mode,_checkAll,_whitelist); + [{ + if (isNil "ACE_Version_ClientErrors") exitWith {}; - waitUntil { - sleep 1; - !isNil "ACE_Version_ClientErrors" - }; + ACE_Version_ClientErrors params ["_missingAddon", "_missingAddonServer", "_oldVersionClient", "_oldVersionServer"]; - _missingAddon = ACE_Version_ClientErrors select 0; - _missingAddonServer = ACE_Version_ClientErrors select 1; - _oldVersionClient = ACE_Version_ClientErrors select 2; - _oldVersionServer = ACE_Version_ClientErrors select 3; + (_this select 0) params ["_mode", "_checkAll", "_whitelist"]; // Display error message. if (_missingAddon || {_missingAddonServer} || {_oldVersionClient} || {_oldVersionServer}) then { + private ["_text", "_error"]; + _text = "[ACE] Version mismatch:

"; _error = format ["ACE version mismatch: %1: ", profileName]; @@ -72,6 +65,8 @@ if (!isServer) then { if (_mode < 2) then { _text = composeText [lineBreak, parseText format ["%1", _text]]; + private ["_rscLayer", "_ctrlHint"]; + _rscLayer = "ACE_RscErrorHint" call BIS_fnc_rscLayer; _rscLayer cutRsc ["ACE_RscErrorHint", "PLAIN", 0, true]; @@ -91,9 +86,11 @@ if (!isServer) then { ["[ACE] ERROR", _text, {findDisplay 46 closeDisplay 0}] call FUNC(errorMessage); }; }; - }; + + [_this select 1] call CBA_fnc_removePerFrameHandler; + }, 1, [_mode, _checkAll, _whitelist]] call CBA_fnc_addPerFrameHandler; }; if (_checkAll) then { - 0 spawn COMPILE_FILE(scripts\Version\checkVersionNumber); + 0 spawn COMPILE_FILE(scripts\Version\checkVersionNumber); // @todo }; diff --git a/addons/common/functions/fnc_claim.sqf b/addons/common/functions/fnc_claim.sqf index 5c8014ee5f..9a5b373fa5 100644 --- a/addons/common/functions/fnc_claim.sqf +++ b/addons/common/functions/fnc_claim.sqf @@ -1,22 +1,19 @@ /* * Author: commy2 - * * Unit claims the ownership over an object. This is used to prevent multiple players from draging the same ammo box or using up the same wheel when repairing etc. * * Arguments: - * 0: Unit that claims another object. ObjNull to remove claim. (Object) - * 1: The object that gets claimed. (Object) - * 2: Lock the claimed object aswell? (Bool) + * 0: Unit that claims another object. ObjNull to remove claim. + * 1: The object that gets claimed. + * 2: Lock the claimed object aswell? (optional: false) * * Return Value: - * NONE + * None * */ #include "script_component.hpp" -PARAMS_3(_unit,_target,_lockTarget); - -if (isNil "_lockTarget") then {_lockTarget = false}; +params ["_unit", "_target", ["_lockTarget", false]]; private "_owner"; _owner = _target getVariable [QGVAR(owner), objNull]; From f83dea6e0145dced32992faebe7f9e6acb435eba Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 18 Sep 2015 14:32:58 +0200 Subject: [PATCH 2/3] formatting, remove an obsolete private --- addons/common/functions/fnc_canGetInPosition.sqf | 2 +- addons/common/functions/fnc_canInteractWith.sqf | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/common/functions/fnc_canGetInPosition.sqf b/addons/common/functions/fnc_canGetInPosition.sqf index 1ea1eeb5a6..40724569d0 100644 --- a/addons/common/functions/fnc_canGetInPosition.sqf +++ b/addons/common/functions/fnc_canGetInPosition.sqf @@ -21,7 +21,7 @@ #define CANGETINDRIVER (isNull (driver _vehicle) || {!alive driver _vehicle}) && {!lockedDriver _vehicle} && {getNumber (_config >> "isUav") != 1} #define CANGETINTURRETINDEX (isNull (_vehicle turretUnit _turret) || {!alive (_vehicle turretUnit _turret)}) && {!(_vehicle lockedTurret _turret)} && {getNumber (_config >> "isUav") != 1} -params ["_unit", "_vehicle", "_position", ["_checkDistance",false], ["_index",-1]]; +params ["_unit", "_vehicle", "_position", ["_checkDistance", false], ["_index", -1]]; _position = toLower _position; diff --git a/addons/common/functions/fnc_canInteractWith.sqf b/addons/common/functions/fnc_canInteractWith.sqf index 2fa0ca26e0..31ebf6b89f 100644 --- a/addons/common/functions/fnc_canInteractWith.sqf +++ b/addons/common/functions/fnc_canInteractWith.sqf @@ -16,10 +16,9 @@ params ["_unit", "_target", ["_exceptions", []]]; -private ["_exceptions", "_owner"]; - _exceptions = [_exceptions, {toLower _this}] call FUNC(map); +private "_owner"; _owner = _target getVariable [QGVAR(owner), objNull]; // exit if the target is not free to interact From 7efcfcc8a02933841a1fa9ca99988749793d3ee4 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 18 Sep 2015 15:40:51 +0200 Subject: [PATCH 3/3] more common cleanup --- addons/common/XEH_preInit.sqf | 1 - .../fnc_closeDialogIfTargetMoves.sqf | 49 --------------- addons/common/functions/fnc_codeToLetter.sqf | 13 +++- addons/common/functions/fnc_codeToString.sqf | 17 +++--- .../common/functions/fnc_convertKeyCode.sqf | 27 +++++---- .../fnc_createOrthonormalReference.sqf | 14 +++-- .../common/functions/fnc_currentChannel.sqf | 10 ++-- addons/common/functions/fnc_debug.sqf | 59 ++++++++----------- addons/common/functions/fnc_debugModule.sqf | 18 +++--- .../common/functions/fnc_defineVariable.sqf | 46 +++++++-------- .../functions/fnc_deviceKeyFindValidIndex.sqf | 18 +++--- .../functions/fnc_deviceKeyRegisterNew.sqf | 7 ++- addons/common/functions/fnc_disableAI.sqf | 13 ++-- 13 files changed, 130 insertions(+), 162 deletions(-) delete mode 100644 addons/common/functions/fnc_closeDialogIfTargetMoves.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 56e3062cd2..2f5c18998b 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -26,7 +26,6 @@ PREP(changeProjectileDirection); PREP(checkFiles); PREP(checkPBOs); PREP(claim); -PREP(closeDialogIfTargetMoves); PREP(codeToLetter); PREP(codeToString); PREP(convertKeyCode); diff --git a/addons/common/functions/fnc_closeDialogIfTargetMoves.sqf b/addons/common/functions/fnc_closeDialogIfTargetMoves.sqf deleted file mode 100644 index db60180bd1..0000000000 --- a/addons/common/functions/fnc_closeDialogIfTargetMoves.sqf +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Author: commy2 - * - * Closes the current dialog if the target moves, changes vehicle etc. - * - * Arguments: - * 0: Target unit - * 1: Ignore the unit being dead? (Optional, default: No) - * - * Return Value: - * None - */ -#include "script_component.hpp" - -_this spawn { - PARAMS_2(_target,_ignoreDead); - private["_inVehicle", "_position", "_vehiclePlayer", "_vehicleTarget"]; - - if (isNil "_ignoreDead") then {_ignoreDead = false}; - - _vehicleTarget = vehicle _target; - _vehiclePlayer = vehicle ACE_player; - _inVehicle = _target != _vehicleTarget; - - _position = getPosASL _target; - - _fnc_check = { - // either unit changed vehicles - if (_vehiclePlayer != vehicle ACE_player) exitWith {True}; - if (_vehicleTarget != vehicle _target) exitWith {True}; - - // target died - if (!alive _target && {!_ignoreDead}) exitWith {True}; - - // player fell unconscious - if (ACE_player getVariable ["ACE_isUnconscious", False]) exitWith {True}; - - // target moved (outside of vehicle) - (!_inVehicle && {getPosASL _target distanceSqr _position > 1}) - }; - - waitUntil { - if (call _fnc_check) then { - closeDialog 0; - call EFUNC(interaction,hideMenu); - }; - (isNil QEGVAR(interaction,MainButton) && !dialog) || {!isNull (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull])} //Exit loop if DisableMouse dialog open - }; -}; diff --git a/addons/common/functions/fnc_codeToLetter.sqf b/addons/common/functions/fnc_codeToLetter.sqf index 8e8a9c8a3e..ccb105ef0b 100644 --- a/addons/common/functions/fnc_codeToLetter.sqf +++ b/addons/common/functions/fnc_codeToLetter.sqf @@ -1,4 +1,15 @@ -// by commy2 +/* + * Author: commy2 + * Converts some keys to an Arma Dik Code. + * + * Arguments: + * 0: Key + * + * Return Value: + * Dik Code + * + * Public: Yes + */ #include "script_component.hpp" ["", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] select ([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 44, 21] find (_this select 0)) + 1 diff --git a/addons/common/functions/fnc_codeToString.sqf b/addons/common/functions/fnc_codeToString.sqf index 1698182051..9347a55b20 100644 --- a/addons/common/functions/fnc_codeToString.sqf +++ b/addons/common/functions/fnc_codeToString.sqf @@ -1,22 +1,23 @@ /* * Author: commy2 - * * Removes the brackets around a code and returns the code as a string. It does nothing if the code is already a string. * * Argument: - * 0: Code (Code or String) + * 0: Code * * Return value: - * Code (String) + * Code + * + * Public: Yes */ #include "script_component.hpp" -PARAMS_1(_function); +params ["_function"]; if (typeName _function == "STRING") exitWith {_function}; _function = toArray str _function; -_function set [0, -1]; -_function set [count _function - 1, -1]; -_function = toString (_function - [-1]); -_function +_function deleteAt 0; +_function deleteAt (count _function - 1); + +toString _function // return diff --git a/addons/common/functions/fnc_convertKeyCode.sqf b/addons/common/functions/fnc_convertKeyCode.sqf index 498a3eb706..3bf6314bef 100644 --- a/addons/common/functions/fnc_convertKeyCode.sqf +++ b/addons/common/functions/fnc_convertKeyCode.sqf @@ -1,27 +1,30 @@ /* * Author: commy2 + * Get a key code used in AGM key input eh. * - * Get a key code used in ACE key input eh. + * Arguments: + * 0: Arma DIK code + * 1: Key state for shift left and shift right key + * 2: Key state for ctrl left and ctrl right key + * 3: Key state for alt and alt gr key * - * Argument: - * 0: Arma DIK code (Number) - * 1: Key state for shift left and shift right key (Bool) - * 2: Key state for ctrl left and ctrl right key (Bool) - * 3: Key state for alt and alt gr key (Bool) + * Return Value: + * Key code * - * Return value: - * Key code (Number) + * Public: Yes + * + * Deprecated */ #include "script_component.hpp" #define KEY_MODIFIERS [42, 54, 29, 157, 56, 184] -PARAMS_1(_key); +params ["_key", "_stateShift", "_stateCtrl", "_stateAlt"]; if (_key in KEY_MODIFIERS) exitWith {_key}; -if (_this select 1) then {_key = _key + 0.1}; -if (_this select 2) then {_key = _key + 0.2}; -if (_this select 3) then {_key = _key + 0.4}; +if (_stateShift) then {_key = _key + 0.1}; +if (_stateCtrl) then {_key = _key + 0.2}; +if (_stateAlt) then {_key = _key + 0.4}; _key diff --git a/addons/common/functions/fnc_createOrthonormalReference.sqf b/addons/common/functions/fnc_createOrthonormalReference.sqf index 346127c658..3e8fb7fb1d 100644 --- a/addons/common/functions/fnc_createOrthonormalReference.sqf +++ b/addons/common/functions/fnc_createOrthonormalReference.sqf @@ -1,19 +1,21 @@ /* * Author: esteldunedain - * * Returns a orthonormal system of reference aligned with the supplied vector * * Argument: * Vector to align the coordinate system with (Array) * - * Return value: - * 0: v1 (Array) - * 1: v2 (Array) - * 2: v3 (Array) + * Return Value: + * 0: Vector Normalized + * 1: Normalized Cross Product Vector + * 2: Vector Cross Product + * + * Public: Yes */ #include "script_component.hpp" -private ["_v1","_v2","_v3"]; +private ["_v1", "_v2", "_v3"]; + _v1 = vectorNormalized _this; _v2 = vectorNormalized (_v1 vectorCrossProduct [0,0,1]); _v3 = _v2 vectorCrossProduct _v1; diff --git a/addons/common/functions/fnc_currentChannel.sqf b/addons/common/functions/fnc_currentChannel.sqf index 127f3b7a54..52aed1f4ce 100644 --- a/addons/common/functions/fnc_currentChannel.sqf +++ b/addons/common/functions/fnc_currentChannel.sqf @@ -3,11 +3,13 @@ * * Returns the current radio / chat / marker channel. * - * Argument: - * NONE. + * Arguments: + * None * - * Return value: - * The current channel. Can be "group", "side", "global", "command", "vehicle", "direct" or "custom_X" (String) + * Return Value: + * The current channel ("group", "side", "global", "command", "vehicle", "direct", "custom_X") + * + * Public: Yes */ #include "script_component.hpp" diff --git a/addons/common/functions/fnc_debug.sqf b/addons/common/functions/fnc_debug.sqf index df770c6e25..49e067f77d 100644 --- a/addons/common/functions/fnc_debug.sqf +++ b/addons/common/functions/fnc_debug.sqf @@ -1,51 +1,43 @@ -/** - * fn_debug.sqf - * @Descr: Print logging messages through the ACE framework. - * @Author: Glowbal +/* + * Author: Glowbal + * Print logging messages through the ACE framework. * - * @Arguments: [message ANY, level NUMBER (Optional)] - * @Return: BOOL True if message has been printed - * @PublicAPI: true + * Arguments: + * 0: Message + * 1: Level (default: 2) + * + * Return Value: + * Message is Printed + * + * Public: Yes */ #include "script_component.hpp" #define DEFAULT_LOGGING_LEVEL -1 #define DEFAULT_TEXT_DISPLAY -1 -private ["_level", "_prefix", "_defaultLoglevel","_defaultLogDisplayLevel", "_message"]; -PARAMS_1(_msg); -_level = if (count _this > 1) then {_this select 1} else { 2 }; +params ["_msg", ["_level", 2, [0]]]; -if (typeName _level != "NUMBER") then { - _level = 2; -}; +private ["_defaultLoglevel", "_defaultLogDisplayLevel"]; -_defaultLoglevel = if (isNil QGVAR(LOGLEVEL)) then { - DEFAULT_LOGGING_LEVEL; -} else { - GVAR(LOGLEVEL); -}; +_defaultLoglevel = [GVAR(LOGLEVEL), DEFAULT_LOGGING_LEVEL] select isNil QGVAR(LOGLEVEL); -if (_defaultLoglevel < 0) exitwith { - false -}; +if (_defaultLoglevel < 0) exitwith {false}; -_defaultLogDisplayLevel = if (isnil QGVAR(LOGDISPLAY_LEVEL)) then { - DEFAULT_TEXT_DISPLAY; -} else { - GVAR(LOGDISPLAY_LEVEL); -}; +_defaultLogDisplayLevel = [GVAR(LOGDISPLAY_LEVEL), DEFAULT_TEXT_DISPLAY] select isNil QGVAR(LOGDISPLAY_LEVEL); if (_level <= _defaultLoglevel) then { + private ["_prefix", "_message"]; - _prefix = switch (_level) do { - case 0: { "ACE Error" }; - case 1: { "ACE Warn" }; - case 2: { "ACE Debug" }; - case 3: { "ACE Info" }; - default { "ACE Unknown" }; + switch (_level) do { + case 0: {_prefix = "Error"}; + case 1: {_prefix = "Warn"}; + case 2: {_prefix = "Debug"}; + case 3: {_prefix = "Info"}; + default {_prefix = "Unknown"}; }; - _message = format["[%1] %2",_prefix,_msg]; + + _message = format ["[ACE %1] %2", _prefix, _msg]; if (_level <= _defaultLogDisplayLevel) then { systemChat _message; @@ -55,4 +47,5 @@ if (_level <= _defaultLoglevel) then { // pass it onwards to the log function: // [0, [], compile format["%1",_msg], true] call FUNC(log); }; + true diff --git a/addons/common/functions/fnc_debugModule.sqf b/addons/common/functions/fnc_debugModule.sqf index 262ae9c02d..d313244e52 100644 --- a/addons/common/functions/fnc_debugModule.sqf +++ b/addons/common/functions/fnc_debugModule.sqf @@ -1,16 +1,18 @@ -/** - * fn_debugModule.sqf - * @Descr: N/A - * @Author: Glowbal +/* + * Author: Glowbal * - * @Arguments: [] - * @Return: - * @PublicAPI: false + * Arguments: + * None + * + * Return Value: + * None + * + * Public: No */ #include "script_component.hpp" -PARAMS_1(_entity); +params ["_entity"]; GVAR(LOGDISPLAY_LEVEL) = call compile (_entity getvariable ["logDisplayLevel","4"]); GVAR(LOGLEVEL) = call compile (_entity getvariable ["logLevel","4"]); diff --git a/addons/common/functions/fnc_defineVariable.sqf b/addons/common/functions/fnc_defineVariable.sqf index 28ed5b2015..f64c20ba61 100644 --- a/addons/common/functions/fnc_defineVariable.sqf +++ b/addons/common/functions/fnc_defineVariable.sqf @@ -1,38 +1,34 @@ -/** - * fn_defineVariable.sqf - * @Descr: Define a variable for the ACE variable framework - * @Author: Glowbal +/* + * Author: Glowbal + * Define a variable for the ACE variable framework * - * @Arguments: [name STRING, defaultValue ANY, publicFlag BOOL, category STRING, type NUMBER, persistentFlag BOOL] - * @Return: - * @PublicAPI: true + * Arguments: + * 0: Name + * 1: defaultValue + * 2: publicFlag + * 3: category + * 4: type (default: 0) + * 5: persistentFlag (default: false) + * + * Return Value: + * None + * + * Public: Yes */ #include "script_component.hpp" -private ["_code","_persistent"]; +params ["_name", "_value", "_defaultGlobal", "_category", ["_code", 0], ["_persistent", false]]; -PARAMS_4(_name,_value,_defaultGlobal,_catagory); +if (isNil "_defaultGlobal") exitWith {}; -_code = 0; -_persistent = false; - -if (count _this < 3) exitwith {}; -if (count _this > 4) then { - _code = _this select 4; - if (count _this > 5) then { - _persistent = _this select 5; - }; -}; - -if (typeName _name != typeName "") exitwith { +if (typeName _name != "STRING") exitwith { [format["Tried to the deinfe a variable with an invalid name: %1 Arguments: %2", _name, _this]] call FUNC(debug); }; -if (isnil QGVAR(OBJECT_VARIABLES_STORAGE)) then { +if (isNil QGVAR(OBJECT_VARIABLES_STORAGE)) then { GVAR(OBJECT_VARIABLES_STORAGE) = []; }; -GVAR(OBJECT_VARIABLES_STORAGE) pushback [_name,_value,_defaultGlobal,_catagory,_code, _persistent]; - -missionNamespace setvariable [QGVAR(OBJECT_VARIABLES_STORAGE_) + _name, [_name,_value,_defaultGlobal,_catagory,_code, _persistent]]; +GVAR(OBJECT_VARIABLES_STORAGE) pushBack [_name, _value, _defaultGlobal, _category, _code, _persistent]; +missionNamespace setVariable [QGVAR(OBJECT_VARIABLES_STORAGE_) + _name, [_name, _value, _defaultGlobal, _category, _code, _persistent]]; diff --git a/addons/common/functions/fnc_deviceKeyFindValidIndex.sqf b/addons/common/functions/fnc_deviceKeyFindValidIndex.sqf index a8418cd4cd..681ab946e0 100644 --- a/addons/common/functions/fnc_deviceKeyFindValidIndex.sqf +++ b/addons/common/functions/fnc_deviceKeyFindValidIndex.sqf @@ -3,7 +3,7 @@ * Finds next valid index for the device array. * * Arguments: - * 0: Offset from currentIndex (use 1 to find next valid after current) or a displayName string or + * 0: Offset from currentIndex (use 1 to find next valid after current) or a displayName string (default: 0) * * Return Value: * The new index (-1 if no valid) @@ -16,23 +16,25 @@ */ #include "script_component.hpp" -DEFAULT_PARAM(0,_searchOffsetOrName,0); +params [["_searchOffsetOrName", 0]]; -private ["_validIndex", "_offsetBy", "_realIndex", "_offset"]; +private ["_validIndex", "_realIndex"]; _validIndex = -1; -if ((typeName _searchOffsetOrName) == "STRING") then { +if (typeName _searchOffsetOrName == "STRING") then { { - if ((_x select 0) == _searchOffsetOrName) exitWith { + if (_x select 0 == _searchOffsetOrName) exitWith { _validIndex = _forEachIndex; }; } forEach GVAR(deviceKeyHandlingArray); } else { - if ((count GVAR(deviceKeyHandlingArray)) > 0) then { - _baseIndex = if (GVAR(deviceKeyCurrentIndex) == -1) then {0} else {GVAR(deviceKeyCurrentIndex) + _searchOffsetOrName}; - for "_offset" from _baseIndex to ((count GVAR(deviceKeyHandlingArray)) - 1 + _baseIndex) do { + if (count GVAR(deviceKeyHandlingArray) > 0) then { + _baseIndex = [GVAR(deviceKeyCurrentIndex) + _searchOffsetOrName, 0] select (GVAR(deviceKeyCurrentIndex) == -1); + + for "_offset" from _baseIndex to (count GVAR(deviceKeyHandlingArray) - 1 + _baseIndex) do { _realIndex = _offset % (count GVAR(deviceKeyHandlingArray)); + if ([] call ((GVAR(deviceKeyHandlingArray) select _realIndex) select 2)) exitWith { _validIndex = _realIndex; }; diff --git a/addons/common/functions/fnc_deviceKeyRegisterNew.sqf b/addons/common/functions/fnc_deviceKeyRegisterNew.sqf index 88ffa84af7..416eef2c77 100644 --- a/addons/common/functions/fnc_deviceKeyRegisterNew.sqf +++ b/addons/common/functions/fnc_deviceKeyRegisterNew.sqf @@ -10,7 +10,7 @@ * 4: Close Code (on ctrl-home press) * * Return Value: - * Nothing + * None * * Example: * [(localize "STR_ACE_microdagr_itemName"), QUOTE(PATHTOF(images\microDAGR_item.paa)), _conditionCode, _toggleCode, _closeCode] call ace_common_fnc_deviceKeyRegisterNew @@ -19,7 +19,8 @@ */ #include "script_component.hpp" -PARAMS_5(_displayName,_iconImage,_conditionCode,_toggleCode,_closeCode); +params ["_displayName", "_iconImage", "_conditionCode", "_toggleCode", "_closeCode"]; + +GVAR(deviceKeyHandlingArray) pushBack [_displayName, _iconImage, _conditionCode, _toggleCode, _closeCode]; -GVAR(deviceKeyHandlingArray) pushBack [_displayName,_iconImage,_conditionCode,_toggleCode,_closeCode]; [] call FUNC(deviceKeyFindValidIndex); diff --git a/addons/common/functions/fnc_disableAI.sqf b/addons/common/functions/fnc_disableAI.sqf index 0e1985eced..1a66628ffb 100644 --- a/addons/common/functions/fnc_disableAI.sqf +++ b/addons/common/functions/fnc_disableAI.sqf @@ -10,15 +10,17 @@ * None * * Example: - * [bob, true] call ace_common_fnc_disableAI; + * [bob, true] call ace_common_fnc_disableAI * * Public: No */ #include "script_component.hpp" -PARAMS_2(_unit,_disable); +params ["_unit", "_disable"]; -if ((local _unit) && {!([_unit] call EFUNC(common,isPlayer))}) then { +if (!local _unit) exitWith {}; + +if !([_unit] call EFUNC(common,isPlayer)) then { if (_disable) then { _unit disableAI "MOVE"; _unit disableAI "TARGET"; @@ -27,7 +29,10 @@ if ((local _unit) && {!([_unit] call EFUNC(common,isPlayer))}) then { _unit disableConversation true; } else { //Sanity check to make sure we don't enable unconsious AI - if (_unit getVariable ["ace_isunconscious", false] && alive _unit) exitWith {ERROR("Enabling AI for unconsious unit");}; + if (_unit getVariable ["ace_isunconscious", false] && alive _unit) exitWith { + ERROR("Enabling AI for unconsious unit"); + }; + _unit enableAI "MOVE"; _unit enableAI "TARGET"; _unit enableAI "AUTOTARGET";