From c3beee82615496b2c29b6b7c179396f5d68c607e Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 30 Aug 2015 21:13:29 +0200 Subject: [PATCH 01/29] make use of getHitpointsDamage command to drastically speed up some functions about hitpoints --- addons/common/XEH_preInit.sqf | 1 + addons/common/functions/fnc_getHitPoints.sqf | 46 ++-------------- .../fnc_getHitPointsWithSelections.sqf | 52 ++----------------- .../fnc_getSelectionsWithoutHitPoints.sqf | 28 ++++++++++ 4 files changed, 37 insertions(+), 90 deletions(-) create mode 100644 addons/common/functions/fnc_getSelectionsWithoutHitPoints.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 6fdf99113c..23b4e5c696 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -215,6 +215,7 @@ PREP(getConfigGunner); PREP(getConfigCommander); PREP(getHitPoints); PREP(getHitPointsWithSelections); +PREP(getSelectionsWithoutHitPoints); PREP(getReflectorsWithSelections); PREP(getLightProperties); PREP(getLightPropertiesWeapon); diff --git a/addons/common/functions/fnc_getHitPoints.sqf b/addons/common/functions/fnc_getHitPoints.sqf index 06b2b8d40b..491f243b44 100644 --- a/addons/common/functions/fnc_getHitPoints.sqf +++ b/addons/common/functions/fnc_getHitPoints.sqf @@ -1,7 +1,7 @@ /* * Author: commy2 * - * Returns all hitpoints of any vehicle. Non unique hitpoints in turrets are ignored. + * Returns all hitpoints of any vehicle. Might contain duplicates if the turrets contain non unique hitpoints with different selection names. * * Arguments: * 0: A vehicle, not the classname (Object) @@ -11,46 +11,6 @@ */ #include "script_component.hpp" -private ["_config", "_hitpoints", "_i"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); - -_config = configFile >> "CfgVehicles" >> typeOf _vehicle; - -_hitpoints = []; - -// get all classes that can contain hitpoints -private "_hitpointClasses"; -_hitpointClasses = [_config >> "HitPoints"]; -{ - private "_class"; - _class = ([_config, _x] call FUNC(getTurretConfigPath)) >> "HitPoints"; - - if (isClass _class) then { - _hitpointClasses pushBack _class; - }; - -} forEach allTurrets _vehicle; - -// iterate through all classes with hitpoints and their parents -{ - private "_class"; - _class = _x; - - while {isClass _class} do { - - for "_i" from 0 to (count _class - 1) do { - private "_entry"; - _entry = configName (_class select _i); - - if (!(_entry in _hitpoints) && {!isNil {_vehicle getHitPointDamage _entry}}) then { - _hitpoints pushBack _entry; - }; - }; - - _class = inheritsFrom _class; - }; - -} forEach _hitpointClasses; - -_hitpoints +(getAllHitPointsDamage _vehicle select 0) - [""] diff --git a/addons/common/functions/fnc_getHitPointsWithSelections.sqf b/addons/common/functions/fnc_getHitPointsWithSelections.sqf index b66700881e..bc3799665e 100644 --- a/addons/common/functions/fnc_getHitPointsWithSelections.sqf +++ b/addons/common/functions/fnc_getHitPointsWithSelections.sqf @@ -11,51 +11,9 @@ */ #include "script_component.hpp" -private ["_config", "_hitpoints", "_selections", "_i"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); - -_config = configFile >> "CfgVehicles" >> typeOf _vehicle; - -_hitpoints = []; -_selections = []; - -// get all classes that can contain hitpoints -private "_hitpointClasses"; -_hitpointClasses = [_config >> "HitPoints"]; -{ - private "_class"; - _class = ([_config, _x] call FUNC(getTurretConfigPath)) >> "HitPoints"; - - if (isClass _class) then { - _hitpointClasses pushBack _class; - }; - -} forEach allTurrets _vehicle; - -// iterate through all classes with hitpoints and their parents -{ - private "_class"; - _class = _x; - - while {isClass _class} do { - - for "_i" from 0 to (count _class - 1) do { - if (isClass (_class select _i)) then { - private ["_entry", "_selection"]; - _entry = configName (_class select _i); - _selection = getText (_class select _i >> "name"); - - if (!(_selection in _selections) && {!isNil {_vehicle getHit _selection}}) then { - _hitpoints pushBack _entry; - _selections pushBack _selection; - }; - }; - }; - - _class = inheritsFrom _class; - }; - -} forEach _hitpointClasses; - -[_hitpoints, _selections] +private "_hitPointsWithSelections"; +_hitPointsWithSelections = getAllHitPointsDamage _vehicle; +_hitPointsWithSelections resize 2; +_hitPointsWithSelections diff --git a/addons/common/functions/fnc_getSelectionsWithoutHitPoints.sqf b/addons/common/functions/fnc_getSelectionsWithoutHitPoints.sqf new file mode 100644 index 0000000000..277155108a --- /dev/null +++ b/addons/common/functions/fnc_getSelectionsWithoutHitPoints.sqf @@ -0,0 +1,28 @@ +/* + * Author: commy2 + * + * Returns all damageable selections without hitpoints of any vehicle. + * + * Arguments: + * 0: A vehicle, not the classname (Object) + * + * Return Value: + * The selections without hitpoints, i.e. reflectors. (Array) + */ +#include "script_component.hpp" + +params ["_vehicle"]; + +private ["_hitPointsFull", "_allSelectionsWithoutHitpoints"]; + +_hitPointsFull = getAllHitPointsDamage _vehicle; + +_allSelectionsWithoutHitpoints = []; + +{ + if (_x == "") then { + _allSelectionsWithoutHitpoints pushBack (_hitPointsFull select 1 select _forEachIndex); + }; +} forEach (_hitPointsFull select 0); + +_allSelectionsWithoutHitpoints From 06a9f6028126db6b53afb762bf431ae6183deadd Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 16 Sep 2015 10:55:23 -0500 Subject: [PATCH 02/29] Cleanup Nightvision --- addons/nightvision/functions/fnc_blending.sqf | 26 +++++++------------ .../functions/fnc_changeNVGBrightness.sqf | 6 +++-- addons/nightvision/script_component.hpp | 2 ++ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/addons/nightvision/functions/fnc_blending.sqf b/addons/nightvision/functions/fnc_blending.sqf index 8c49711079..a565eb65c0 100644 --- a/addons/nightvision/functions/fnc_blending.sqf +++ b/addons/nightvision/functions/fnc_blending.sqf @@ -23,25 +23,19 @@ if (!hasInterface) exitWith {}; -private ["_vehicle", "_weapon", "_ammo", "_magazine", "_player"]; +params ["_vehicle", "_weapon", "", "", "_ammo", "_magazine"]; -_vehicle = _this select 0; -_weapon = _this select 1; -_ammo = _this select 4; -_magazine = _this select 5; - -_player = ACE_player; //If our vehicle didn't shoot, or we're not in NVG mode, exit -if ((_vehicle != (vehicle _player)) || {(currentVisionMode _player) != 1}) exitWith {}; +if ((_vehicle != (vehicle ACE_player)) || {(currentVisionMode ACE_player) != 1}) exitWith {}; //If we are mounted, and it wasn't our weapon system that fired, exit -if (_player != _vehicle && {!(_weapon in (_vehicle weaponsTurret ([_player] call EFUNC(common,getTurretIndex))))}) exitWith {}; +if (ACE_player != _vehicle && {!(_weapon in (_vehicle weaponsTurret ([ACE_player] call EFUNC(common,getTurretIndex))))}) exitWith {}; -private ["_silencer", "_visibleFireCoef", "_visibleFireTimeCoef", "_visibleFire", "_visibleFireTime", "_nvgBrightnessCoef", "_fnc_isTracer", "_darkness"]; +private["_darkness", "_nvgBrightnessCoef", "_silencer", "_visibleFire", "_visibleFireCoef", "_visibleFireTime", "_visibleFireTimeCoef"]; _silencer = switch (_weapon) do { -case (primaryWeapon _player) : {primaryWeaponItems _player select 0}; -case (secondaryWeapon _player) : {secondaryWeaponItems _player select 0}; -case (handgunWeapon _player) : {handgunItems _player select 0}; + case (primaryWeapon ACE_player) : {primaryWeaponItems ACE_player select 0}; + case (secondaryWeapon ACE_player) : {secondaryWeaponItems ACE_player select 0}; + case (handgunWeapon ACE_player) : {handgunItems ACE_player select 0}; default {""}; }; @@ -55,14 +49,14 @@ if (_silencer != "") then { _visibleFire = getNumber (configFile >> "CfgAmmo" >> _ammo >> "visibleFire"); _visibleFireTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "visibleFireTime"); -_nvgBrightnessCoef = 1 + (_player getVariable [QGVAR(NVGBrightness), 0]) / 4; +_nvgBrightnessCoef = 1 + (ACE_player getVariable [QGVAR(NVGBrightness), 0]) / 4; _fnc_isTracer = { private ["_indexShot", "_lastRoundsTracer", "_tracersEvery"]; if (getNumber (configFile >> "CfgAmmo" >> _ammo >> "nvgOnly") > 0) exitWith {false}; - _indexShot = (_player ammo _weapon) + 1; + _indexShot = (ACE_player ammo _weapon) + 1; _lastRoundsTracer = getNumber (configFile >> "CfgMagazines" >> _magazine >> "lastRoundsTracer"); if (_indexShot <= _lastRoundsTracer) exitWith {true}; @@ -83,7 +77,7 @@ _darkness = 1 - (call EFUNC(common,ambientBrightness)); _visibleFire = _darkness * _visibleFireCoef * _visibleFire * _nvgBrightnessCoef / 10 min 1; _visibleFireTime = _darkness * _visibleFireTimeCoef * _visibleFireTime * _nvgBrightnessCoef / 10 min 0.5; -// ["NightVision", [_visibleFire, _visibleFireTime], {format ["visibleFire: %1 - visibleFireTime: %2", _this select 0, _this select 1]}] call AGM_Debug_fnc_log; //todo +TRACE_2("Player Shot, Adjusting NVG Effect", _visibleFire, _visibleFireTime); GVAR(ppEffectMuzzleFlash) ppEffectAdjust [1, 1, _visibleFire, [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1]]; GVAR(ppEffectMuzzleFlash) ppEffectCommit 0; diff --git a/addons/nightvision/functions/fnc_changeNVGBrightness.sqf b/addons/nightvision/functions/fnc_changeNVGBrightness.sqf index a55535e40a..116ab9b5a5 100644 --- a/addons/nightvision/functions/fnc_changeNVGBrightness.sqf +++ b/addons/nightvision/functions/fnc_changeNVGBrightness.sqf @@ -16,10 +16,12 @@ */ #include "script_component.hpp" -if (!hasInterface) exitWith {}; +params ["_player", "_changeInBrightness"]; +TRACE_2("params",_player,_changeInBrightness); + private ["_brightness"]; -PARAMS_2(_player,_changeInBrightness); +if (!hasInterface) exitWith {}; _brightness = _player getVariable [QGVAR(NVGBrightness), 0]; diff --git a/addons/nightvision/script_component.hpp b/addons/nightvision/script_component.hpp index d322ea0799..9afeeb5d8d 100644 --- a/addons/nightvision/script_component.hpp +++ b/addons/nightvision/script_component.hpp @@ -1,6 +1,8 @@ #define COMPONENT nightvision #include "\z\ace\addons\main\script_mod.hpp" +// #define DEBUG_MODE_FULL + #ifdef DEBUG_ENABLED_NIGHTVISION #define DEBUG_MODE_FULL #endif From 65b8585d60891727e80d94bfeee37d13d6c97675 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 18 Sep 2015 12:48:59 -0500 Subject: [PATCH 03/29] Use _player instead of ACE_player --- addons/nightvision/functions/fnc_blending.sqf | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/addons/nightvision/functions/fnc_blending.sqf b/addons/nightvision/functions/fnc_blending.sqf index a565eb65c0..42d586248d 100644 --- a/addons/nightvision/functions/fnc_blending.sqf +++ b/addons/nightvision/functions/fnc_blending.sqf @@ -25,17 +25,20 @@ if (!hasInterface) exitWith {}; params ["_vehicle", "_weapon", "", "", "_ammo", "_magazine"]; +private "_player"; +_player = ACE_player; + //If our vehicle didn't shoot, or we're not in NVG mode, exit -if ((_vehicle != (vehicle ACE_player)) || {(currentVisionMode ACE_player) != 1}) exitWith {}; +if ((_vehicle != (vehicle _player)) || {(currentVisionMode _player) != 1}) exitWith {}; //If we are mounted, and it wasn't our weapon system that fired, exit -if (ACE_player != _vehicle && {!(_weapon in (_vehicle weaponsTurret ([ACE_player] call EFUNC(common,getTurretIndex))))}) exitWith {}; +if (_player != _vehicle && {!(_weapon in (_vehicle weaponsTurret ([_player] call EFUNC(common,getTurretIndex))))}) exitWith {}; private["_darkness", "_nvgBrightnessCoef", "_silencer", "_visibleFire", "_visibleFireCoef", "_visibleFireTime", "_visibleFireTimeCoef"]; _silencer = switch (_weapon) do { - case (primaryWeapon ACE_player) : {primaryWeaponItems ACE_player select 0}; - case (secondaryWeapon ACE_player) : {secondaryWeaponItems ACE_player select 0}; - case (handgunWeapon ACE_player) : {handgunItems ACE_player select 0}; + case (primaryWeapon _player): {(primaryWeaponItems _player) select 0}; + case (secondaryWeapon _player): {(secondaryWeaponItems _player) select 0}; + case (handgunWeapon _player): {(handgunItems _player) select 0}; default {""}; }; @@ -49,14 +52,14 @@ if (_silencer != "") then { _visibleFire = getNumber (configFile >> "CfgAmmo" >> _ammo >> "visibleFire"); _visibleFireTime = getNumber (configFile >> "CfgAmmo" >> _ammo >> "visibleFireTime"); -_nvgBrightnessCoef = 1 + (ACE_player getVariable [QGVAR(NVGBrightness), 0]) / 4; +_nvgBrightnessCoef = 1 + (_player getVariable [QGVAR(NVGBrightness), 0]) / 4; _fnc_isTracer = { private ["_indexShot", "_lastRoundsTracer", "_tracersEvery"]; if (getNumber (configFile >> "CfgAmmo" >> _ammo >> "nvgOnly") > 0) exitWith {false}; - _indexShot = (ACE_player ammo _weapon) + 1; + _indexShot = (_player ammo _weapon) + 1; _lastRoundsTracer = getNumber (configFile >> "CfgMagazines" >> _magazine >> "lastRoundsTracer"); if (_indexShot <= _lastRoundsTracer) exitWith {true}; From 6773119f097ee07e6f5c6ea956f712d8cc65e838 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Fri, 18 Sep 2015 13:14:00 -0500 Subject: [PATCH 04/29] Script to search for undefined functions --- tools/search_undefinedFunctions.py | 111 +++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tools/search_undefinedFunctions.py diff --git a/tools/search_undefinedFunctions.py b/tools/search_undefinedFunctions.py new file mode 100644 index 0000000000..e7c1b8fb34 --- /dev/null +++ b/tools/search_undefinedFunctions.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 + +import fnmatch +import os +import re +import ntpath +import sys +import argparse + +import ctypes + +#from http://stackoverflow.com/a/3429034 +#Get required functions, strcpy.. +strcpy = ctypes.cdll.msvcrt.strcpy +ocb = ctypes.windll.user32.OpenClipboard #Basic Clipboard functions +ecb = ctypes.windll.user32.EmptyClipboard +gcd = ctypes.windll.user32.GetClipboardData +scd = ctypes.windll.user32.SetClipboardData +ccb = ctypes.windll.user32.CloseClipboard +ga = ctypes.windll.kernel32.GlobalAlloc # Global Memory allocation +gl = ctypes.windll.kernel32.GlobalLock # Global Memory Locking +gul = ctypes.windll.kernel32.GlobalUnlock +GMEM_DDESHARE = 0x2000 + +def Get( ): + ocb(None) # Open Clip, Default task + pcontents = gcd(1) # 1 means CF_TEXT.. too lazy to get the token thingy ... + data = ctypes.c_char_p(pcontents).value + #gul(pcontents) ? + ccb() + return data + +def Paste( data ): + ocb(None) # Open Clip, Default task + ecb() + hCd = ga( GMEM_DDESHARE, len( bytes(data,"ascii") )+1 ) + pchData = gl(hCd) + strcpy(ctypes.c_char_p(pchData),bytes(data,"ascii")) + gul(hCd) + scd(1,hCd) + ccb() + + + +def getFunctions(filepath): + + selfmodule = (re.search('addons[\W]*([_a-zA-Z0-9]*)', filepath)).group(1) + + # print("Checking {0} from {1}".format(filepath,selfmodule)) + + def pushClosing(t): + closingStack.append(closing.expr) + closing << Literal( closingFor[t[0]] ) + + def popClosing(): + closing << closingStack.pop() + + with open(filepath, 'r') as file: + content = file.read() + + srch = re.compile('[^E]FUNC\(([_a-zA-Z0-9]*)\)') + modfuncs = srch.findall(content) + modfuncs = sorted(set(modfuncs)) + + srch = re.compile('EFUNC\(([_a-zA-Z0-9]*),([_a-zA-Z0-9]*)\)') + exfuncs = srch.findall(content) + exfuncs = sorted(set(exfuncs)) + + allFuncs = [] + for func in modfuncs: + allFuncs.append("ace_{0}_fnc_{1}".format(selfmodule,func)) + + for exModule,func in exfuncs: + allFuncs.append("ace_{0}_fnc_{1}".format(exModule, func)) + + return allFuncs + +def main(): + + print("#########################") + print("# All Functions #") + print("#########################") + + sqf_list = [] + allFunctions = [] + + parser = argparse.ArgumentParser() + parser.add_argument('-m','--module', help='only search specified module addon folder', required=False, default=".") + args = parser.parse_args() + + for root, dirnames, filenames in os.walk('../addons' + '/' + args.module): + for filename in fnmatch.filter(filenames, '*.sqf'): + sqf_list.append(os.path.join(root, filename)) + + for filename in sqf_list: + allFunctions = allFunctions + getFunctions(filename) + + + testCode1 = "diag_log text '*********** Scaning for nil functions [count {0}]';".format(len(set(allFunctions))); + testCode2 = "{ if (isNil _x) then {systemChat format ['%1 is nil', _x]; diag_log text format ['%1 is nil', _x];}} forEach allFunctions;"; + + outputCode = "{0} allFunctions = {1}; {2}".format(testCode1, list(set(allFunctions)), testCode2) + + print(outputCode) + Paste(outputCode); + + print ("") + print ("Copied to clipboard, total func count {0}".format(len(set(allFunctions)))) + +if __name__ == "__main__": + main() From 2e48a92eefbd60449ffb423be94c06ea176ef875 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 18 Sep 2015 22:25:09 +0200 Subject: [PATCH 05/29] fix ai seemingly reloading disposable launcher at mission start, fix #2508 --- addons/disposable/CfgVehicles.hpp | 102 +++++++++--------- .../functions/fnc_takeLoadedATWeapon.sqf | 2 + 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/addons/disposable/CfgVehicles.hpp b/addons/disposable/CfgVehicles.hpp index 13d4cedf4b..0ad3ff51c0 100644 --- a/addons/disposable/CfgVehicles.hpp +++ b/addons/disposable/CfgVehicles.hpp @@ -1,5 +1,5 @@ class CfgVehicles { -#define MACRO_NONLAW \ + #define MACRO_NONLAW \ class TransportMagazines { \ class _xx_NLAW_F { \ count = 0; \ @@ -73,56 +73,56 @@ class CfgVehicles { MACRO_NONLAW }; /*class B_APC_Tracked_01_base_F: APC_Tracked_01_base_F { - MACRO_NONLAW -}; -class B_APC_Tracked_01_rcws_F: B_APC_Tracked_01_base_F { - MACRO_NONLAW -}; -class B_APC_Tracked_01_CRV_F: B_APC_Tracked_01_base_F { - MACRO_NONLAW -}; -class B_APC_Tracked_01_AA_F: B_APC_Tracked_01_base_F { - MACRO_NONLAW -};*/ + MACRO_NONLAW + }; + class B_APC_Tracked_01_rcws_F: B_APC_Tracked_01_base_F { + MACRO_NONLAW + }; + class B_APC_Tracked_01_CRV_F: B_APC_Tracked_01_base_F { + MACRO_NONLAW + }; + class B_APC_Tracked_01_AA_F: B_APC_Tracked_01_base_F { + MACRO_NONLAW + };*/ class Car_F; class MRAP_01_base_F: Car_F { MACRO_NONLAW }; /*class MRAP_01_gmg_base_F: MRAP_01_base_F { - MACRO_NONLAW -}; -class MRAP_01_hmg_base_F: MRAP_01_gmg_base_F { - MACRO_NONLAW -}; -class B_MRAP_01_F: MRAP_01_base_F { - MACRO_NONLAW -}; -class B_MRAP_01_gmg_F: MRAP_01_gmg_base_F { - MACRO_NONLAW -}; -class B_MRAP_01_hmg_F: MRAP_01_hmg_base_F { - MACRO_NONLAW -};*/ + MACRO_NONLAW + }; + class MRAP_01_hmg_base_F: MRAP_01_gmg_base_F { + MACRO_NONLAW + }; + class B_MRAP_01_F: MRAP_01_base_F { + MACRO_NONLAW + }; + class B_MRAP_01_gmg_F: MRAP_01_gmg_base_F { + MACRO_NONLAW + }; + class B_MRAP_01_hmg_F: MRAP_01_hmg_base_F { + MACRO_NONLAW + };*/ class MRAP_03_base_F: Car_F { MACRO_NONLAW }; /*class MRAP_03_hmg_base_F: MRAP_03_base_F { - MACRO_NONLAW -}; -class MRAP_03_gmg_base_F: MRAP_03_hmg_base_F { - MACRO_NONLAW -}; -class I_MRAP_03_F: MRAP_03_base_F { - MACRO_NONLAW -}; -class I_MRAP_03_hmg_F: MRAP_03_hmg_base_F { - MACRO_NONLAW -}; -class I_MRAP_03_gmg_F: MRAP_03_gmg_base_F { - MACRO_NONLAW -};*/ + MACRO_NONLAW + }; + class MRAP_03_gmg_base_F: MRAP_03_hmg_base_F { + MACRO_NONLAW + }; + class I_MRAP_03_F: MRAP_03_base_F { + MACRO_NONLAW + }; + class I_MRAP_03_hmg_F: MRAP_03_hmg_base_F { + MACRO_NONLAW + }; + class I_MRAP_03_gmg_F: MRAP_03_gmg_base_F { + MACRO_NONLAW + };*/ class Wheeled_APC_F: Car_F {}; class APC_Wheeled_03_base_F: Wheeled_APC_F { @@ -132,15 +132,15 @@ class I_MRAP_03_gmg_F: MRAP_03_gmg_base_F { MACRO_NONLAW }; /*class B_APC_Wheeled_01_base_F: APC_Wheeled_01_base_F { - MACRO_NONLAW -}; -class B_APC_Wheeled_01_cannon_F: B_APC_Wheeled_01_base_F { - MACRO_NONLAW -}; -class I_APC_Wheeled_03_base_F: APC_Wheeled_03_base_F { - MACRO_NONLAW -}; -class I_APC_Wheeled_03_cannon_F: I_APC_Wheeled_03_base_F { - MACRO_NONLAW -};*/ + MACRO_NONLAW + }; + class B_APC_Wheeled_01_cannon_F: B_APC_Wheeled_01_base_F { + MACRO_NONLAW + }; + class I_APC_Wheeled_03_base_F: APC_Wheeled_03_base_F { + MACRO_NONLAW + }; + class I_APC_Wheeled_03_cannon_F: I_APC_Wheeled_03_base_F { + MACRO_NONLAW + };*/ }; diff --git a/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf b/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf index b379584b68..de7cdefd70 100644 --- a/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf +++ b/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf @@ -36,6 +36,7 @@ if (isClass _config && {getText (_config >> "ACE_UsedTube") != ""} && {getNumber if (backpack _unit == "") then { _unit addBackpack "Bag_Base"; + _unit removeWeapon _launcher; _unit addMagazine _magazine; _didAdd = _magazine in (magazines _unit); _unit addWeapon _launcher; @@ -45,6 +46,7 @@ if (isClass _config && {getText (_config >> "ACE_UsedTube") != ""} && {getNumber }; removeBackpack _unit; } else { + _unit removeWeapon _launcher; _unit addMagazine _magazine; _didAdd = _magazine in (magazines _unit); _unit addWeapon _launcher; From 493ce1b09211ea7aacfbbb783f9ff3eea9420872 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 20 Sep 2015 22:16:51 +0200 Subject: [PATCH 06/29] more common code cleanup --- .../common/functions/fnc_disableUserInput.sqf | 28 ++++----- .../functions/fnc_displayTextPicture.sqf | 29 +++++----- .../functions/fnc_displayTextStructured.sqf | 25 ++++---- addons/common/functions/fnc_doAnimation.sqf | 45 +++++---------- addons/common/functions/fnc_dropBackpack.sqf | 22 +++---- addons/common/functions/fnc_dumpArray.sqf | 26 +++++++-- .../functions/fnc_dumpPerformanceCounters.sqf | 57 ++++++++++++------- 7 files changed, 123 insertions(+), 109 deletions(-) diff --git a/addons/common/functions/fnc_disableUserInput.sqf b/addons/common/functions/fnc_disableUserInput.sqf index d9485b11e7..ffa6d8e28f 100644 --- a/addons/common/functions/fnc_disableUserInput.sqf +++ b/addons/common/functions/fnc_disableUserInput.sqf @@ -5,23 +5,20 @@ * Arguments: * 0: True to disable key inputs, false to re-enable them * - * Return value: - * Nothing + * Return Value: + * None * - * Public: Yes + * Public: No */ - #include "script_component.hpp" -private ["_dlg"]; - -PARAMS_1(_state); +params ["_state"]; if (_state) then { disableSerialization; if (!isNull (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull])) exitWith {}; - if ("ACE_DisableUserInput" in ([BIS_stackedEventHandlers_onEachFrame, {_this select 0}] call FUNC(map))) exitWith {}; + if (!isNil QGVAR(disableInputPFH)) exitWith {}; // end TFAR and ACRE2 radio transmissions call FUNC(endRadioTransmission); @@ -34,19 +31,22 @@ if (_state) then { closeDialog 0; createDialog QGVAR(DisableMouse_Dialog); + private "_dlg"; _dlg = uiNamespace getVariable QGVAR(dlgDisableMouse); _dlg displayAddEventHandler ["KeyDown", { - private ["_key", "_dlg", "_ctrl", "_config", "_acc", "_index"]; - _key = _this select 1; + params ["", "_key"]; if (_key == 1 && {alive player}) then { createDialog (["RscDisplayInterrupt", "RscDisplayMPInterrupt"] select isMultiplayer); disableSerialization; + + private ["_dlg", "_ctrl"]; + _dlg = finddisplay 49; _dlg displayAddEventHandler ["KeyDown", { - _key = _this select 1; + params ["", "_key"]; !(_key == 1) }]; @@ -62,19 +62,21 @@ if (_state) then { _ctrl = _dlg displayctrl ([104, 1010] select isMultiplayer); _ctrl ctrlSetEventHandler ["buttonClick", QUOTE(closeDialog 0; player setDamage 1; [false] call DFUNC(disableUserInput);)]; - _ctrl ctrlEnable (call {_config = missionConfigFile >> "respawnButton"; !isNumber _config || {getNumber _config == 1}}); + _ctrl ctrlEnable (call {private "_config"; _config = missionConfigFile >> "respawnButton"; !isNumber _config || {getNumber _config == 1}}); _ctrl ctrlSetText "RESPAWN"; _ctrl ctrlSetTooltip "Respawn."; }; if (_key in actionKeys "TeamSwitch" && {teamSwitchEnabled}) then { (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) closeDisplay 0; + + private "_acc"; _acc = accTime; teamSwitch; setAccTime _acc; }; - if (_key in actionKeys "CuratorInterface" && {getAssignedCuratorLogic player in allCurators}) then { + if (_key in actionKeys "CuratorInterface" && {getAssignedCuratorLogic player in allCurators}) then { (uiNamespace getVariable [QGVAR(dlgDisableMouse), displayNull]) closeDisplay 0; openCuratorInterface; }; diff --git a/addons/common/functions/fnc_displayTextPicture.sqf b/addons/common/functions/fnc_displayTextPicture.sqf index 93d4d38df7..3bdf908d16 100644 --- a/addons/common/functions/fnc_displayTextPicture.sqf +++ b/addons/common/functions/fnc_displayTextPicture.sqf @@ -1,25 +1,21 @@ /* * Author: commy2, Glowbal - * * Display a structured text with image. * - * Argument: + * Arguments: * 0: Text * 1: Image - * 2: Image color - * 3: Target Unit. Will only display if target is the player controlled object + * 2: Image color (default: [0, 0, 0, 0]) + * 3: Target Unit. Will only display if target is the player controlled object (default: ACE_player) * - * Return value: - * Nothing + * Return Value: + * None + * + * Public: Yes */ - #include "script_component.hpp" -private ["_imageColor", "_target"]; -PARAMS_2(_text,_image); -_imageColor = if (count _this > 2) then {_this select 2} else {[1,1,1]}; -_imageColor resize 3; -_target = if (count _this > 3) then {_this select 3} else {ACE_player}; +params ["_text", "_image", ["_imageColor", [1,1,1]], ["_target", ACE_player]]; if (_target != ACE_player) exitWith {}; @@ -28,16 +24,21 @@ if (typeName _text != "TEXT") then { if (count _text > 0) then { { if (typeName _x == "STRING" && {isLocalized _x}) then { - _text set [_foreachIndex, localize _x]; + _text set [_forEachIndex, localize _x]; }; - }foreach _text; + } forEach _text; + _text = format _text; }; }; + if (typeName _text == "STRING" && {isLocalized _text}) then { _text = localize _text; }; + _text = parseText format ["%1", _text]; }; + _text = composeText [parseText format ["", _image, _imageColor call BIS_fnc_colorRGBtoHTML], lineBreak, _text]; + [_text, 2] call FUNC(displayTextStructured); diff --git a/addons/common/functions/fnc_displayTextStructured.sqf b/addons/common/functions/fnc_displayTextStructured.sqf index cfe2feb3cb..255a014b6f 100644 --- a/addons/common/functions/fnc_displayTextStructured.sqf +++ b/addons/common/functions/fnc_displayTextStructured.sqf @@ -1,23 +1,20 @@ /* * Author: commy2, Glowbal - * * Display a structured text. * - * Argument: + * Arguments: * 0: Text - * 1: Size of the textbox - * 2: Target Unit. Will only display if target is the player controlled object + * 1: Size of the textbox (default: 1.5) + * 2: Target Unit. Will only display if target is the player controlled object (default: ACE_player) * - * Return value: - * Nothing + * Return Value: + * None + * + * Public: Yes */ - #include "script_component.hpp" -private ["_text", "_size", "_isShown", "_ctrlHint", "_yPos", "_xPos", "_wPos", "_hPos", "_position", "_target"]; -_text = _this select 0; -_size = if (count _this > 1) then {_this select 1} else {1.5;}; -_target = if (count _this > 2) then {_this select 2} else {ACE_player}; +params ["_text", ["_size", 1.5], ["_target", ACE_player]]; if (_target != ACE_player) exitWith {}; @@ -38,6 +35,8 @@ if (typeName _text != "TEXT") then { _text = composeText [lineBreak, parseText format ["%1", _text]]; }; +private ["_isShown", "_ctrlHint", "_xPos", "_yPos", "_wPos", "_hPos", "_position"]; + _isShown = ctrlShown (uiNamespace getVariable ["ACE_ctrlHint", controlNull]); ("ACE_RscHint" call BIS_fnc_rscLayer) cutRsc ["ACE_RscHint", "PLAIN", 0, true]; @@ -60,8 +59,8 @@ _yPos = safeZoneY + 0.175 * safezoneH; _wPos = (10 *(((safezoneW / safezoneH) min 1.2) / 40)); _hPos = (2 *((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)); -//Zeus Interface Open and Display would be under the "CREATE" list -if (!isnull curatorCamera) then { +// Zeus Interface Open and Display would be under the "CREATE" list +if (!isNull curatorCamera) then { _xPos = _xPos min ((safezoneX + safezoneW - 12.5 * (((safezoneW / safezoneH) min 1.2) / 40)) - _wPos); }; diff --git a/addons/common/functions/fnc_doAnimation.sqf b/addons/common/functions/fnc_doAnimation.sqf index 5b7a1ed1bf..42d59f0b72 100644 --- a/addons/common/functions/fnc_doAnimation.sqf +++ b/addons/common/functions/fnc_doAnimation.sqf @@ -3,35 +3,22 @@ * * Execute an animation. This is used to not break things like the unconsciousness animation. * - * Argument: - * 0: Unit (Object) - * 1: Animation (String) - * 2: Priority of the animation. (Number, optional default: 0) - * 0: PlayMove - * 1: PlayMoveNow - * 2: SwitchMove (no transitional animation, doesn't overwrite priority 1) + * Arguments: + * 0: Unit + * 1: Animation + * 2: Priority of the animation. (default: 0) + * 0 = PlayMove + * 1 = PlayMoveNow + * 2 = SwitchMove (no transitional animation, doesn't overwrite priority 1) * - * Return value: - * Nothing + * Return Value: + * None + * + * Public: Yes */ #include "script_component.hpp" -private ["_force"]; - -PARAMS_3(_unit,_animation,_priority); -_force = False; - -// no animation given -if (isNil "_animation") exitWith { - ACE_LOGERROR_1("No animation specified in %1.",_fnc_scriptNameParent); -}; - -if (isNil "_priority") then { - _priority = 0; -}; -if (count _this > 3) then { - _force = _this select 3; -}; +params ["_unit", "_animation", ["_priority", 0], ["_force", false]]; // don't overwrite more important animations if (_unit getVariable ["ACE_isUnconscious", false] && {(_animation != "Unconscious")} && {!_force}) exitWith {}; @@ -47,7 +34,7 @@ if (_animation == "") then { //if (_animation == animationState _unit) exitWith {}; switch (_priority) do { - case 0 : { + case 0: { if (_unit == vehicle _unit) then { [_unit, format ["{_this playMove '%1'}", _animation], _unit] call FUNC(execRemoteFnc); } else { @@ -55,7 +42,7 @@ switch (_priority) do { [_unit, format ["{_this playMove '%1'}", _animation]] call FUNC(execRemoteFnc); }; }; - case 1 : { + case 1: { if (_unit == vehicle _unit) then { [_unit, format ["{_this playMoveNow '%1'}", _animation], _unit] call FUNC(execRemoteFnc); } else { @@ -63,7 +50,7 @@ switch (_priority) do { [_unit, format ["{_this playMoveNow '%1'}", _animation]] call FUNC(execRemoteFnc); }; }; - case 2 : { + case 2: { // try playMoveNow first if (_unit == vehicle _unit) then { [_unit, format ["{_this playMoveNow '%1'}", _animation], _unit] call FUNC(execRemoteFnc); @@ -80,5 +67,3 @@ switch (_priority) do { }; default {}; }; - -["Anim", [_priority, _animation]] call FUNC(log); diff --git a/addons/common/functions/fnc_dropBackpack.sqf b/addons/common/functions/fnc_dropBackpack.sqf index 05ee3ab750..fc2b0bba64 100644 --- a/addons/common/functions/fnc_dropBackpack.sqf +++ b/addons/common/functions/fnc_dropBackpack.sqf @@ -1,30 +1,24 @@ /* * Author: commy2 - * * Drops a backback. Also returns the ground wepaon holder object of the dropped backpack. * - * Argument: - * 0: Unit that has a backpack (Object) + * Arguments: + * 0: Unit that has a backpack * * Return value: - * Ground wepaon holder with backpack (Object) + * Ground wepaon holder with backpack * + * Public: Yes */ #include "script_component.hpp" -PARAMS_1(_unit); +params ["_unit"]; -private ["_backpackObject","_holder"]; +private ["_backpackObject", "_holder"]; _backpackObject = backpackContainer _unit; + _unit addBackpack "Bag_Base"; removeBackpack _unit; -_holder = objNull; -{ - if (_backpackObject in everyBackpack _x) exitWith { - _holder = _x; - }; -} forEach (position _unit nearObjects ["WeaponHolder", 5]); - -_holder +objectParent _backpackObject // return diff --git a/addons/common/functions/fnc_dumpArray.sqf b/addons/common/functions/fnc_dumpArray.sqf index 8572aaf134..e07da9f695 100644 --- a/addons/common/functions/fnc_dumpArray.sqf +++ b/addons/common/functions/fnc_dumpArray.sqf @@ -1,10 +1,21 @@ -//fnc_dumpArray.sqf +/* + * Author: ? + * ? + * + * Arguments: + * 0: Array to be dumped + * 1: Depth + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" -private ["_pad", "_i", "_x"]; - -PARAMS_2(_var,_depth); +params ["_var", "_depth"]; +private "_pad"; _pad = ""; for "_i" from 0 to _depth do { @@ -14,11 +25,14 @@ for "_i" from 0 to _depth do { _depth = _depth + 1; if (IS_ARRAY(_var)) then { - if ((count _var) > 0) then { + if (count _var > 0) then { diag_log text format["%1[", _pad]; + { [_x, _depth] call FUNC(dumpArray); - } forEach _var; + false + } count _var; + diag_log text format["%1],", _pad]; } else { diag_log text format["%1[],", _pad]; diff --git a/addons/common/functions/fnc_dumpPerformanceCounters.sqf b/addons/common/functions/fnc_dumpPerformanceCounters.sqf index 0c3d6c8e78..7845aaf95d 100644 --- a/addons/common/functions/fnc_dumpPerformanceCounters.sqf +++ b/addons/common/functions/fnc_dumpPerformanceCounters.sqf @@ -1,49 +1,68 @@ -//fnc_dumpPerformanceCounters.sqf -#define DEBUG_MODE_FULL +/* + * Author: ? + * Dumps performance counter statistics into Logs. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public: No + */ #include "script_component.hpp" - diag_log text format["REGISTERED ACE PFH HANDLERS"]; diag_log text format["-------------------------------------------"]; + if (!isNil "ACE_PFH_COUNTER") then { { - private ["_isActive"]; _x params ["_pfh", "_parameters"]; - _isActive = if (!isNil {cba_common_PFHhandles select (_pfh select 0)}) then {"ACTIVE"} else {"REMOVED"}; - diag_log text format["Registered PFH: id=%1 [%2, delay %3], %4:%5", (_pfh select 0), (_isActive), (_parameters select 1), (_pfh select 1), (_pfh select 2) ]; - } forEach ACE_PFH_COUNTER; + + private "_isActive"; + _isActive = ["ACTIVE", "REMOVED"] select isNil {CBA_common_PFHhandles select (_pfh select 0)} + + diag_log text format ["Registered PFH: id=%1 [%2, delay %3], %4:%5", _pfh select 0, _isActive, _parameters select 1, _pfh select 1, _pfh select 2]; + false + } count ACE_PFH_COUNTER; }; -diag_log text format["ACE COUNTER RESULTS"]; -diag_log text format["-------------------------------------------"]; +diag_log text format ["ACE COUNTER RESULTS"]; +diag_log text format ["-------------------------------------------"]; + { - private ["_counterEntry", "_iter", "_total", "_count", "_delta", "_averageResult"]; + private ["_counterEntry", "_iter", "_total", "_count", "_averageResult", "_delta"]; + _counterEntry = _x; _iter = 0; _total = 0; _count = 0; _averageResult = 0; - if( (count _counterEntry) > 3) then { + + if (count _counterEntry > 3) then { // calc { - if(_iter > 2) then { + if (_iter > 2) then { _count = _count + 1; _delta = (_x select 1) - (_x select 0); _total = _total + _delta; }; + _iter = _iter + 1; - } forEach _counterEntry; - + false + } count _counterEntry; + // results _averageResult = (_total / _count) * 1000; - + // dump results - diag_log text format["%1: Average: %2s / %3 = %4ms", (_counterEntry select 0), _total, _count, _averageResult]; + diag_log text format ["%1: Average: %2s / %3 = %4ms", _counterEntry select 0, _total, _count, _averageResult]; } else { - diag_log text format["%1: No results", (_counterEntry select 0) ]; + diag_log text format ["%1: No results", _counterEntry select 0]; }; -} forEach ACE_COUNTERS; + false +} count ACE_COUNTERS; /* // Dump PFH Trackers @@ -71,4 +90,4 @@ diag_log text format["-------------------------------------------"]; // //} forEach ACRE_EXCESSIVE_FRAME_TRACKER; -*/ \ No newline at end of file +*/ From 5fd1938f25efb1d2b202544445d05f80bfbf66f4 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 20 Sep 2015 22:29:38 +0200 Subject: [PATCH 07/29] more common code cleanup --- addons/common/functions/fnc__handleNetEvent.sqf | 3 ++- .../fnc__handleRequestAllSyncedEvents.sqf | 3 ++- .../functions/fnc__handleRequestSyncedEvent.sqf | 3 ++- addons/common/functions/fnc_ambientBrightness.sqf | 1 - .../common/functions/fnc_applyForceWalkStatus.sqf | 4 ++-- .../common/functions/fnc_assignObjectsInList.sqf | 15 +++++++++------ addons/common/functions/fnc_blurScreen.sqf | 1 - addons/common/functions/fnc_canGetInPosition.sqf | 1 - addons/common/functions/fnc_claim.sqf | 1 + addons/common/functions/fnc_currentChannel.sqf | 1 - addons/common/functions/fnc_debugModule.sqf | 2 +- 11 files changed, 19 insertions(+), 16 deletions(-) diff --git a/addons/common/functions/fnc__handleNetEvent.sqf b/addons/common/functions/fnc__handleNetEvent.sqf index 90cf95ac77..e409afe6a3 100644 --- a/addons/common/functions/fnc__handleNetEvent.sqf +++ b/addons/common/functions/fnc__handleNetEvent.sqf @@ -80,6 +80,7 @@ if (_eventType == "ACEc") then { ["ACEg", ACEg] call FUNC(_handleNetEvent); }; }; - } forEach _eventTargets; + false + } count _eventTargets; }; }; diff --git a/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf b/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf index fbaeb60e4f..4e755562b5 100644 --- a/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf +++ b/addons/common/functions/fnc__handleRequestAllSyncedEvents.sqf @@ -21,6 +21,7 @@ params ["_client"]; _eventLog = _eventEntry select 1; ["SEH_s", _client, [_x, _eventLog]] call FUNC(targetEvent); -} forEach (GVAR(syncedEvents) select 0); + false +} count (GVAR(syncedEvents) select 0); true diff --git a/addons/common/functions/fnc__handleRequestSyncedEvent.sqf b/addons/common/functions/fnc__handleRequestSyncedEvent.sqf index 96cd7a51f5..d4d9b2cf76 100644 --- a/addons/common/functions/fnc__handleRequestSyncedEvent.sqf +++ b/addons/common/functions/fnc__handleRequestSyncedEvent.sqf @@ -41,7 +41,8 @@ if (isServer) then { { _x params ["", "_eventArgs","_ttl"]; [_eventName, _eventArgs, _ttl] call FUNC(_handleSyncedEvent); - } forEach _eventLog; + false + } count _eventLog; ACE_LOGINFO_1("[%1] synchronized",_eventName); }; diff --git a/addons/common/functions/fnc_ambientBrightness.sqf b/addons/common/functions/fnc_ambientBrightness.sqf index 86aef99b0c..4ec2840e47 100644 --- a/addons/common/functions/fnc_ambientBrightness.sqf +++ b/addons/common/functions/fnc_ambientBrightness.sqf @@ -1,6 +1,5 @@ /* * Author: commy2, idea by Falke - * * Returns a brightness value depending on the sun and moon state. Ranges from 0 to 1 (dark ... bright). * * Arguments: diff --git a/addons/common/functions/fnc_applyForceWalkStatus.sqf b/addons/common/functions/fnc_applyForceWalkStatus.sqf index 82fbd9da3a..d3b58a25a4 100644 --- a/addons/common/functions/fnc_applyForceWalkStatus.sqf +++ b/addons/common/functions/fnc_applyForceWalkStatus.sqf @@ -9,10 +9,10 @@ * None * * Example: - * [ACE_Player] call FUNC(applyForceWalkStatus) + * [ACE_Player] call ace_common_fnc_applyForceWalkStatus * * Public: No -*/ + */ #include "script_component.hpp" params ["_unit"]; diff --git a/addons/common/functions/fnc_assignObjectsInList.sqf b/addons/common/functions/fnc_assignObjectsInList.sqf index 0d10066d01..6bbb31d2dc 100644 --- a/addons/common/functions/fnc_assignObjectsInList.sqf +++ b/addons/common/functions/fnc_assignObjectsInList.sqf @@ -14,37 +14,40 @@ * * Public: No */ - #include "script_component.hpp" -private ["_splittedList", "_nilCheckPassedList"]; params ["_list", "_variable", "_setting", "_global"]; if (typeName _list == "STRING") then { + private ["_splittedList", "_nilCheckPassedList"]; + _splittedList = [_list, ","] call BIS_fnc_splitString; _nilCheckPassedList = ""; + { _x = [_x] call FUNC(stringRemoveWhiteSpace); - if !(isnil _x) then { + if !(isNil _x) then { if (_nilCheckPassedList == "") then { _nilCheckPassedList = _x; } else { _nilCheckPassedList = _nilCheckPassedList + ","+ _x; }; }; - }foreach _splittedList; + false + } count _splittedList; _list = [] call compile format["[%1]",_nilCheckPassedList]; }; { - if (!isnil "_x") then { + if (!isNil "_x") then { if (typeName _x == typeName objNull) then { if (local _x) then { _x setvariable [_variable, _setting, _global]; }; }; }; -}foreach _list; + false +} count _list; true diff --git a/addons/common/functions/fnc_blurScreen.sqf b/addons/common/functions/fnc_blurScreen.sqf index 8136d1476c..a3394a1fbf 100644 --- a/addons/common/functions/fnc_blurScreen.sqf +++ b/addons/common/functions/fnc_blurScreen.sqf @@ -10,7 +10,6 @@ * * Public: Yes */ - #include "script_component.hpp" if (!hasInterface) exitWith {}; diff --git a/addons/common/functions/fnc_canGetInPosition.sqf b/addons/common/functions/fnc_canGetInPosition.sqf index 40724569d0..45a2642655 100644 --- a/addons/common/functions/fnc_canGetInPosition.sqf +++ b/addons/common/functions/fnc_canGetInPosition.sqf @@ -1,6 +1,5 @@ /* * Author: commy2 - * * Is the unit able to enter the vehicle in the given position? * * Arguments: diff --git a/addons/common/functions/fnc_claim.sqf b/addons/common/functions/fnc_claim.sqf index 9a5b373fa5..ac89a80172 100644 --- a/addons/common/functions/fnc_claim.sqf +++ b/addons/common/functions/fnc_claim.sqf @@ -10,6 +10,7 @@ * Return Value: * None * + * Public: No */ #include "script_component.hpp" diff --git a/addons/common/functions/fnc_currentChannel.sqf b/addons/common/functions/fnc_currentChannel.sqf index 52aed1f4ce..82dd66b485 100644 --- a/addons/common/functions/fnc_currentChannel.sqf +++ b/addons/common/functions/fnc_currentChannel.sqf @@ -1,6 +1,5 @@ /* * Author: commy2 - * * Returns the current radio / chat / marker channel. * * Arguments: diff --git a/addons/common/functions/fnc_debugModule.sqf b/addons/common/functions/fnc_debugModule.sqf index d313244e52..4f3da4d7cb 100644 --- a/addons/common/functions/fnc_debugModule.sqf +++ b/addons/common/functions/fnc_debugModule.sqf @@ -1,5 +1,6 @@ /* * Author: Glowbal + * ? * * Arguments: * None @@ -9,7 +10,6 @@ * * Public: No */ - #include "script_component.hpp" params ["_entity"]; From 62ec00a2518b8a9c47987502b5c961207f0359d6 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 20 Sep 2015 22:36:05 +0200 Subject: [PATCH 08/29] more common code cleanup --- addons/common/functions/fnc_addCanInteractWithCondition.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/common/functions/fnc_addCanInteractWithCondition.sqf b/addons/common/functions/fnc_addCanInteractWithCondition.sqf index 11213accd6..740fa9bb9f 100644 --- a/addons/common/functions/fnc_addCanInteractWithCondition.sqf +++ b/addons/common/functions/fnc_addCanInteractWithCondition.sqf @@ -17,11 +17,11 @@ params ["_conditionName", "_conditionFunc"]; _conditionName = toLower _conditionName; -private "_conditions"; +private ["_conditions", "_index"]; + _conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]]; _conditions params ["_conditionNames", "_conditionFuncs"]; -private "_index"; _index = _conditionNames find _conditionName; if (_index == -1) then { From a98a45e5d161d73535905bfb8e53b1db0bd7197b Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 20 Sep 2015 23:18:51 +0200 Subject: [PATCH 09/29] 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 From ffc5a1638445f574c96807aa3df5d812ddb52494 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 20 Sep 2015 23:40:51 +0200 Subject: [PATCH 10/29] more common code cleanup --- .../fnc_getAllDefinedSetVariables.sqf | 46 +++++++++++-------- .../functions/fnc_getTurretConfigPath.sqf | 21 +++++---- .../functions/fnc_getTurretDirection.sqf | 38 +++++++++------ .../common/functions/fnc_getTurretIndex.sqf | 20 ++++---- addons/common/functions/fnc_getTurrets.sqf | 30 +++++++----- 5 files changed, 95 insertions(+), 60 deletions(-) diff --git a/addons/common/functions/fnc_getAllDefinedSetVariables.sqf b/addons/common/functions/fnc_getAllDefinedSetVariables.sqf index 2163accae2..18c8a18c72 100644 --- a/addons/common/functions/fnc_getAllDefinedSetVariables.sqf +++ b/addons/common/functions/fnc_getAllDefinedSetVariables.sqf @@ -1,30 +1,40 @@ -/** - * fn_getAllSetVariables.sqf - * @Descr: Returns an 2d array of all variables that have been set on the object - * @Author: Glowbal +/* + * Author: Glowbal + * Returns an 2d array of all variables that have been set on the object * - * @Arguments: [unit OBJECT, category STRING (Optional. Only get the variables from the specified category. Default is "" == all)] - * @Return: ARRAY REturns an array with the format [ [name STRING, typeName STRING, value ANY, publicFlag BOOL, peristentFlag BOOL] ] - * @PublicAPI: true + * Arguments: + * 0: Unit + * 1: Limiting Category (default: "") + * + * Return Value: + * Variable Data + * 0: Name + * 1: typeName + * 2: value + * 3: publicFlag + * 4: peristentFlag + * + * Public: Yes */ - #include "script_component.hpp" -private ["_return", "_val", "_category"]; -PARAMS_1(_object); -_category = if (count _this > 1) then { _this select 1 } else { "" }; +params ["_object", ["_category", ""]]; -if (isnil QGVAR(OBJECT_VARIABLES_STORAGE)) exitwith { - []; -}; +if (isNil QGVAR(OBJECT_VARIABLES_STORAGE)) exitwith {[]}; + +private ["_return", "_val"]; _return = []; + { _val = _object getvariable (_x select 0); - if (!isnil "_val") then { + + if (!isNil "_val") then { if (_category == "" || _category == _x select 3) then { - _return pushback [_x select 0, typeName _val, _val, _x select 2, _x select 5]; + _return pushBack [_x select 0, typeName _val, _val, _x select 2, _x select 5]; }; }; -}foreach GVAR(OBJECT_VARIABLES_STORAGE); -_return \ No newline at end of file + false +} count GVAR(OBJECT_VARIABLES_STORAGE); + +_return diff --git a/addons/common/functions/fnc_getTurretConfigPath.sqf b/addons/common/functions/fnc_getTurretConfigPath.sqf index 1fca65eaac..07d7ac4e0c 100644 --- a/addons/common/functions/fnc_getTurretConfigPath.sqf +++ b/addons/common/functions/fnc_getTurretConfigPath.sqf @@ -1,28 +1,29 @@ /* * Author: commy2 - * * Get the config path of a vehicles turret. * - * Argument: - * 0: vehicles config (Config) - * 1: Turret index (Array) + * Arguments: + * 0: Vehicle Config + * 1: Turret indecies * - * Return value: - * Turret config (Config) + * Return Value: + * Turret config + * + * Public: Yes */ #include "script_component.hpp" -private ["_index", "_offset", "_config2", "_foundClasses", "_a"]; +params ["_config", "_turretIndex"]; -PARAMS_2(_config,_turretIndex); +private ["_offset", "_config2", "_foundClasses"]; for "_index" from 0 to (count _turretIndex - 1) do { _config = _config >> "Turrets"; _offset = 0; _config2 = _config select 0; - _foundClasses = 0; + for "_a" from 0 to (count _config - 1) do { if (isClass _config2) then { _foundClasses = _foundClasses + 1; @@ -33,6 +34,8 @@ for "_index" from 0 to (count _turretIndex - 1) do { if (_foundClasses == _turretIndex select _index) exitWith {}; }; + _config = _config2; }; + _config diff --git a/addons/common/functions/fnc_getTurretDirection.sqf b/addons/common/functions/fnc_getTurretDirection.sqf index 31b68ccabc..ced29a9a85 100644 --- a/addons/common/functions/fnc_getTurretDirection.sqf +++ b/addons/common/functions/fnc_getTurretDirection.sqf @@ -1,37 +1,47 @@ /* * Author: jaynus - * * Get the absolute turret direction for FOV/PIP turret. * - * Argument: - * 0: Vehicle (Object) - * 1: Turret Position + * Arguments: + * 0: Vehicle + * 1: Turret Position * - * Return value: - * [position, direction] + * Return Value: + * 0: Position ASL + * 1: Direction + * + * Public: Yes */ #include "script_component.hpp" -PARAMS_2(_vehicle,_position); -private ["_turret", "_povPos", "_povDir", "_gunBeginPos", "_gunEndPos", "_pov", "_gunBeg", "_gunEnd", "_pipDir"]; +params ["_vehicle", "_position"]; + +private ["_turret", "_pov", "_gunBeg", "_gunEnd", "_povPos", "_povDir"]; _turret = [_vehicle, _position] call CBA_fnc_getTurret; + _pov = getText (_turret >> "memoryPointGunnerOptics"); _gunBeg = getText (_turret >> "gunBeg"); -_gunEnd = getText (_turret >> "gunEnd"); +_gunEnd = getText (_turret >> "gunEnd"); + TRACE_3("", _pov, _gunBeg, _gunEnd); // Pull the PIP pov or barrel direction, depending on how the model is set up -_povPos = ATLtoASL ( _vehicle modelToWorldVisual (_vehicle selectionPosition _pov ) ); +_povPos = ATLtoASL (_vehicle modelToWorldVisual (_vehicle selectionPosition _pov)); //@todo AGLToASL ? _povDir = [0,0,0]; if (_pov == "pip0_pos") then { - _pipDir = ATLtoASL ( _vehicle modelToWorldVisual (_vehicle selectionPosition "pip0_dir" ) ); + private "_pipDir"; + _pipDir = ATLtoASL (_vehicle modelToWorldVisual (_vehicle selectionPosition "pip0_dir")); + _povDir = _pipDir vectorDiff _povPos; } else { - _gunBeginPos = ATLtoASL ( _vehicle modelToWorldVisual (_vehicle selectionPosition _gunBeg ) ); - _gunEndPos = ATLtoASL ( _vehicle modelToWorldVisual (_vehicle selectionPosition _gunEnd ) ); + private ["_gunBeginPos", "_gunEndPos"]; + + _gunBeginPos = ATLtoASL (_vehicle modelToWorldVisual (_vehicle selectionPosition _gunBeg)); + _gunEndPos = ATLtoASL (_vehicle modelToWorldVisual (_vehicle selectionPosition _gunEnd)); + _povDir = _gunBeginPos vectorDiff _gunEndPos; }; -[_povPos, _povDir] \ No newline at end of file +[_povPos, _povDir] diff --git a/addons/common/functions/fnc_getTurretIndex.sqf b/addons/common/functions/fnc_getTurretIndex.sqf index bfb96b4665..b2f28c5f90 100644 --- a/addons/common/functions/fnc_getTurretIndex.sqf +++ b/addons/common/functions/fnc_getTurretIndex.sqf @@ -1,19 +1,21 @@ /* * Author: commy2 - * * Get the turret index of a units current turret. * - * Argument: - * 0: Unit, not the vehicle (as in not a car but the player) (Object) + * Arguments: + * 0: Unit * - * Return value: - * Turret index array or config path. E.g: [0] for gunner or [0,0] for commander. Returns empty array if unit is not in a turret. (Array) + * Return Value: + * Turret Index + * + * Public: Yes */ #include "script_component.hpp" +params ["_unit"]; + private ["_vehicle", "_turrets", "_units", "_index"]; -PARAMS_1(_unit); _vehicle = vehicle _unit; if (_unit == _vehicle) exitWith {[]}; @@ -21,9 +23,11 @@ if (_unit == _vehicle) exitWith {[]}; _turrets = allTurrets [_vehicle, true]; _units = []; + { - _units pushBack (_vehicle turretUnit _x); -} forEach _turrets; + _units pushBack (_vehicle turretUnit _x); + false +} count _turrets; _index = _units find _unit; diff --git a/addons/common/functions/fnc_getTurrets.sqf b/addons/common/functions/fnc_getTurrets.sqf index ea656941e4..9a1a48e2bd 100644 --- a/addons/common/functions/fnc_getTurrets.sqf +++ b/addons/common/functions/fnc_getTurrets.sqf @@ -1,37 +1,45 @@ /* * Author: commy2 + * Get all turret indicies of a vehicle type. * - * Get all turret indicies of a vehicle. + * Arguments: + * 0: Vehicle type * - * Argument: - * 0: Vehicle type (String) + * Return Value: + * Turret Indecies * - * Return value: - * All turret index arrays of the vehicle. E.g: [[0], [0,0]] (Array) + * Public: Yes + * + * Note: It's advised to use allTurrets [_vehicle, true] instead whenever possible */ #include "script_component.hpp" -private ["_config", "_turrets", "_fnc_addTurret", "_varName"]; +params ["_type"]; -PARAMS_1(_type); +private ["_varName", "_turrets"]; -_varName = format ["ACE_CachedTurrets_%1", _type]; +_varName = format [QGVAR(CachedTurrets_%1), _type]; _turrets = + (uiNamespace getVariable _varName); if (!isNil "_turrets") exitWith {_turrets}; +private ["_config", "_fnc_addTurret"]; + _config = configFile >> "CfgVehicles" >> _type; _turrets = []; -_fnc_addTurret = { - private ["_count", "_offset", "_index", "_path2", "_config2"]; - PARAMS_2(_config,_path); +_fnc_addTurret = { + params ["_config", "_path"]; _config = _config >> "Turrets"; + + private ["_count", "_offset", "_path2", "_config2"]; + _count = count _config; _offset = 0; + for "_index" from 0 to (_count - 1) do { _path2 = _path + [_index - _offset]; _config2 = _config select _index; From 1d4eb209a46af0003c589ff9aef121c78e72b1e1 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 20 Sep 2015 23:50:30 +0200 Subject: [PATCH 11/29] fix missing ; in dumpPerformanceCounters --- addons/common/functions/fnc_dumpPerformanceCounters.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/functions/fnc_dumpPerformanceCounters.sqf b/addons/common/functions/fnc_dumpPerformanceCounters.sqf index 7845aaf95d..d23e3428db 100644 --- a/addons/common/functions/fnc_dumpPerformanceCounters.sqf +++ b/addons/common/functions/fnc_dumpPerformanceCounters.sqf @@ -20,7 +20,7 @@ if (!isNil "ACE_PFH_COUNTER") then { _x params ["_pfh", "_parameters"]; private "_isActive"; - _isActive = ["ACTIVE", "REMOVED"] select isNil {CBA_common_PFHhandles select (_pfh select 0)} + _isActive = ["ACTIVE", "REMOVED"] select isNil {CBA_common_PFHhandles select (_pfh select 0)}; diag_log text format ["Registered PFH: id=%1 [%2, delay %3], %4:%5", _pfh select 0, _isActive, _parameters select 1, _pfh select 1, _pfh select 2]; false From 1679235b5152b110106b3ac1c9386f34489573b9 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 00:28:25 +0200 Subject: [PATCH 12/29] more common code cleanup --- addons/common/functions/fnc_getDeathAnim.sqf | 23 ++++++----- .../common/functions/fnc_getDefaultAnim.sqf | 40 ++++++++++++++----- .../functions/fnc_getDefinedVariable.sqf | 39 ++++++++++-------- .../fnc_getDefinedVariableDefault.sqf | 27 ++++++++----- .../functions/fnc_getDefinedVariableInfo.sqf | 23 ++++++----- .../functions/fnc_getDisplayConfigName.sqf | 28 ++++++++++--- .../common/functions/fnc_getDoorTurrets.sqf | 21 +++++----- addons/common/functions/fnc_globalEvent.sqf | 1 - 8 files changed, 128 insertions(+), 74 deletions(-) diff --git a/addons/common/functions/fnc_getDeathAnim.sqf b/addons/common/functions/fnc_getDeathAnim.sqf index 539c8d2616..c88f89d35f 100644 --- a/addons/common/functions/fnc_getDeathAnim.sqf +++ b/addons/common/functions/fnc_getDeathAnim.sqf @@ -9,35 +9,38 @@ * animation * * Example: - * [bob] call ace_common_fnc_getDeathAnim; + * [bob] call ace_common_fnc_getDeathAnim * * Public: No */ #include "script_component.hpp" -PARAMS_1(_unit); +params ["_unit"]; -private ["_returnAnimation", "_animationState", "_unitAnimationCfg", "_unitActionsCfg", "_interpolateArray", "_indexAnimation", "_index"]; +private ["_returnAnimation", "_animationState", "_unitAnimationCfg", "_unitActionsCfg", "_interpolateArray", "_indexAnimation"]; _returnAnimation = ""; -_animationState = (animationState _unit); -_unitAnimationCfg = (configFile >> "CfgMovesMaleSdr" >> "States" >> _animationState); -//If we're already in a terminal animation just return current -if ((getNumber (_unitAnimationCfg >> "terminal")) == 1) exitWith {_animationState}; +_animationState = animationState _unit; +_unitAnimationCfg = configFile >> "CfgMovesMaleSdr" >> "States" >> _animationState; -_unitActionsCfg = (configFile >> "CfgMovesBasic" >> "Actions" >> (getText (_unitAnimationCfg >> "actions"))); +//If we're already in a terminal animation just return current +if (getNumber (_unitAnimationCfg >> "terminal") == 1) exitWith {_animationState}; + +_unitActionsCfg = configFile >> "CfgMovesBasic" >> "Actions" >> getText (_unitAnimationCfg >> "actions"); TRACE_2("Animation/Action", configName _unitAnimationCfg, configName _unitActionsCfg); -if ((vehicle _unit) != _unit) then { +if (vehicle _unit != _unit) then { _interpolateArray = getArray (_unitAnimationCfg >> "interpolateTo"); + for "_index" from 0 to (count _interpolateArray - 1) step 2 do { _indexAnimation = _interpolateArray select _index; + //No guarentee that first animation will be right so scan for the first "terminal" animation //E.G.: interpolateTo[] = {"passenger_apc_generic04still",1,"KIA_passenger_apc_generic04",1}; - if ((getNumber ((configFile >> "CfgMovesMaleSdr" >> "States" >> _indexAnimation) >> "terminal")) == 1) exitWith { + if (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> _indexAnimation >> "terminal") == 1) exitWith { _returnAnimation = _indexAnimation; }; }; diff --git a/addons/common/functions/fnc_getDefaultAnim.sqf b/addons/common/functions/fnc_getDefaultAnim.sqf index fbcca2712e..372a2424eb 100644 --- a/addons/common/functions/fnc_getDefaultAnim.sqf +++ b/addons/common/functions/fnc_getDefaultAnim.sqf @@ -1,29 +1,47 @@ -// by commy2 +/* + * Author: commy2 + * Get the Defualt animation for the unit + * + * Arguments: + * 0: unit + * + * Return Value: + * animation + * + * Example: + * [bob] call ace_common_fnc_getDefaultAnim; + * + * Public: No + */ #include "script_component.hpp" +params ["_unit"]; + private ["_anim", "_stance"]; -PARAMS_1(_unit); -_anim = toLower (animationState _unit); +_anim = toLower animationState _unit; // stance is broken for some animations. _stance = stance _unit; + if (_anim find "ppne" == 4) then { - _stance = "PRONE"; + _stance = "PRONE"; }; + if (_anim find "pknl" == 4) then { - _stance = "CROUCH"; + _stance = "CROUCH"; }; + if (_anim find "perc" == 4) then { - _stance = "STAND"; + _stance = "STAND"; }; _anim = format ["AmovP%1M%2S%3W%4D%5", - ["erc", "knl", "pne"] select (["STAND", "CROUCH", "PRONE"] find _stance) max 0, - ["stp", "run"] select (vectorMagnitude velocity _unit > 1), - [["ras", "low"] select weaponLowered _unit, "non"] select (currentWeapon _unit == ""), - ["non", "rfl", "lnr", "pst", "bin"] select (["", primaryWeapon _unit, secondaryWeapon _unit, handgunWeapon _unit, binocular _unit] find currentWeapon _unit) max 0, - ["non", _anim select [count _anim - 1, 1]] select (_anim select [count _anim - 2, 2] in ["df", "db", "dl", "dr"]) + ["erc", "knl", "pne"] select (["STAND", "CROUCH", "PRONE"] find _stance) max 0, + ["stp", "run"] select (vectorMagnitude velocity _unit > 1), + [["ras", "low"] select weaponLowered _unit, "non"] select (currentWeapon _unit == ""), + ["non", "rfl", "lnr", "pst", "bin"] select (["", primaryWeapon _unit, secondaryWeapon _unit, handgunWeapon _unit, binocular _unit] find currentWeapon _unit) max 0, + ["non", _anim select [count _anim - 1, 1]] select (_anim select [count _anim - 2, 2] in ["df", "db", "dl", "dr"]) ]; ["", _anim] select isClass (configFile >> "CfgMovesMaleSdr" >> "States" >> _anim) diff --git a/addons/common/functions/fnc_getDefinedVariable.sqf b/addons/common/functions/fnc_getDefinedVariable.sqf index 6c10c4f682..c0d7ce8d83 100644 --- a/addons/common/functions/fnc_getDefinedVariable.sqf +++ b/addons/common/functions/fnc_getDefinedVariable.sqf @@ -1,33 +1,38 @@ -/** - * fn_getVariable.sqf - * @Descr: Grabs a variable. If variable has not been set, attempts to use default defined value - * @Author: Glowbal +/* + * Author: Glowbal + * Grabs a variable. If variable has not been set, attempts to use default defined value * - * @Arguments: [unit OBJECT, variableName STRING] - * @Return: ANY - * @PublicAPI: true + * Arguments: + * 0: unit + * 1: Variable Name + * + * Return Value: + * Value of variable or default value, if the variable is undefined + * + * Public: No */ - #include "script_component.hpp" -#define UNIT (_this select 0) -#define VARIABLE (_this select 1) +params ["_unit", "_variable", "_defaultValue"]; private "_value"; +_value = _unit getvariable _variable; -_value = UNIT getvariable VARIABLE; -if (isnil "_value") then { - if (count _this >2) then { - _value = _this select 2; +if (isNil "_value") then { + if (!isNil "_defaultValue") then { + _value = _defaultValue; } else { private "_definedVariable"; - _definedVariable = ([VARIABLE] call FUNC(getDefinedVariableInfo)); + _definedVariable = [_variable] call FUNC(getDefinedVariableInfo); + if (count _definedVariable > 1) then { _value = _definedVariable select 1; }; }; - if (isnil "_value") then { + + if (isNil "_value") then { _value = 0; }; }; -_value \ No newline at end of file + +_value diff --git a/addons/common/functions/fnc_getDefinedVariableDefault.sqf b/addons/common/functions/fnc_getDefinedVariableDefault.sqf index cd4e4f08f2..4bb4b12253 100644 --- a/addons/common/functions/fnc_getDefinedVariableDefault.sqf +++ b/addons/common/functions/fnc_getDefinedVariableDefault.sqf @@ -1,19 +1,24 @@ -/** - * fn_getvariableDefault.sqf - * @Descr: Get the variable default value - * @Author: Glowbal +/* + * Author: Glowbal + * Get the variable default value * - * @Arguments: [variableName STRING] - * @Return: ANY - * @PublicAPI: true + * Arguments: + * 0: Variable Name + * + * Return Value: + * Default value of variable + * + * Public: Yes */ - #include "script_component.hpp" +params ["_varName"]; + private "_variableDefinition"; -_variableDefinition = ([_this select 0] call FUNC(getDefinedVariableInfo)); -if (count _variableDefinition > 0) exitwith { +_variableDefinition = [_varName] call FUNC(getDefinedVariableInfo); + +if !(_variableDefinition isEqualTo []) exitwith { _variableDefinition select 1; }; -nil; \ No newline at end of file +nil diff --git a/addons/common/functions/fnc_getDefinedVariableInfo.sqf b/addons/common/functions/fnc_getDefinedVariableInfo.sqf index 03b50b0649..adcb70c6ee 100644 --- a/addons/common/functions/fnc_getDefinedVariableInfo.sqf +++ b/addons/common/functions/fnc_getDefinedVariableInfo.sqf @@ -1,12 +1,17 @@ -/** - * fn_getvariableInfo.sqf - * @Descr: N/A - * @Author: Glowbal +/* + * Author: Glowbal + * Get the variable Informations * - * @Arguments: [] - * @Return: - * @PublicAPI: false + * Arguments: + * 0: Variable Name + * + * Return Value: + * Variable Metadata + * + * Public: No */ - #include "script_component.hpp" -+(missionNamespace getvariable [QGVAR(OBJECT_VARIABLES_STORAGE_) + (_this select 0),[]]) + +params ["_varName"]; + ++ (missionNamespace getVariable [format [QGVAR(OBJECT_VARIABLES_STORAGE_%1), _varName], []]) diff --git a/addons/common/functions/fnc_getDisplayConfigName.sqf b/addons/common/functions/fnc_getDisplayConfigName.sqf index 92b6700238..7a0d9ffa95 100644 --- a/addons/common/functions/fnc_getDisplayConfigName.sqf +++ b/addons/common/functions/fnc_getDisplayConfigName.sqf @@ -1,15 +1,31 @@ -// by commy2 +/* + * Author: commy2 + * Get display classnames from config with given idd. + * + * Arguments: + * 0: Display ID (idd) + * + * Return Value: + * Display Classnames + * + * Public: Yes + * + * Note: Really slow due to iteration through whole config. Meant for debugging. + */ #include "script_component.hpp" -private ["_configName", "_index", "_config"]; +params ["_idd"]; -_configName = ""; +private ["_configNames", "_config"]; + +_configNames = []; for "_index" from 0 to (count configFile - 1) do { _config = configFile select _index; - if (isClass _config && {isNumber (_config >> "idd")} && {getNumber (_config >> "idd") == _this}) exitWith { - _configName = configName _config; + + if (isClass _config && {isNumber (_config >> "idd")} && {getNumber (_config >> "idd") == _idd}) then { + _configNames pushBack configName _config; }; }; -_configName +_configNames diff --git a/addons/common/functions/fnc_getDoorTurrets.sqf b/addons/common/functions/fnc_getDoorTurrets.sqf index f304c1714c..cab259a214 100644 --- a/addons/common/functions/fnc_getDoorTurrets.sqf +++ b/addons/common/functions/fnc_getDoorTurrets.sqf @@ -1,19 +1,20 @@ /* * Author: bux578 + * Returns all turret indecies of door gunners. * - * Gets the turret index of door gunners + * Arguments: + * 0: Vehicle * - * Argument: - * 0: Vehicle (Object) + * Return Value: + * All turret indecies of the Vehicle * - * Return value: - * Turret indexes of the door gunner. Empty array means no gunner position. (Array) + * Public: Yes */ #include "script_component.hpp" -private ["_turrets", "_doorTurrets", "_config"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_turrets", "_doorTurrets", "_config"]; _turrets = allTurrets [_vehicle, true]; @@ -21,11 +22,13 @@ _doorTurrets = []; { _config = configFile >> "CfgVehicles" >> typeOf _vehicle; + _config = [_config, _x] call FUNC(getTurretConfigPath); - if ((getNumber (_config >> "isCopilot") == 0) && count (getArray (_config >> "weapons")) > 0 ) then { + if (getNumber (_config >> "isCopilot" == 0) && {count getArray (_config >> "weapons") > 0}) then { _doorTurrets pushBack _x; }; -} forEach _turrets; + false +} count _turrets; _doorTurrets diff --git a/addons/common/functions/fnc_globalEvent.sqf b/addons/common/functions/fnc_globalEvent.sqf index 9928bc3468..126419b553 100644 --- a/addons/common/functions/fnc_globalEvent.sqf +++ b/addons/common/functions/fnc_globalEvent.sqf @@ -1,6 +1,5 @@ /* * Author: Nou - * * Execute a global event on all clients, including self. * * Arguments: From 5f7d8c0095c4bb4138054ba8ddd5587e312c5aa6 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 00:34:04 +0200 Subject: [PATCH 13/29] more common code cleanup --- addons/common/functions/fnc_dumpArray.sqf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/common/functions/fnc_dumpArray.sqf b/addons/common/functions/fnc_dumpArray.sqf index e07da9f695..7e8128e3ed 100644 --- a/addons/common/functions/fnc_dumpArray.sqf +++ b/addons/common/functions/fnc_dumpArray.sqf @@ -25,7 +25,9 @@ for "_i" from 0 to _depth do { _depth = _depth + 1; if (IS_ARRAY(_var)) then { - if (count _var > 0) then { + if (_var isEqualTo []) then { + diag_log text format["%1[],", _pad]; + } else { diag_log text format["%1[", _pad]; { @@ -34,8 +36,6 @@ if (IS_ARRAY(_var)) then { } count _var; diag_log text format["%1],", _pad]; - } else { - diag_log text format["%1[],", _pad]; }; } else { diag_log text format["%1%2", _pad, [_var] call FUNC(formatVar)]; From fe75aa55cf5c44c203dc5f6b550e1f240fbe6792 Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Mon, 21 Sep 2015 00:39:13 +0200 Subject: [PATCH 14/29] Add missing english string --- addons/common/stringtable.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/common/stringtable.xml b/addons/common/stringtable.xml index e39ef4d7db..8973d1d3e6 100644 --- a/addons/common/stringtable.xml +++ b/addons/common/stringtable.xml @@ -482,7 +482,8 @@ Проверка аддонов - Sprawdzaj spójność addonów z serwerem + Check addon integrity with server and do selected action if an addon is missing. + Sprawdzaj spójność addonów z serwerem i wykonuj stosowną akcję jeżeli zostanie wykryty brak addonu. Este módulo verifica la integridad de los addons con los que iniciamos el simulador Dieses Modul überprüft ob jeder Spieler die richtigen PBO-Dateien hat. Zjistit addon který je v souladu se serverem From 29db26eb580ad385690c710426baa3b1bb4bf821 Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Mon, 21 Sep 2015 00:40:14 +0200 Subject: [PATCH 15/29] Add missing english string --- addons/mk6mortar/stringtable.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/mk6mortar/stringtable.xml b/addons/mk6mortar/stringtable.xml index bd8f99da0d..f1bbef9228 100644 --- a/addons/mk6mortar/stringtable.xml +++ b/addons/mk6mortar/stringtable.xml @@ -127,6 +127,7 @@ Показывает цифровой компас MK6 + This module allows you to setup MK6 mortar settings. Moduł ten pozwala dostosować ustawienia moździerza MK6. Dieses Modul erlaubt das Einstellen des MK6-Mörsers. Tento modul umožňuje nastavení minometu MK6. From 89a1495534afc6f7ceb7b95e2f6e169af4cb0e76 Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Mon, 21 Sep 2015 00:42:08 +0200 Subject: [PATCH 16/29] Add missing english string --- addons/respawn/stringtable.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/respawn/stringtable.xml b/addons/respawn/stringtable.xml index 0406b4caa6..0b4a06ff7f 100644 --- a/addons/respawn/stringtable.xml +++ b/addons/respawn/stringtable.xml @@ -238,6 +238,7 @@ Система точек сбора + This module allows you to use rally points in missions, to which you can quickly teleport from base flag. Requires placing special objects on map - base and flag. Both available in category Empty -> ACE Respawn. Moduł ten pozwala zastosować na misji "punkt zbiórki", do którego można szybko przeteleportować się z "bazy". Wymaga postawienia odpowiednich obiektów na mapie - bazy oraz flagi. Obydwa dostępne są w kategorii Puste -> ACE Odrodzenie. Tento modul umožňuje určit místo shromaždiště, kam se mohou jednokty rychle teleportovat ze "základny". Toto vyžaduje vhodné objekty v mapě - základna a vlajka. Oba dva můžete najít v kategorii Prázdné -> ACE Oživení. Este módulo permite que você aplique em uma missão "pontos de encontro", que pode rapidamente se teletransportar para a "base". Ele requer colocar objetos apropriados no mapa - base e bandeiras. Ambos estão disponíveis na categoria em branco -> ACE Revival. From 5555eb195a4ba33dcf8b321a5f655995f53e84b7 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 20 Sep 2015 17:46:43 -0500 Subject: [PATCH 17/29] Also search for missing stringtable entries --- addons/spectator/stringtable.xml | 2 +- tools/search_undefinedFunctions.py | 90 +++++++++++++++++++----------- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/addons/spectator/stringtable.xml b/addons/spectator/stringtable.xml index fbd3311d52..00d50e4704 100644 --- a/addons/spectator/stringtable.xml +++ b/addons/spectator/stringtable.xml @@ -9,7 +9,7 @@ Nastavení Pozorovatele Ajustes de espectador - + Configure how the spectator system will operate by default. Skonfiguruj domyślne ustawienia obserwatora. Configura como o sistema de espectador operará por padrão. diff --git a/tools/search_undefinedFunctions.py b/tools/search_undefinedFunctions.py index e7c1b8fb34..6d7ec5ae62 100644 --- a/tools/search_undefinedFunctions.py +++ b/tools/search_undefinedFunctions.py @@ -20,11 +20,11 @@ ccb = ctypes.windll.user32.CloseClipboard ga = ctypes.windll.kernel32.GlobalAlloc # Global Memory allocation gl = ctypes.windll.kernel32.GlobalLock # Global Memory Locking gul = ctypes.windll.kernel32.GlobalUnlock -GMEM_DDESHARE = 0x2000 +GMEM_DDESHARE = 0x2000 def Get( ): ocb(None) # Open Clip, Default task - pcontents = gcd(1) # 1 means CF_TEXT.. too lazy to get the token thingy ... + pcontents = gcd(1) # 1 means CF_TEXT.. too lazy to get the token thingy ... data = ctypes.c_char_p(pcontents).value #gul(pcontents) ? ccb() @@ -41,20 +41,10 @@ def Paste( data ): ccb() - def getFunctions(filepath): - selfmodule = (re.search('addons[\W]*([_a-zA-Z0-9]*)', filepath)).group(1) - # print("Checking {0} from {1}".format(filepath,selfmodule)) - - def pushClosing(t): - closingStack.append(closing.expr) - closing << Literal( closingFor[t[0]] ) - - def popClosing(): - closing << closingStack.pop() - + with open(filepath, 'r') as file: content = file.read() @@ -65,16 +55,41 @@ def getFunctions(filepath): srch = re.compile('EFUNC\(([_a-zA-Z0-9]*),([_a-zA-Z0-9]*)\)') exfuncs = srch.findall(content) exfuncs = sorted(set(exfuncs)) - - allFuncs = [] + + fileFuncs = [] for func in modfuncs: - allFuncs.append("ace_{0}_fnc_{1}".format(selfmodule,func)) - + fileFuncs.append("ace_{0}_fnc_{1}".format(selfmodule,func)) + for exModule,func in exfuncs: - allFuncs.append("ace_{0}_fnc_{1}".format(exModule, func)) - - return allFuncs - + fileFuncs.append("ace_{0}_fnc_{1}".format(exModule, func)) + + return fileFuncs + + +def getStrings(filepath): + selfmodule = (re.search('addons[\W]*([_a-zA-Z0-9]*)', filepath)).group(1) + # print("Checking {0} from {1}".format(filepath,selfmodule)) + + with open(filepath, 'r') as file: + content = file.read() + + srch = re.compile('[^E][CL]STRING\(([_a-zA-Z0-9]*)\)') + modfuncs = srch.findall(content) + modfuncs = sorted(set(modfuncs)) + + srch = re.compile('[^E][CL]STRING\(([_a-zA-Z0-9]*)\)') + exfuncs = srch.findall(content) + exfuncs = sorted(set(exfuncs)) + + fileStrings = [] + for func in modfuncs: + fileStrings.append("STR_ACE_{0}_{1}".format(selfmodule,func)) + + # for exModule,func in exfuncs: + # fileStrings.append("STR_ACE_{0}_{1}".format(exModule, func)) + + return fileStrings + def main(): print("#########################") @@ -82,30 +97,39 @@ def main(): print("#########################") sqf_list = [] + allFunctions = [] - + allStrings = [] + parser = argparse.ArgumentParser() parser.add_argument('-m','--module', help='only search specified module addon folder', required=False, default=".") args = parser.parse_args() - + for root, dirnames, filenames in os.walk('../addons' + '/' + args.module): for filename in fnmatch.filter(filenames, '*.sqf'): sqf_list.append(os.path.join(root, filename)) - + for filename in fnmatch.filter(filenames, '*.cpp'): + sqf_list.append(os.path.join(root, filename)) + for filename in fnmatch.filter(filenames, '*.hpp'): + sqf_list.append(os.path.join(root, filename)) + for filename in sqf_list: allFunctions = allFunctions + getFunctions(filename) - - - testCode1 = "diag_log text '*********** Scaning for nil functions [count {0}]';".format(len(set(allFunctions))); - testCode2 = "{ if (isNil _x) then {systemChat format ['%1 is nil', _x]; diag_log text format ['%1 is nil', _x];}} forEach allFunctions;"; - - outputCode = "{0} allFunctions = {1}; {2}".format(testCode1, list(set(allFunctions)), testCode2) - + for filename in sqf_list: + allStrings = allStrings + getStrings(filename) + + + codeHeader = "diag_log text '*********** Scaning for nil functions [funcs {0} / strings {1}]';".format(len(set(allFunctions)), len(set(allStrings))) + codeFuncCheck = "{ if (isNil _x) then {systemChat format ['%1 is nil', _x]; diag_log text format ['%1 is nil', _x];}} forEach allFunctions;" + codeStringCheck = "{ if (!isLocalized _x) then {systemChat format ['%1 is not in stringtable', _x]; diag_log text format ['%1 is not in stringtable', _x];}} forEach allStrings;" + + outputCode = "{0} allFunctions = {1}; allStrings = {2}; {3} {4}".format(codeHeader, list(set(allFunctions)), list(set(allStrings)), codeFuncCheck, codeStringCheck) + print(outputCode) Paste(outputCode); print ("") - print ("Copied to clipboard, total func count {0}".format(len(set(allFunctions)))) - + print ("Copied to clipboard, [funcs {0} / strings {1}]'".format(len(set(allFunctions)), len(set(allStrings)))) + if __name__ == "__main__": main() From 80483f6dad2dfb42698ddb2a7bc8999e6851ba01 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 20 Sep 2015 17:56:07 -0500 Subject: [PATCH 18/29] fix ESTRING search --- tools/search_undefinedFunctions.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/search_undefinedFunctions.py b/tools/search_undefinedFunctions.py index 6d7ec5ae62..1c281fa717 100644 --- a/tools/search_undefinedFunctions.py +++ b/tools/search_undefinedFunctions.py @@ -74,19 +74,19 @@ def getStrings(filepath): content = file.read() srch = re.compile('[^E][CL]STRING\(([_a-zA-Z0-9]*)\)') - modfuncs = srch.findall(content) - modfuncs = sorted(set(modfuncs)) + modStrings = srch.findall(content) + modStrings = sorted(set(modStrings)) - srch = re.compile('[^E][CL]STRING\(([_a-zA-Z0-9]*)\)') - exfuncs = srch.findall(content) - exfuncs = sorted(set(exfuncs)) + srch = re.compile('E[CL]STRING\(([_a-zA-Z0-9]*),([_a-zA-Z0-9]*)\)') + exStrings = srch.findall(content) + exStrings = sorted(set(exStrings)) fileStrings = [] - for func in modfuncs: - fileStrings.append("STR_ACE_{0}_{1}".format(selfmodule,func)) + for localString in modStrings: + fileStrings.append("STR_ACE_{0}_{1}".format(selfmodule, localString)) - # for exModule,func in exfuncs: - # fileStrings.append("STR_ACE_{0}_{1}".format(exModule, func)) + for (exModule, exString) in exStrings: + fileStrings.append("STR_ACE_{0}_{1}".format(exModule, exString)) return fileStrings From d449e4bd8307120e99599fbb702fc7227680d23a Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 01:07:49 +0200 Subject: [PATCH 19/29] more common code cleanup --- addons/common/functions/fnc_dumpArray.sqf | 8 +- .../functions/fnc_dumpPerformanceCounters.sqf | 4 +- .../functions/fnc_getForceWalkStatus.sqf | 35 +++-- addons/common/functions/fnc_getInPosition.sqf | 125 +++++++++--------- addons/common/functions/fnc_getItemType.sqf | 95 +++++++------ .../functions/fnc_getLightProperties.sqf | 50 ++----- .../fnc_getLightPropertiesWeapon.sqf | 49 ++----- addons/common/functions/fnc_getName.sqf | 22 ++- .../common/functions/fnc_getPitchBankYaw.sqf | 15 ++- .../common/functions/fnc_getWindDirection.sqf | 48 +++---- addons/common/functions/fnc_getZoom.sqf | 15 ++- 11 files changed, 206 insertions(+), 260 deletions(-) diff --git a/addons/common/functions/fnc_dumpArray.sqf b/addons/common/functions/fnc_dumpArray.sqf index 7e8128e3ed..182c542df2 100644 --- a/addons/common/functions/fnc_dumpArray.sqf +++ b/addons/common/functions/fnc_dumpArray.sqf @@ -26,17 +26,17 @@ _depth = _depth + 1; if (IS_ARRAY(_var)) then { if (_var isEqualTo []) then { - diag_log text format["%1[],", _pad]; + diag_log text format ["%1[],", _pad]; } else { - diag_log text format["%1[", _pad]; + diag_log text format ["%1[", _pad]; { [_x, _depth] call FUNC(dumpArray); false } count _var; - diag_log text format["%1],", _pad]; + diag_log text format ["%1],", _pad]; }; } else { - diag_log text format["%1%2", _pad, [_var] call FUNC(formatVar)]; + diag_log text format ["%1%2", _pad, [_var] call FUNC(formatVar)]; }; diff --git a/addons/common/functions/fnc_dumpPerformanceCounters.sqf b/addons/common/functions/fnc_dumpPerformanceCounters.sqf index d23e3428db..e076831c6f 100644 --- a/addons/common/functions/fnc_dumpPerformanceCounters.sqf +++ b/addons/common/functions/fnc_dumpPerformanceCounters.sqf @@ -12,8 +12,8 @@ */ #include "script_component.hpp" -diag_log text format["REGISTERED ACE PFH HANDLERS"]; -diag_log text format["-------------------------------------------"]; +diag_log text format ["REGISTERED ACE PFH HANDLERS"]; +diag_log text format ["-------------------------------------------"]; if (!isNil "ACE_PFH_COUNTER") then { { diff --git a/addons/common/functions/fnc_getForceWalkStatus.sqf b/addons/common/functions/fnc_getForceWalkStatus.sqf index dbab640d86..acdc2f1a05 100644 --- a/addons/common/functions/fnc_getForceWalkStatus.sqf +++ b/addons/common/functions/fnc_getForceWalkStatus.sqf @@ -1,25 +1,23 @@ /* -Name: FUNC(getForceWalkStatus) - -Author: Pabst Mirror (from captivity by commy2) - -Description: - Returns reasons why the unit is forceWalk-ing, empty if not forced. - -Parameters: - 0: OBJECT - Unit - -Returns: - ARRAY(of strings) - Reason why the unit is force walking - -Example: - [ACE_Player] call FUNC(getForceWalkStatus) -*/ + * Author: PabstMirror, commy2 + * Returns reasons why the unit is forceWalk-ing. + * + * Arguments: + * 0: unit + * + * Return Value: + * Force Walk reasons + * + * Example: + * [ACE_Player] call ace_common_fnc_getForceWalkStatus + * + * Public: Yes + */ #include "script_component.hpp" -private ["_forceWalkReasons", "_unitForceWalkNumber", "_unitForceWalkStatus", "_unitForceWalkReasons"]; +params ["_unit"]; -PARAMS_1(_unit); +private ["_forceWalkReasons", "_unitForceWalkNumber", "_unitForceWalkStatus", "_unitForceWalkReasons"]; _forceWalkReasons = missionNamespace getVariable ["ACE_forceWalkReasons", []]; @@ -28,6 +26,7 @@ _unitForceWalkNumber = _unit getVariable ["ACE_forceWalkStatusNumber", 0]; _unitForceWalkStatus = [_unitForceWalkNumber, count _forceWalkReasons] call FUNC(binarizeNumber); _unitForceWalkReasons = []; + { if (_unitForceWalkStatus select _forEachIndex) then { _unitForceWalkReasons pushBack _x; diff --git a/addons/common/functions/fnc_getInPosition.sqf b/addons/common/functions/fnc_getInPosition.sqf index d80c387b5d..dc3ad38cde 100644 --- a/addons/common/functions/fnc_getInPosition.sqf +++ b/addons/common/functions/fnc_getInPosition.sqf @@ -1,31 +1,26 @@ /* * Author: commy2 + * Move unit into given vehicle position or switch to that position if the unit is already inside the vehicle. + * + * Arguments: + * 0: Unit + * 1: Vehicle + * 2: Position ("Driver", "Pilot", "Gunner", "Commander", "Copilot", "Turret", "FFV", "Codriver", "Cargo") + * 3: Index (only applies to "Turret", "FFV", "Codriver", "Cargo") (default: next free index) + * + * Return Value: + * None * - * Move unit into given vehicle position. Or switch to that position if the unit is already inside the vehicle. - * - * 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: 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) - * - * Return Value: - * Nothing + * Public: Yes */ #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", "_index"]; +params ["_unit", "_vehicle", "_position", ["_index", -1]]; -PARAMS_2(_unit,_vehicle); - -_position = toLower (_this select 2); -_index = _this select 3; // optional, please don't use - -if (isNil "_index") then {_index = -1}; +_position = toLower _position; // general if (!alive _vehicle || {locked _vehicle > 1}) exitWith {false}; @@ -39,27 +34,29 @@ _isInside = vehicle _unit == _vehicle; _script = {}; _enemiesInVehicle = false; //Possible Side Restriction + { if (side _unit getFriend side _x < 0.6) exitWith {_enemiesInVehicle = true}; -} forEach crew _vehicle; + false +} count crew _vehicle; switch (_position) do { case "driver" : { if (CANGETINDRIVER) then { - _script = [ - {_unit action [["GetInDriver", "MoveToDriver"] select _isInside, _vehicle];}, - {if (_isInside) then {moveOut _unit}; _unit moveInDriver _vehicle; call _fnc_getInEH;} - ] select _enemiesInVehicle; + _script = [ + {_unit action [["GetInDriver", "MoveToDriver"] select _isInside, _vehicle];}, + {if (_isInside) then {moveOut _unit}; _unit moveInDriver _vehicle; call _fnc_getInEH;} + ] select _enemiesInVehicle; }; }; case "pilot" : { if (CANGETINDRIVER) then { - _script = [ - {_unit action [["GetInPilot", "MoveToPilot"] select _isInside, _vehicle];}, - {if (_isInside) then {moveOut _unit}; _unit moveInDriver _vehicle; call _fnc_getInEH;} - ] select _enemiesInVehicle; - _position = "driver"; + _script = [ + {_unit action [["GetInPilot", "MoveToPilot"] select _isInside, _vehicle];}, + {if (_isInside) then {moveOut _unit}; _unit moveInDriver _vehicle; call _fnc_getInEH;} + ] select _enemiesInVehicle; + _position = "driver"; }; }; @@ -67,10 +64,10 @@ switch (_position) do { _turret = [_vehicle] call FUNC(getTurretGunner); if (CANGETINTURRETINDEX) then { - _script = [ - {_unit action [["GetInGunner", "MoveToGunner"] select _isInside, _vehicle];}, - {if (_isInside) then {moveOut _unit}; _unit moveInGunner _vehicle; call _fnc_getInEH;} - ] select _enemiesInVehicle; + _script = [ + {_unit action [["GetInGunner", "MoveToGunner"] select _isInside, _vehicle];}, + {if (_isInside) then {moveOut _unit}; _unit moveInGunner _vehicle; call _fnc_getInEH;} + ] select _enemiesInVehicle; }; }; @@ -78,10 +75,10 @@ switch (_position) do { _turret = [_vehicle] call FUNC(getTurretCommander); if (CANGETINTURRETINDEX) then { - _script = [ - {_unit action [["GetInCommander", "MoveToCommander"] select _isInside, _vehicle];}, - {if (_isInside) then {moveOut _unit}; _unit moveInCommander _vehicle; call _fnc_getInEH;} - ] select _enemiesInVehicle; + _script = [ + {_unit action [["GetInCommander", "MoveToCommander"] select _isInside, _vehicle];}, + {if (_isInside) then {moveOut _unit}; _unit moveInCommander _vehicle; call _fnc_getInEH;} + ] select _enemiesInVehicle; }; }; @@ -89,12 +86,12 @@ switch (_position) do { _turret = [_vehicle] call FUNC(getTurretCopilot); if (CANGETINTURRETINDEX) then { - _script = [ - {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, - {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} - ] select _enemiesInVehicle; + _script = [ + {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, + {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} + ] select _enemiesInVehicle; - _position = "gunner"; // I think. It's a turret after all and turrets supposedly return "gunner" + _position = "gunner"; // I think. It's a turret after all and turrets supposedly return "gunner" }; }; @@ -104,8 +101,8 @@ switch (_position) do { if (_index != -1 && {_turret = _turrets select _index; CANGETINTURRETINDEX}) then { _script = [ - {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, - {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} + {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, + {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} ] select _enemiesInVehicle; _position = "gunner"; @@ -114,13 +111,13 @@ switch (_position) do { _turret = _turrets select _index; if (CANGETINTURRETINDEX) exitWith { _script = [ - {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, - {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} + {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, + {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} ] select _enemiesInVehicle; _position = "gunner"; }; - }; + }; }; }; @@ -130,22 +127,22 @@ switch (_position) do { if (_index != -1 && {_turret = _turrets select _index; CANGETINTURRETINDEX}) then { _script = [ - {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, - {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} + {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, + {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} ] select _enemiesInVehicle; _position = "gunner"; // I think. It's a turret after all and turrets supposedly return "gunner" } else { for "_index" from 0 to (count _turrets - 1) do { - _turret = _turrets select _index; - if (CANGETINTURRETINDEX) exitWith { - _script = [ - {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, - {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} - ] select _enemiesInVehicle; + _turret = _turrets select _index; + if (CANGETINTURRETINDEX) exitWith { + _script = [ + {_unit action [["GetInTurret", "moveToTurret"] select _isInside, _vehicle, _turret];}, + {if (_isInside) then {moveOut _unit}; _unit moveInTurret [_vehicle, _turret]; call _fnc_getInEH;} + ] select _enemiesInVehicle; - _position = "gunner"; // I think. It's a turret after all and turrets supposedly return "gunner" - }; + _position = "gunner"; // I think. It's a turret after all and turrets supposedly return "gunner" + }; }; }; }; @@ -160,8 +157,8 @@ switch (_position) do { if (_index != -1 && {_index in _positions}) then { _script = [ - {_unit action [["GetInCargo", "MoveToCargo"] select _isInside, _vehicle, _index];}, - {if (_isInside) then {moveOut _unit}; _unit moveInCargo [_vehicle, _index]; call _fnc_getInEH;} + {_unit action [["GetInCargo", "MoveToCargo"] select _isInside, _vehicle, _index];}, + {if (_isInside) then {moveOut _unit}; _unit moveInCargo [_vehicle, _index]; call _fnc_getInEH;} ] select _enemiesInVehicle; _position = "cargo"; @@ -169,8 +166,8 @@ switch (_position) do { _index = _positions select 0; if (!isNil "_index") then { _script = [ - {_unit action [["GetInCargo", "MoveToCargo"] select _isInside, _vehicle, _index];}, - {if (_isInside) then {moveOut _unit}; _unit moveInCargo [_vehicle, _index]; call _fnc_getInEH;} + {_unit action [["GetInCargo", "MoveToCargo"] select _isInside, _vehicle, _index];}, + {if (_isInside) then {moveOut _unit}; _unit moveInCargo [_vehicle, _index]; call _fnc_getInEH;} ] select _enemiesInVehicle; _position = "cargo"; @@ -188,8 +185,8 @@ switch (_position) do { if (_index != -1 && {_index in _positions}) then { _script = [ - {_unit action [["GetInCargo", "MoveToCargo"] select _isInside, _vehicle, _index];}, - {if (_isInside) then {moveOut _unit}; _unit moveInCargo [_vehicle, _index]; call _fnc_getInEH;} + {_unit action [["GetInCargo", "MoveToCargo"] select _isInside, _vehicle, _index];}, + {if (_isInside) then {moveOut _unit}; _unit moveInCargo [_vehicle, _index]; call _fnc_getInEH;} ] select _enemiesInVehicle; _position = "cargo"; @@ -197,8 +194,8 @@ switch (_position) do { _index = _positions select 0; if (!isNil "_index") then { _script = [ - {_unit action [["GetInCargo", "MoveToCargo"] select _isInside, _vehicle, _index];}, - {if (_isInside) then {moveOut _unit}; _unit moveInCargo [_vehicle, _index]; call _fnc_getInEH;} + {_unit action [["GetInCargo", "MoveToCargo"] select _isInside, _vehicle, _index];}, + {if (_isInside) then {moveOut _unit}; _unit moveInCargo [_vehicle, _index]; call _fnc_getInEH;} ] select _enemiesInVehicle; _position = "cargo"; diff --git a/addons/common/functions/fnc_getItemType.sqf b/addons/common/functions/fnc_getItemType.sqf index 4de2bfa862..79abf41341 100644 --- a/addons/common/functions/fnc_getItemType.sqf +++ b/addons/common/functions/fnc_getItemType.sqf @@ -1,83 +1,78 @@ /* * Author: commy2 + * Returns item type of given classname. * - * What kind of item is given classname + * Arguments: + * 0: Item * - * Argument: - * 0: Classname of a item. (String) - * - * Return value: - * Item type. (Array) - * 0: "weapon", "item", "magazine" or "" (String) - * 1: A description of the item (e.g. "primary" for a weapon or "vest" for a vest item) + * Return Value: + * 0: Type ("weapon", "item", "magazine", "") + * 1: Item Description * + * Public: Yes */ #include "script_component.hpp" -PARAMS_1(_item); +params ["_item"]; -private ["_cfgType"]; +private ["_cfgType", "_config", "_type", "_default"]; _cfgType = [_item] call FUNC(getConfigType); -if (_cfgType == "") exitWith {["",""]}; +if (_cfgType == "") exitWith {["", ""]}; -if (_cfgType == "CfgGlasses") exitWith {["item","glasses"]}; - -private ["_config", "_type"]; +if (_cfgType == "CfgGlasses") exitWith {["item", "glasses"]}; _config = configFile >> _cfgType >> _item; - _type = getNumber (_config >> "type"); if (isNumber (_config >> "ItemInfo" >> "type")) then { _type = getNumber (_config >> "ItemInfo" >> "type"); }; -private "_default"; _default = ["item", "magazine"] select (_cfgType == "CfgMagazines"); switch (true) do { case (_type == 0): {[_default,"unknown"]}; - case (_type == 2^0): {["weapon","primary"]}; - case (_type == 2^1): {["weapon","handgun"]}; - case (_type == 2^2): {["weapon","secondary"]}; - case (_type < 2^4): {["weapon","unknown"]}; - case (_type == 2^4): {["magazine","handgun"]}; // handgun - case (_type == 2^8): {["magazine","primary"]}; // rifle - case (_type == 2^9): {["magazine","secondary"]}; // rpg, mg, mines - //case (_type < 2^11): {["magazine","unknown"]}; + case (_type == 2^0): {["weapon", "primary"]}; + case (_type == 2^1): {["weapon", "handgun"]}; + case (_type == 2^2): {["weapon", "secondary"]}; + case (_type < 2^4): {["weapon", "unknown"]}; + case (_type == 2^4): {["magazine", "handgun"]}; // handgun + case (_type == 2^8): {["magazine", "primary"]}; // rifle + case (_type == 2^9): {["magazine", "secondary"]}; // rpg, mg, mines + //case (_type < 2^11): {["magazine", "unknown"]}; - case (_type == 101): {["item","muzzle"]}; - case (_type == 201): {["item","optics"]}; - case (_type == 301): {["item","flashlight"]}; - case (_type == 302): {["item","under"]}; // czech for bipod item - case (_type == 401): {["item","first_aid_kit"]}; - case (_type == 501): {["item","fins"]}; // not implemented - case (_type == 601): {["item","breathing_bomb"]}; // not implemented - case (_type == 603): {["item","goggles"]}; - case (_type == 604): {["item","scuba"]}; // not implemented - case (_type == 605): {["item","headgear"]}; - case (_type == 611): {["item","radio"]}; - case (_type == 616): {["item","hmd"]}; - case (_type == 617): {["item","binocular"]}; - case (_type == 619): {["item","medikit"]}; - case (_type == 620): {["item","toolkit"]}; - case (_type == 621): {["item","uav_terminal"]}; - case (_type == 701): {["item","vest"]}; - case (_type == 801): {["item","uniform"]}; + case (_type == 101): {["item", "muzzle"]}; + case (_type == 201): {["item", "optics"]}; + case (_type == 301): {["item", "flashlight"]}; + case (_type == 302): {["item", "under"]}; // czech for bipod item + case (_type == 401): {["item", "first_aid_kit"]}; + case (_type == 501): {["item", "fins"]}; // not implemented + case (_type == 601): {["item", "breathing_bomb"]}; // not implemented + case (_type == 603): {["item", "goggles"]}; + case (_type == 604): {["item", "scuba"]}; // not implemented + case (_type == 605): {["item", "headgear"]}; + case (_type == 611): {["item", "radio"]}; + case (_type == 616): {["item", "hmd"]}; + case (_type == 617): {["item", "binocular"]}; + case (_type == 619): {["item", "medikit"]}; + case (_type == 620): {["item", "toolkit"]}; + case (_type == 621): {["item", "uav_terminal"]}; + case (_type == 701): {["item", "vest"]}; + case (_type == 801): {["item", "uniform"]}; case (_type == 2^12): { switch (toLower getText (_config >> "simulation")) do { - case ("weapon"): {["weapon","binocular"]}; - case ("binocular"): {["weapon","binocular"]}; - case ("nvgoggles"): {["item","nvgoggles"]}; - case ("itemminedetector"): {["item","minedetector"]}; - default {[_default,"unknown"]}; + case ("weapon"): {["weapon", "binocular"]}; + case ("binocular"): {["weapon", "binocular"]}; + case ("nvgoggles"): {["item", "nvgoggles"]}; + case ("itemminedetector"): {["item", "minedetector"]}; + default {[_default, "unknown"]}; }; }; - case (_type == 2^16): {["weapon","vehicle"]}; - case (_type == 2^17): {[_default,"unknown"]}; // ??? - default {[_default,"unknown"]}; + case (_type == 2^16): {["weapon", "vehicle"]}; + case (_type == 2^17): {[_default, "unknown"]}; // ??? + default {[_default, "unknown"]}; }; diff --git a/addons/common/functions/fnc_getLightProperties.sqf b/addons/common/functions/fnc_getLightProperties.sqf index 456084c3f9..bbaf955a8b 100644 --- a/addons/common/functions/fnc_getLightProperties.sqf +++ b/addons/common/functions/fnc_getLightProperties.sqf @@ -3,22 +3,26 @@ * Read properties of given vehicles light. * * Arguments: - * 0: Object with lights (Object) - * 1: Light classname (String) + * 0: Object with lights + * 1: Light classname * * Return Value: - * Stuff from config (Array) + * 0: Light intensity + * 1: Light position + * 2: Light direction + * 3: Light inner angle + * 4: Light outer angle * + * Public: Yes */ #include "script_component.hpp" -PARAMS_2(_vehicle,_light); +params ["_vehicle", "_light"]; + +private ["_config", "_intensity", "_position", "_direction", "_innerAngle", "_outerAngle"]; -private "_config"; _config = configFile >> "CfgVehicles" >> typeOf _vehicle >> "Reflectors" >> _light; -private ["_intensity", "_position", "_direction", "_innerAngle", "_outerAngle"]; - _intensity = getNumber (_config >> "intensity"); _position = getText (_config >> "position"); _direction = getText (_config >> "direction"); @@ -26,35 +30,3 @@ _innerAngle = getNumber (_config >> "innerAngle"); _outerAngle = getNumber (_config >> "outerAngle"); [_intensity, _position, _direction, _innerAngle, _outerAngle] - -/* -class Reflectors -{ - class Light_1 - { - color[] = {1000,1000,1100}; - ambient[] = {10,10,11}; - intensity = 5; - size = 1; - innerAngle = 90; - outerAngle = 130; - coneFadeCoef = 2; - position = "Light_1_pos"; - direction = "Light_1_dir"; - hitpoint = "Light_1_hitpoint"; - selection = "Light_1_hide"; - useFlare = 1; - flareSize = 0.9; - flareMaxDistance = 85; - class Attenuation - { - start = 0; - constant = 0; - linear = 0; - quadratic = 0.9; - hardLimitStart = 40; - hardLimitEnd = 60; - }; - }; -}; -*/ diff --git a/addons/common/functions/fnc_getLightPropertiesWeapon.sqf b/addons/common/functions/fnc_getLightPropertiesWeapon.sqf index 03c6753a76..01567fee58 100644 --- a/addons/common/functions/fnc_getLightPropertiesWeapon.sqf +++ b/addons/common/functions/fnc_getLightPropertiesWeapon.sqf @@ -1,23 +1,29 @@ /* * Author: commy2 - * Read properties of given flashlight. @todo, Can weapons themselves still have flashlights (no attachment)? + * Read properties of given flashlight. * * Arguments: - * 0: A flashlight (String) + * 0: Flashlight * * Return Value: - * Stuff from config (Array) + * 0: Light intensity + * 1: Light position + * 2: Light direction + * 3: Light inner angle + * 4: Light outer angle * + * Public: Yes */ #include "script_component.hpp" -PARAMS_1(_weapon); +params ["_weapon"]; + +// @todo: Can weapons themselves still have flashlights (no attachment)? + +private ["_config", "_intensity", "_position", "_direction", "_innerAngle", "_outerAngle"]; -private "_config"; _config = configFile >> "CfgWeapons" >> _weapon >> "ItemInfo" >> "FlashLight"; -private ["_intensity", "_position", "_direction", "_innerAngle", "_outerAngle"]; - _intensity = getNumber (_config >> "intensity"); _position = getText (_config >> "position"); _direction = getText (_config >> "direction"); @@ -25,32 +31,3 @@ _innerAngle = getNumber (_config >> "innerAngle"); _outerAngle = getNumber (_config >> "outerAngle"); [_intensity, _position, _direction, _innerAngle, _outerAngle] - -/* -class FlashLight -{ - color[] = {180,156,120}; - ambient[] = {0.9,0.78,0.6}; - intensity = 20; - size = 1; - innerAngle = 20; - outerAngle = 80; - coneFadeCoef = 5; - position = "flash dir"; - direction = "flash"; - useFlare = 1; - flareSize = 1.4; - flareMaxDistance = "100.0f"; - dayLight = 0; - class Attenuation - { - start = 0.5; - constant = 0; - linear = 0; - quadratic = 1.1; - hardLimitStart = 20; - hardLimitEnd = 30; - }; - scale[] = {0}; -}; -*/ diff --git a/addons/common/functions/fnc_getName.sqf b/addons/common/functions/fnc_getName.sqf index 1da59534f0..a7facd2c6d 100644 --- a/addons/common/functions/fnc_getName.sqf +++ b/addons/common/functions/fnc_getName.sqf @@ -1,25 +1,21 @@ /* * Author: commy2 - * * Returns the name of the object. Used to prevent issues with the name command. * - * Argument: - * 0: Object (Object) - * 1: Show effective commander name? (Bool, optinal default: false) + * Arguments: + * 0: Object + * 1: Use effective commander name when used on vehicles (default: false) * - * Return value: - * The name. + * Return Value: + * Object Name + * + * Public: Yes */ #include "script_component.hpp" -private ["_name"]; - -PARAMS_2(_unit,_showEffective); - -if (isNil "_showEffective") then { - _showEffective = false; -}; +params ["_unit", ["_showEffective", false]]; +private "_name"; _name = ""; if (_unit isKindOf "CAManBase") then { diff --git a/addons/common/functions/fnc_getPitchBankYaw.sqf b/addons/common/functions/fnc_getPitchBankYaw.sqf index 2a9b0bacd1..74eac376fc 100644 --- a/addons/common/functions/fnc_getPitchBankYaw.sqf +++ b/addons/common/functions/fnc_getPitchBankYaw.sqf @@ -1,14 +1,19 @@ /* * Author: KoffeinFlummi - * - * Returns [pitch, bank, yaw] for given vehicle in degrees. + * Returns pitch, bank, yaw for given vehicle in degrees. * * Arguments: - * 0: Unit/Vehicle + * 0: Unit/Vehicle * * Return Value: - * [pitch, bank, yaw] + * 0: pitch + * 1: bank + * 2: yaw + * + * Public: Yes */ #include "script_component.hpp" -((_this select 0) call BIS_fnc_getPitchBank) + [getDir (_this select 0)] +private ["_vehicle"]; + +(_vehicle call BIS_fnc_getPitchBank) + [getDir _vehicle] diff --git a/addons/common/functions/fnc_getWindDirection.sqf b/addons/common/functions/fnc_getWindDirection.sqf index d93023bfe4..7341ea9c1d 100644 --- a/addons/common/functions/fnc_getWindDirection.sqf +++ b/addons/common/functions/fnc_getWindDirection.sqf @@ -1,31 +1,33 @@ /* * Author: commy2 - * * Get the compass direction the wind is blowing from. * - * Argument: - * None. + * Arguments: + * None * - * Return value: - * Wind direction. (String) + * Return Value: + * Wind cardinal direction + * + * Public: Yes */ #include "script_component.hpp" -switch (round (windDir / 360 * 16)) do { - case 1 : {localize QUOTE(DOUBLES(STR,GVAR(SSW)))}; - case 2 : {localize QUOTE(DOUBLES(STR,GVAR(SW)))}; - case 3 : {localize QUOTE(DOUBLES(STR,GVAR(WSW)))}; - case 4 : {localize QUOTE(DOUBLES(STR,GVAR(W)))}; - case 5 : {localize QUOTE(DOUBLES(STR,GVAR(WNW)))}; - case 6 : {localize QUOTE(DOUBLES(STR,GVAR(NW)))}; - case 7 : {localize QUOTE(DOUBLES(STR,GVAR(NNW)))}; - case 8 : {localize QUOTE(DOUBLES(STR,GVAR(N)))}; - case 9 : {localize QUOTE(DOUBLES(STR,GVAR(NNE)))}; - case 10 : {localize QUOTE(DOUBLES(STR,GVAR(NE)))}; - case 11 : {localize QUOTE(DOUBLES(STR,GVAR(ENE)))}; - case 12 : {localize QUOTE(DOUBLES(STR,GVAR(E)))}; - case 13 : {localize QUOTE(DOUBLES(STR,GVAR(ESE)))}; - case 14 : {localize QUOTE(DOUBLES(STR,GVAR(SE)))}; - case 15 : {localize QUOTE(DOUBLES(STR,GVAR(SSE)))}; - default {localize QUOTE(DOUBLES(STR,GVAR(S)))}; -}; +localize ([ + LSTRING(S), + LSTRING(SSW), + LSTRING(SW), + LSTRING(WSW), + LSTRING(W), + LSTRING(WNW), + LSTRING(NW), + LSTRING(NNW), + LSTRING(N), + LSTRING(NNE), + LSTRING(NE), + LSTRING(ENE), + LSTRING(E), + LSTRING(ESE), + LSTRING(SE), + LSTRING(SSE), + LSTRING(S) +] select (round (windDir / 360 * 16))) // return diff --git a/addons/common/functions/fnc_getZoom.sqf b/addons/common/functions/fnc_getZoom.sqf index 1f319ac768..f4113198a7 100644 --- a/addons/common/functions/fnc_getZoom.sqf +++ b/addons/common/functions/fnc_getZoom.sqf @@ -1,14 +1,17 @@ /* * Author: commy2 - * * Returns a value depending on current zoom level. * - * Argument: - * None. + * Arguments: + * None * - * Return value: - * Zoom. (Number) + * Return Value: + * Zoom + * + * Public: Yes */ #include "script_component.hpp" -(0.5 - ((worldToScreen positionCameraToWorld [0,1,1]) select 1)) * (getResolution select 5) +if (!hasInterface) exitWith {0}; + +(0.5 - ((worldToScreen positionCameraToWorld [0, 1, 1]) select 1)) * (getResolution select 5) From d802cdfb23bff474fd3efa3d47e90e29be4e4c0f Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 01:41:17 +0200 Subject: [PATCH 20/29] more common code cleanup --- addons/common/functions/fnc_getItemType.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/functions/fnc_getItemType.sqf b/addons/common/functions/fnc_getItemType.sqf index 79abf41341..4d6ee932fa 100644 --- a/addons/common/functions/fnc_getItemType.sqf +++ b/addons/common/functions/fnc_getItemType.sqf @@ -33,7 +33,7 @@ if (isNumber (_config >> "ItemInfo" >> "type")) then { _default = ["item", "magazine"] select (_cfgType == "CfgMagazines"); switch (true) do { - case (_type == 0): {[_default,"unknown"]}; + case (_type == 0): {[_default, "unknown"]}; case (_type == 2^0): {["weapon", "primary"]}; case (_type == 2^1): {["weapon", "handgun"]}; case (_type == 2^2): {["weapon", "secondary"]}; From 9fa6eb0651df16d916c5f021f3fb97481149384e Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 13:08:10 +0200 Subject: [PATCH 21/29] 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 From b0f9eab1f7a94f1378a450e588800d741ffe783f Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 13:53:12 +0200 Subject: [PATCH 22/29] more common code cleanup --- .../common/functions/fnc_getMapGridData.sqf | 28 +++++--- .../functions/fnc_getMapPosFromGrid.sqf | 19 +++--- addons/common/functions/fnc_getMarkerType.sqf | 68 ++++++++++--------- .../fnc_getReflectorsWithSelections.sqf | 11 +-- 4 files changed, 71 insertions(+), 55 deletions(-) diff --git a/addons/common/functions/fnc_getMapGridData.sqf b/addons/common/functions/fnc_getMapGridData.sqf index 838b753e91..c74f378d75 100644 --- a/addons/common/functions/fnc_getMapGridData.sqf +++ b/addons/common/functions/fnc_getMapGridData.sqf @@ -1,12 +1,13 @@ /* - * Author: PabstMirror (ideas from Nou's mapGridToPos and BIS_fnc_gridToPos) + * Author: PabstMirror * Finds real x/y offset and map step for a 10 digit grid * Save time by preparing data one time at startup + * Ideas from Nou's mapGridToPos and BIS_fnc_gridToPos * - * Argument: + * Arguments: * None * - * Return values: + * Return Value: * None * * Example: @@ -16,10 +17,10 @@ */ #include "script_component.hpp" -private["_cfgGrid", "_formatX", "_formatY", "_heightOffset", "_offsetX", "_offsetY", "_originGrid", "_realOffsetY", "_startGrid", "_stepX", "_stepY", "_zoom", "_zoomMax", "_letterGrid"]; - GVAR(mapGridData) = []; +private ["_cfgGrid", "_offsetX", "_offsetY", "_zoomMax", "_formatX", "_formatY", "_stepX", "_stepY", "_zoom", "_letterGrid", "_heightOffset", "_startGrid", "_originGrid", "_realOffsetY"]; + //--- Extract grid values from world config (Borrowed from BIS_fnc_gridToPos) _cfgGrid = configFile >> "CfgWorlds" >> worldName >> "Grid"; _offsetX = getNumber (_cfgGrid >> "offsetX"); @@ -29,6 +30,7 @@ _formatX = ""; _formatY = ""; _stepX = 1e10; _stepY = 1e10; + { _zoom = getnumber (_x >> "zoomMax"); if (_zoom < _zoomMax) then { @@ -38,11 +40,14 @@ _stepY = 1e10; _stepX = getNumber (_x >> "stepX"); _stepY = getNumber (_x >> "stepY"); }; -} foreach configProperties [_cfgGrid, "isClass _x", false]; + false +} count configProperties [_cfgGrid, "isClass _x", false]; _letterGrid = false; -if (((toLower _formatX) find "a") != -1) then {_letterGrid = true}; -if (((toLower _formatY) find "a") != -1) then {_letterGrid = true}; + +if (toLower _formatX find "a" != -1) then {_letterGrid = true}; +if (toLower _formatY find "a" != -1) then {_letterGrid = true}; + if (_letterGrid) exitWith { ACE_LOGWARNING_3("Map Grid Warning (%1) - Map uses letter grids [%2, %3]",worldName,_formatX,_formatY); }; @@ -51,13 +56,14 @@ if (_letterGrid) exitWith { _heightOffset = 500; _startGrid = mapGridPosition [0, _heightOffset]; _originGrid = _startGrid; + while {_startGrid == _originGrid} do { _heightOffset = _heightOffset + 1; _originGrid = mapGridPosition [0, _heightOffset]; }; //Calculate the real y offset -_realOffsetY = parseNumber (_originGrid select [(count _formatX), (count _formatY)]) * _stepY + _heightOffset - 1; +_realOffsetY = (parseNumber (_originGrid select [count _formatX, count _formatY])) * _stepY + _heightOffset - 1; //Calculate MGRS 10digit step - they should both be 1 meter: _stepXat5 = _stepX * 10 ^ ((count _formatX) - 5); @@ -66,10 +72,12 @@ _stepYat5 = -1 * _stepY * 10 ^ ((count _formatY) - 5); if (_stepYat5 < 0) then { ACE_LOGWARNING_1("Map Grid Warning (%1) - Northing is reversed.",worldName); }; + if (_stepXat5 != 1) then { ACE_LOGWARNING_2("Map Grid Warning (%1) - MGRS 10 digit grid does not equal 1 meter: (%2) for x.",worldName,_stepXat5); }; -if ((_stepYat5 != 1) && {_stepYat5 != -1}) then { + +if (_stepYat5 != 1 && {_stepYat5 != -1}) then { ACE_LOGWARNING_2("Map Grid Warning (%1) - MGRS 10 digit grid does not equal 1 meter: (%2) for y.",worldName,_stepXat5); }; diff --git a/addons/common/functions/fnc_getMapPosFromGrid.sqf b/addons/common/functions/fnc_getMapPosFromGrid.sqf index 20194df88a..5ba67a40bf 100644 --- a/addons/common/functions/fnc_getMapPosFromGrid.sqf +++ b/addons/common/functions/fnc_getMapPosFromGrid.sqf @@ -2,9 +2,9 @@ * Author: PabstMirror * Gets position from grid cords * - * Argument: + * Arguments: * 0: Grid Cords - * 1: Get Center or bottom right + * 1: Grid center (true), Grid Bottom Right (false) (default: true) * * Return values: * Position @@ -16,24 +16,23 @@ */ #include "script_component.hpp" -PARAMS_1(_inputString); -DEFAULT_PARAM(1,_getCenterOfGrid,true); +params ["_inputString", ["_getCenterOfGrid", true]]; -private["_countInput", "_countInputHalf", "_xPart", "_xPos", "_yPart", "_yPos"]; - -if ((count GVAR(mapGridData)) == 0) exitWith { +if (count GVAR(mapGridData) == 0) exitWith { ERROR("Map has bad data, falling back to BIS_fnc_gridToPos"); (_this call BIS_fnc_gridToPos) select 0 }; -EXPLODE_4_PVT(GVAR(mapGridData),_offsetX,_realOffsetY,_stepXat5,_stepYat5); +GVAR(mapGridData) params ["_offsetX", "_realOffsetY", "_stepXat5", "_stepYat5"]; + +private ["_countInput", "_countInputHalf", "_xPart", "_yPart", "_xPos", "_yPos"]; _countInput = count _inputString; _countInputHalf = floor (_countInput / 2); //Split string, ignoring middle _xPart = _inputString select [0, _countInputHalf]; -_yPart = _inputString select [(ceil (_countInput / 2)), _countInputHalf]; +_yPart = _inputString select [ceil (_countInput / 2), _countInputHalf]; _xPos = ((parseNumber _xPart) * _stepXat5 * 10 ^ (5 - _countInputHalf)) + _offsetX; _yPos = ((parseNumber _yPart) * _stepYat5 * 10 ^ (5 - _countInputHalf)) + _realOffsetY; @@ -43,4 +42,4 @@ if (_getCenterOfGrid) then { _yPos = _yPos + 0.5 * _stepYat5 * 10 ^ (5 - _countInputHalf); }; -[_xPos, _yPos, 0]; +[_xPos, _yPos, 0] diff --git a/addons/common/functions/fnc_getMarkerType.sqf b/addons/common/functions/fnc_getMarkerType.sqf index bba8c15199..7c99302d8f 100644 --- a/addons/common/functions/fnc_getMarkerType.sqf +++ b/addons/common/functions/fnc_getMarkerType.sqf @@ -1,19 +1,20 @@ /* * Author: KoffeinFlummi - * * Get the apropriate marker for a group. * * Arguments: * 0: Group * * Return Value: - * Marker Type (string) + * Marker Type + * + * Public: No */ #include "script_component.hpp" -private ["_leader","_vehicle","_side"]; +params ["_group"]; -PARAMS_1(_group); +private ["_leader", "_vehicle", "_side"]; _leader = leader _group; _vehicle = vehicle _leader; @@ -21,56 +22,61 @@ _side = side _leader; if (_vehicle == _leader) exitWith { if ( - (getNumber (configFile >> "CfgVehicles" >> (typeOf _leader) >> "detectSkill") > 20) or - (getNumber (configFile >> "CfgVehicles" >> (typeOf _leader) >> "camouflage") < 1) or - (getText (configFile >> "CfgVehicles" >> (typeOf _leader) >> "textsingular") == "diver") - ) then { - ["n_recon", "b_recon", "o_recon"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + getNumber (configFile >> "CfgVehicles" >> typeOf _leader >> "detectSkill") > 20 || + getNumber (configFile >> "CfgVehicles" >> typeOf _leader >> "camouflage") < 1 || + getText (configFile >> "CfgVehicles" >> typeOf _leader >> "textsingular") == "diver" + ) then { + ["n_recon", "b_recon", "o_recon"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) } else { - ["n_inf", "b_inf", "o_inf"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + ["n_inf", "b_inf", "o_inf"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) }; }; -if (getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "attendant") == 1) exitWith { - ["n_med", "b_med", "o_med"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) +if (getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "attendant") == 1) exitWith { + ["n_med", "b_med", "o_med"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) }; + if ( - (getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "transportRepair") > 0) or - (getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "transportFuel") > 0) or - (getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "transportAmmo") > 0) or - (getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "ACE_canRepair") > 0) or - (getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "ACE_fuelCapacityCargo") > 0) - ) exitWith { - ["n_maint", "b_maint", "o_maint"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "transportRepair") > 0 || + getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "transportFuel") > 0 || + getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "transportAmmo") > 0 || + getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "ACE_canRepair") > 0 || + getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "ACE_fuelCapacityCargo") > 0 +) exitWith { + ["n_maint", "b_maint", "o_maint"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) }; if (_vehicle isKindOf "Plane") exitWith { - ["n_plane", "b_plane", "o_plane"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + ["n_plane", "b_plane", "o_plane"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) }; + if (_vehicle isKindOf "Air") exitWith { - ["n_air", "b_air", "o_air"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + ["n_air", "b_air", "o_air"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) }; if (_vehicle isKindOf "StaticMortar") exitWith { - ["n_mortar", "b_mortar", "o_mortar"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + ["n_mortar", "b_mortar", "o_mortar"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) }; -if (getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "artilleryScanner") == 1) exitWith { - ["n_art", "b_art", "o_art"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + +if (getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "artilleryScanner") == 1) exitWith { + ["n_art", "b_art", "o_art"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) }; if (_vehicle isKindOf "Car") exitWith { - ["n_motor_inf", "b_motor_inf", "o_motor_inf"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) -}; -if ((_vehicle isKindOf "Tank") and (getNumber (configFile >> "CfgVehicles" >> (typeOf _vehicle) >> "transportSoldier") > 0)) exitWith { - ["n_mech_inf", "b_mech_inf", "o_mech_inf"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + ["n_motor_inf", "b_motor_inf", "o_motor_inf"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) }; + if (_vehicle isKindOf "Tank") exitWith { - ["n_armor", "b_armor", "o_armor"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + if (getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "transportSoldier") > 0) then { + ["n_mech_inf", "b_mech_inf", "o_mech_inf"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) + } else { + ["n_armor", "b_armor", "o_armor"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) + }; }; if (_vehicle isKindOf "Ship") exitWith { - ["n_naval", "b_naval", "o_naval"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) + ["n_naval", "b_naval", "o_naval"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) }; // generic marker -["n_unknown", "b_unknown", "o_unknown"] select ((["GUER", "WEST", "EAST"] find (str _side)) max 0) +["n_unknown", "b_unknown", "o_unknown"] select ((["GUER", "WEST", "EAST"] find str _side) max 0) diff --git a/addons/common/functions/fnc_getReflectorsWithSelections.sqf b/addons/common/functions/fnc_getReflectorsWithSelections.sqf index d50269ade8..ef2b908bde 100644 --- a/addons/common/functions/fnc_getReflectorsWithSelections.sqf +++ b/addons/common/functions/fnc_getReflectorsWithSelections.sqf @@ -6,16 +6,19 @@ * They behave like having an armor value of 0. * * Arguments: - * 0: A vehicle, not the classname (Object) + * 0: Vehicle * * Return Value: - * The light names and selections (Array) + * 0: Light Hitpoints + * 1: Selections + * + * Public: Yes */ #include "script_component.hpp" -private ["_config", "_hitpoints", "_selections", "_i"]; +params ["_vehicle"]; -PARAMS_1(_vehicle); +private ["_config", "_hitpoints", "_selections"]; _config = configFile >> "CfgVehicles" >> typeOf _vehicle; From df3211cc429c6433fcca867772c05e5ba193f4c5 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 14:20:53 +0200 Subject: [PATCH 23/29] more common code cleanup --- addons/common/functions/fnc_getHitPoints.sqf | 11 +- .../fnc_getHitPointsWithSelections.sqf | 14 ++- addons/common/functions/fnc_getMGRSdata.sqf | 118 +++++++++--------- .../functions/fnc_getMapGridFromPos.sqf | 33 ++--- 4 files changed, 94 insertions(+), 82 deletions(-) diff --git a/addons/common/functions/fnc_getHitPoints.sqf b/addons/common/functions/fnc_getHitPoints.sqf index 491f243b44..8b2f10728c 100644 --- a/addons/common/functions/fnc_getHitPoints.sqf +++ b/addons/common/functions/fnc_getHitPoints.sqf @@ -1,13 +1,16 @@ /* * Author: commy2 - * - * Returns all hitpoints of any vehicle. Might contain duplicates if the turrets contain non unique hitpoints with different selection names. + * Returns all hitpoints and their selections of any vehicle. Might contain duplicates if the turrets contain non unique hitpoints with different selection names. * * Arguments: - * 0: A vehicle, not the classname (Object) + * 0: Vehicle * * Return Value: - * The hitpoints (Array) + * Hitpoints + * + * Public: Yes + * + * Deprecated */ #include "script_component.hpp" diff --git a/addons/common/functions/fnc_getHitPointsWithSelections.sqf b/addons/common/functions/fnc_getHitPointsWithSelections.sqf index bc3799665e..7b027d9efa 100644 --- a/addons/common/functions/fnc_getHitPointsWithSelections.sqf +++ b/addons/common/functions/fnc_getHitPointsWithSelections.sqf @@ -1,13 +1,17 @@ /* * Author: commy2 - * - * Returns all hitpoints and their selections of any vehicle. Might contain duplicates if the turrets contain non unique hitpoints with different selection names. + * Returns all hitpoints and their respective selections of any vehicle. Might contain duplicates for non unique hitpoints in turrets. * * Arguments: - * 0: A vehicle, not the classname (Object) + * 0: Vehicle * * Return Value: - * The hitpoints with selections. Format: [hitpoints, selections]. They correspond by index. (Array) + * 0: Hitpoints + * 1: Selections + * + * Public: Yes + * + * Deprecated */ #include "script_component.hpp" @@ -15,5 +19,7 @@ params ["_vehicle"]; private "_hitPointsWithSelections"; _hitPointsWithSelections = getAllHitPointsDamage _vehicle; + _hitPointsWithSelections resize 2; + _hitPointsWithSelections diff --git a/addons/common/functions/fnc_getMGRSdata.sqf b/addons/common/functions/fnc_getMGRSdata.sqf index 775f439174..b4f10db8a4 100644 --- a/addons/common/functions/fnc_getMGRSdata.sqf +++ b/addons/common/functions/fnc_getMGRSdata.sqf @@ -1,28 +1,28 @@ /* * Author: VKing * Gets the current map's MGRS grid zone designator and 100km square. - * Also gets longitude, latitude and altitude offset for the map + * Also gets longitude, latitude and altitude offset for the map. + * Writes return values to GVAR(MGRS_data) if run on the current map. * * Argument: - * 0: Optional: Map name, if undefined the current map is used (String) + * 0: Map name (default: worldName) * - * Return value: - * 0: Grid zone designator (String) - * 1: 100km square (String) - * 2: GZD + 100km sq. as a single string (String) - * Writes return values to GVAR(MGRS_data) if run on the current map + * Return Value: + * 0: Grid zone designator + * 1: 100km square + * 2: GZD + 100km sq. as a single string + * + * Public: No */ - -// #define DEBUG_MODE_FULL #include "script_component.hpp" -private ["_zone","_band","_GZD","_long","_lat","_UTM","_easting","_northing", "_altitude"]; +params [["_map", worldName]]; -DEFAULT_PARAM(0,_map,worldName); +private ["_long", "_lat", "_altitude", "_UTM", "_easting", "_northing", "_zone", "_band", "_GZD"]; -_long = getNumber (ConfigFile >> "CfgWorlds" >> _map >> "longitude"); -_lat = getNumber (ConfigFile >> "CfgWorlds" >> _map >> "latitude"); -_altitude = getNumber (ConfigFile >> "CfgWorlds" >> _map >> "elevationOffset"); +_long = getNumber (configFile >> "CfgWorlds" >> _map >> "longitude"); +_lat = getNumber (configFile >> "CfgWorlds" >> _map >> "latitude"); +_altitude = getNumber (configFile >> "CfgWorlds" >> _map >> "elevationOffset"); if (_map in ["Chernarus", "Bootcamp_ACR", "Woodland_ACR", "utes"]) then { _lat = 50; _altitude = 0; }; if (_map in ["Altis", "Stratis"]) then { _lat = 40; _altitude = 0; }; @@ -46,11 +46,10 @@ if (_map in ["lingor"]) then { _lat = -4; _altitude = 0; }; if (_map in ["Panthera3"]) then { _lat = 46; _altitude = 0; }; if (_map in ["Kunduz"]) then { _lat = 37; _altitude = 400; }; - _UTM = [_long,_lat] call BIS_fnc_posDegToUTM; _easting = _UTM select 0; _northing = _UTM select 1; -// _zone = _UTM select 2; +//_zone = _UTM select 2; TRACE_4("",_UTM,_easting,_northing,_zone); /* @@ -76,9 +75,11 @@ _band = switch (true) do { case (_lat>8): {"P"}; case (_lat>=0): {"N"}; }; - */ +*/ + _zone = 1 + (floor ((_long + 180) / 6)); _band = "Z"; + if (_lat <= -80) then { _band = "A"; } else { @@ -86,13 +87,13 @@ if (_lat <= -80) then { _band = "CDEFGHJKLMNPQRSTUVWXX" select [(floor ((_lat / 8) + 10)), 1]; }; }; + if (_map == "VR") then {_zone = 0; _band = "RV";}; _GZD = format ["%1%2",_zone,_band]; TRACE_3("",_zone,_band,_GZD); - -private ["_set1","_set2","_set3","_set4","_set5","_set6","_metaE","_metaN","_letterE","_letterN","_grid100km"]; +private ["_set1", "_set2", "_set3", "_set4", "_set5", "_set6", "_metaE", "_metaN", "_letterE", "_letterN", "_grid100km"]; _set1 = [1,7,13,19,25,31,37,43,49,55]; _set2 = [2,8,14,20,26,32,38,44,50,56]; @@ -102,25 +103,25 @@ _set5 = [5,11,17,23,29,35,41,47,53,59]; _set6 = [6,12,18,24,30,36,42,48,54,60]; switch (true) do { -case (_zone in _set1): {_metaE = 1; _metaN = 1;}; -case (_zone in _set2): {_metaE = 2; _metaN = 2;}; -case (_zone in _set3): {_metaE = 3; _metaN = 1;}; -case (_zone in _set4): {_metaE = 1; _metaN = 2;}; -case (_zone in _set5): {_metaE = 2; _metaN = 1;}; -case (_zone in _set6): {_metaE = 3; _metaN = 2;}; + case (_zone in _set1): {_metaE = 1; _metaN = 1;}; + case (_zone in _set2): {_metaE = 2; _metaN = 2;}; + case (_zone in _set3): {_metaE = 3; _metaN = 1;}; + case (_zone in _set4): {_metaE = 1; _metaN = 2;}; + case (_zone in _set5): {_metaE = 2; _metaN = 1;}; + case (_zone in _set6): {_metaE = 3; _metaN = 2;}; }; TRACE_2("",_metaE,_metaN); switch (true) do { -case (_zone == 0): {_letterE = "E"}; -case (_easting > 800000): {LOG("E8"); switch (_metaE) do {case 1: {_letterE="H"}; case 2: {_letterE="R"}; case 3: {_letterE="Z"}; }; }; -case (_easting > 700000): {LOG("E7"); switch (_metaE) do {case 1: {_letterE="G"}; case 2: {_letterE="Q"}; case 3: {_letterE="Y"}; }; }; -case (_easting > 600000): {LOG("E6"); switch (_metaE) do {case 1: {_letterE="F"}; case 2: {_letterE="P"}; case 3: {_letterE="X"}; }; }; -case (_easting > 500000): {LOG("E5"); switch (_metaE) do {case 1: {_letterE="E"}; case 2: {_letterE="N"}; case 3: {_letterE="W"}; }; }; -case (_easting > 400000): {LOG("E4"); switch (_metaE) do {case 1: {_letterE="D"}; case 2: {_letterE="M"}; case 3: {_letterE="V"}; }; }; -case (_easting > 300000): {LOG("E3"); switch (_metaE) do {case 1: {_letterE="C"}; case 2: {_letterE="L"}; case 3: {_letterE="U"}; }; }; -case (_easting > 200000): {LOG("E2"); switch (_metaE) do {case 1: {_letterE="B"}; case 2: {_letterE="K"}; case 3: {_letterE="T"}; }; }; -case (_easting > 100000): {LOG("E1"); switch (_metaE) do {case 1: {_letterE="A"}; case 2: {_letterE="J"}; case 3: {_letterE="S"}; }; }; + case (_zone == 0): {_letterE = "E"}; + case (_easting > 800000): {LOG("E8"); switch (_metaE) do {case 1: {_letterE="H"}; case 2: {_letterE="R"}; case 3: {_letterE="Z"}; }; }; + case (_easting > 700000): {LOG("E7"); switch (_metaE) do {case 1: {_letterE="G"}; case 2: {_letterE="Q"}; case 3: {_letterE="Y"}; }; }; + case (_easting > 600000): {LOG("E6"); switch (_metaE) do {case 1: {_letterE="F"}; case 2: {_letterE="P"}; case 3: {_letterE="X"}; }; }; + case (_easting > 500000): {LOG("E5"); switch (_metaE) do {case 1: {_letterE="E"}; case 2: {_letterE="N"}; case 3: {_letterE="W"}; }; }; + case (_easting > 400000): {LOG("E4"); switch (_metaE) do {case 1: {_letterE="D"}; case 2: {_letterE="M"}; case 3: {_letterE="V"}; }; }; + case (_easting > 300000): {LOG("E3"); switch (_metaE) do {case 1: {_letterE="C"}; case 2: {_letterE="L"}; case 3: {_letterE="U"}; }; }; + case (_easting > 200000): {LOG("E2"); switch (_metaE) do {case 1: {_letterE="B"}; case 2: {_letterE="K"}; case 3: {_letterE="T"}; }; }; + case (_easting > 100000): {LOG("E1"); switch (_metaE) do {case 1: {_letterE="A"}; case 2: {_letterE="J"}; case 3: {_letterE="S"}; }; }; default {_letterE="@"}; }; TRACE_1("",_letterE); @@ -129,37 +130,38 @@ _northing = _northing mod 2000000; TRACE_1("",_northing); switch (true) do { -case (_zone == 0): {_letterN = "N"}; -case (_northing > 1900000): {LOG("N19"); switch (_metaN) do {case 1: {_letterN = "V"}; case 2: {_letterN = "E"}; }; }; -case (_northing > 1800000): {LOG("N18"); switch (_metaN) do {case 1: {_letterN = "U"}; case 2: {_letterN = "D"}; }; }; -case (_northing > 1700000): {LOG("N17"); switch (_metaN) do {case 1: {_letterN = "T"}; case 2: {_letterN = "C"}; }; }; -case (_northing > 1600000): {LOG("N16"); switch (_metaN) do {case 1: {_letterN = "S"}; case 2: {_letterN = "B"}; }; }; -case (_northing > 1500000): {LOG("N15"); switch (_metaN) do {case 1: {_letterN = "R"}; case 2: {_letterN = "A"}; }; }; -case (_northing > 1400000): {LOG("N14"); switch (_metaN) do {case 1: {_letterN = "Q"}; case 2: {_letterN = "V"}; }; }; -case (_northing > 1300000): {LOG("N13"); switch (_metaN) do {case 1: {_letterN = "P"}; case 2: {_letterN = "U"}; }; }; -case (_northing > 1200000): {LOG("N12"); switch (_metaN) do {case 1: {_letterN = "N"}; case 2: {_letterN = "T"}; }; }; -case (_northing > 1100000): {LOG("N11"); switch (_metaN) do {case 1: {_letterN = "M"}; case 2: {_letterN = "S"}; }; }; -case (_northing > 1000000): {LOG("N10"); switch (_metaN) do {case 1: {_letterN = "L"}; case 2: {_letterN = "R"}; }; }; -case (_northing > 900000): {LOG("N09"); switch (_metaN) do {case 1: {_letterN = "K"}; case 2: {_letterN = "Q"}; }; }; -case (_northing > 800000): {LOG("N08"); switch (_metaN) do {case 1: {_letterN = "J"}; case 2: {_letterN = "P"}; }; }; -case (_northing > 700000): {LOG("N07"); switch (_metaN) do {case 1: {_letterN = "H"}; case 2: {_letterN = "N"}; }; }; -case (_northing > 600000): {LOG("N06"); switch (_metaN) do {case 1: {_letterN = "G"}; case 2: {_letterN = "M"}; }; }; -case (_northing > 500000): {LOG("N05"); switch (_metaN) do {case 1: {_letterN = "F"}; case 2: {_letterN = "L"}; }; }; -case (_northing > 400000): {LOG("N04"); switch (_metaN) do {case 1: {_letterN = "E"}; case 2: {_letterN = "K"}; }; }; -case (_northing > 300000): {LOG("N03"); switch (_metaN) do {case 1: {_letterN = "D"}; case 2: {_letterN = "J"}; }; }; -case (_northing > 200000): {LOG("N02"); switch (_metaN) do {case 1: {_letterN = "C"}; case 2: {_letterN = "H"}; }; }; -case (_northing > 100000): {LOG("N01"); switch (_metaN) do {case 1: {_letterN = "B"}; case 2: {_letterN = "G"}; }; }; -case (_northing > 0): {LOG("N00"); switch (_metaN) do {case 1: {_letterN = "A"}; case 2: {_letterN = "F"}; }; }; + case (_zone == 0): {_letterN = "N"}; + case (_northing > 1900000): {LOG("N19"); switch (_metaN) do {case 1: {_letterN = "V"}; case 2: {_letterN = "E"}; }; }; + case (_northing > 1800000): {LOG("N18"); switch (_metaN) do {case 1: {_letterN = "U"}; case 2: {_letterN = "D"}; }; }; + case (_northing > 1700000): {LOG("N17"); switch (_metaN) do {case 1: {_letterN = "T"}; case 2: {_letterN = "C"}; }; }; + case (_northing > 1600000): {LOG("N16"); switch (_metaN) do {case 1: {_letterN = "S"}; case 2: {_letterN = "B"}; }; }; + case (_northing > 1500000): {LOG("N15"); switch (_metaN) do {case 1: {_letterN = "R"}; case 2: {_letterN = "A"}; }; }; + case (_northing > 1400000): {LOG("N14"); switch (_metaN) do {case 1: {_letterN = "Q"}; case 2: {_letterN = "V"}; }; }; + case (_northing > 1300000): {LOG("N13"); switch (_metaN) do {case 1: {_letterN = "P"}; case 2: {_letterN = "U"}; }; }; + case (_northing > 1200000): {LOG("N12"); switch (_metaN) do {case 1: {_letterN = "N"}; case 2: {_letterN = "T"}; }; }; + case (_northing > 1100000): {LOG("N11"); switch (_metaN) do {case 1: {_letterN = "M"}; case 2: {_letterN = "S"}; }; }; + case (_northing > 1000000): {LOG("N10"); switch (_metaN) do {case 1: {_letterN = "L"}; case 2: {_letterN = "R"}; }; }; + case (_northing > 900000): {LOG("N09"); switch (_metaN) do {case 1: {_letterN = "K"}; case 2: {_letterN = "Q"}; }; }; + case (_northing > 800000): {LOG("N08"); switch (_metaN) do {case 1: {_letterN = "J"}; case 2: {_letterN = "P"}; }; }; + case (_northing > 700000): {LOG("N07"); switch (_metaN) do {case 1: {_letterN = "H"}; case 2: {_letterN = "N"}; }; }; + case (_northing > 600000): {LOG("N06"); switch (_metaN) do {case 1: {_letterN = "G"}; case 2: {_letterN = "M"}; }; }; + case (_northing > 500000): {LOG("N05"); switch (_metaN) do {case 1: {_letterN = "F"}; case 2: {_letterN = "L"}; }; }; + case (_northing > 400000): {LOG("N04"); switch (_metaN) do {case 1: {_letterN = "E"}; case 2: {_letterN = "K"}; }; }; + case (_northing > 300000): {LOG("N03"); switch (_metaN) do {case 1: {_letterN = "D"}; case 2: {_letterN = "J"}; }; }; + case (_northing > 200000): {LOG("N02"); switch (_metaN) do {case 1: {_letterN = "C"}; case 2: {_letterN = "H"}; }; }; + case (_northing > 100000): {LOG("N01"); switch (_metaN) do {case 1: {_letterN = "B"}; case 2: {_letterN = "G"}; }; }; + case (_northing > 0): {LOG("N00"); switch (_metaN) do {case 1: {_letterN = "A"}; case 2: {_letterN = "F"}; }; }; }; TRACE_1("",_letterN); -_grid100km = _letterE+_letterN; +_grid100km = _letterE + _letterN; TRACE_1("",_grid100km); if (_map == worldName) then { - GVAR(MGRS_data) = [_GZD,_grid100km,_GZD+_grid100km]; + GVAR(MGRS_data) = [_GZD, _grid100km, _GZD + _grid100km]; GVAR(mapAltitude) = _altitude; GVAR(mapLatitude) = _lat; GVAR(mapLongitude) = _long; }; -[_GZD,_grid100km,_GZD+_grid100km] \ No newline at end of file + +[_GZD, _grid100km, _GZD + _grid100km] diff --git a/addons/common/functions/fnc_getMapGridFromPos.sqf b/addons/common/functions/fnc_getMapGridFromPos.sqf index 983b78ffff..1f946a6e80 100644 --- a/addons/common/functions/fnc_getMapGridFromPos.sqf +++ b/addons/common/functions/fnc_getMapGridFromPos.sqf @@ -2,57 +2,58 @@ * Author: VKing, PabstMirror * Gets a 10-digit map grid for the given world position * - * Argument: + * Arguments: * 0: Position (2D Position) - * 1: Return type; false for array of easting and northing, true for single string + * 1: Return type; false for array of easting and northing, true for single string (default: false) * - * Return values: + * Return Value: * 0: Easting * 1: Northing * * Example: - * [(getPos player)] call ace_common_fnc_getMapGridFromPos; + * [getPos player] call ace_common_fnc_getMapGridFromPos * * Public: Yes */ -// #define DEBUG_MODE_FULL #include "script_component.hpp" -PARAMS_1(_pos); -DEFAULT_PARAM(1,_returnSingleString,false); +params ["_pos", ["_returnSingleString", false]]; -private["_count", "_easting", "_nativeGrid", "_northing"]; +private ["_nativeGrid", "_count", "_easting", "_northing"]; //Fallback, when map data is weird (letters) -if ((count GVAR(mapGridData)) == 0) exitWith { +if (GVAR(mapGridData) isEqualTo []) exitWith { _nativeGrid = mapGridPosition _pos; + if (_returnSingleString) then { _nativeGrid } else { _count = floor ((count _nativeGrid) / 2); - [(_nativeGrid select [0, _count]), (_nativeGrid select [_count, _count])] + [_nativeGrid select [0, _count], _nativeGrid select [_count, _count]] }; }; -EXPLODE_4_PVT(GVAR(mapGridData),_offsetX,_realOffsetY,_stepXat5,_stepYat5); +GVAR(mapGridData) params ["_offsetX", "_realOffsetY", "_stepXat5", "_stepYat5"]; + _easting = floor (((_pos select 0) - _offsetX) / _stepXat5); _northing = floor (((_pos select 1) - _realOffsetY) / _stepYat5); //Attempt to handle negative east/north (e.g.: moving west of map bounds) if (_easting > 0) then { _easting = str _easting; - while {count _easting < 5} do {_easting = "0" + _easting;}; + while {count _easting < 5} do {_easting = "0" + _easting}; } else { _easting = str abs _easting; - while {count _easting < 4} do {_easting = "0" + _easting;}; + while {count _easting < 4} do {_easting = "0" + _easting}; _easting = "-" + _easting; }; + if (_northing > 0) then { _northing = str _northing; - while {count _northing < 5} do {_northing = "0" + _northing;}; + while {count _northing < 5} do {_northing = "0" + _northing}; } else { _northing = str abs _northing; - while {count _northing < 4} do {_northing = "0" + _northing;}; + while {count _northing < 4} do {_northing = "0" + _northing}; _northing = "-" + _northing; }; @@ -60,4 +61,4 @@ if (_returnSingleString) then { _easting + _northing } else { [_easting, _northing] -}; +}; // return From 3037181fc2b6aeef5082a25a362bfc50d559a9a2 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 17:00:53 +0200 Subject: [PATCH 24/29] more common code cleanup --- addons/common/XEH_postInit.sqf | 426 +++++++++++++++++++-------------- 1 file changed, 248 insertions(+), 178 deletions(-) diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index a9db9bb92e..9f9824efb5 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -1,16 +1,18 @@ // ACE - Common - -// #define ENABLE_PERFORMANCE_COUNTERS #include "script_component.hpp" -//IGNORE_PRIVATE_WARNING("_handleNetEvent", "_handleRequestAllSyncedEvents", "_handleRequestSyncedEvent", "_handleSyncedEvent"); +// #define ENABLE_PERFORMANCE_COUNTERS + +////////////////////////////////////////////////// +// PFHs +////////////////////////////////////////////////// //Singe PFEH to handle execNextFrame and waitAndExec: [{ - private ["_entry"]; + private "_entry"; //Handle the waitAndExec array: - while {((count GVAR(waitAndExecArray)) > 0) && {((GVAR(waitAndExecArray) select 0) select 0) <= ACE_Time}} do { + while {!(GVAR(waitAndExecArray) isEqualTo []) && {GVAR(waitAndExecArray) select 0 select 0 <= ACE_Time}} do { _entry = GVAR(waitAndExecArray) deleteAt 0; (_entry select 2) call (_entry select 1); }; @@ -18,7 +20,9 @@ //Handle the execNextFrame array: { (_x select 0) call (_x select 1); - } forEach GVAR(nextFrameBufferA); + false + } count GVAR(nextFrameBufferA); + //Swap double-buffer: GVAR(nextFrameBufferA) = GVAR(nextFrameBufferB); GVAR(nextFrameBufferB) = []; @@ -26,39 +30,46 @@ }, 0, []] call CBA_fnc_addPerFrameHandler; -// Listens for global "SettingChanged" events, to update the force status locally -["SettingChanged", { - PARAMS_2(_name,_value); - if !(count _this > 2) exitWith {}; - private ["_force", "_settingData"]; - _force = _this select 2; - if (_force) then { - _settingData = [_name] call FUNC(getSettingData); - if (count _settingData == 0) exitWith {}; - _settingData set [6,_force]; - }; -}] call FUNC(addEventhandler); +////////////////////////////////////////////////// +// Get Map Data +////////////////////////////////////////////////// - -["HeadbugFixUsed", { - PARAMS_2(_profileName,_animation); - ACE_LOGINFO_2("Headbug Used: Name: %1, Animation: %2",_profileName,_animation); -}] call FUNC(addEventHandler); - - -//~~~~~Get Map Data~~~~~ //Find MGRS zone and 100km grid for current map [] call FUNC(getMGRSdata); //Prepare variables for FUNC(getMapGridFromPos)/FUNC(getMapPosFromGrid) [] call FUNC(getMapGridData); +////////////////////////////////////////////////// +// Eventhandlers +////////////////////////////////////////////////// -["fixCollision", DFUNC(fixCollision)] call FUNC(addEventhandler); -["fixFloating", DFUNC(fixFloating)] call FUNC(addEventhandler); -["fixPosition", DFUNC(fixPosition)] call FUNC(addEventhandler); +// Listens for global "SettingChanged" events, to update the force status locally +["SettingChanged", { + params ["_name", "_value", "_force"]; -["unloadPersonEvent", DFUNC(unloadPersonLocal)] call FUNC(addEventhandler); + if (_force) then { + private "_settingData"; + _settingData = [_name] call FUNC(getSettingData); + + if (_settingData isEqualTo []) exitWith {}; + + _settingData set [6, _force]; + }; +}] call FUNC(addEventhandler); + + +// Event to log Fix Headbug output +["HeadbugFixUsed", { + params ["_profileName", "_animation"]; + ACE_LOGINFO_2("Headbug Used: Name: %1, Animation: %2",_profileName,_animation); +}] call FUNC(addEventHandler); + +["fixCollision", FUNC(fixCollision)] call FUNC(addEventhandler); +["fixFloating", FUNC(fixFloating)] call FUNC(addEventhandler); +["fixPosition", FUNC(fixPosition)] call FUNC(addEventhandler); + +["unloadPersonEvent", FUNC(unloadPersonLocal)] call FUNC(addEventhandler); ["lockVehicle", { _this setVariable [QGVAR(lockStatus), locked _this]; @@ -77,22 +88,10 @@ if (isServer) then { ["hideObjectGlobal", {(_this select 0) hideObjectGlobal (_this select 1)}] call FUNC(addEventHandler); }; -QGVAR(remoteFnc) addPublicVariableEventHandler { - (_this select 1) call FUNC(execRemoteFnc); -}; -[missionNamespace] call FUNC(executePersistent); - -private ["_currentVersion", "_previousVersion"]; -// check previous version number from profile -_currentVersion = getText (configFile >> "CfgPatches" >> QUOTE(ADDON) >> "version"); -_previousVersion = profileNamespace getVariable ["ACE_VersionNumberString", ""]; - -if (_currentVersion != _previousVersion) then { - // do something - - profileNamespace setVariable ["ACE_VersionNumberString", _currentVersion]; -}; +////////////////////////////////////////////////// +// Set up remote execution +////////////////////////////////////////////////// // ACE events "ACEg" addPublicVariableEventHandler { _this call FUNC(_handleNetEvent); }; @@ -100,7 +99,7 @@ if (_currentVersion != _previousVersion) then { // Synced ACE events // Handle JIP scenario -if(!isServer) then { +if (!isServer) then { ["PlayerJip", { ACE_LOGINFO("JIP event synchronization initialized"); ["SEH_all", [player]] call FUNC(serverEvent); @@ -108,31 +107,72 @@ if(!isServer) then { } else { ["SEH_all", FUNC(_handleRequestAllSyncedEvents)] call FUNC(addEventHandler); }; + ["SEH", FUNC(_handleSyncedEvent)] call FUNC(addEventHandler); ["SEH_s", FUNC(_handleRequestSyncedEvent)] call FUNC(addEventHandler); + if (isServer) then { [FUNC(syncedEventPFH), 0.5, []] call CBA_fnc_addPerFrameHandler; }; +// @todo deprecated +QGVAR(remoteFnc) addPublicVariableEventHandler { + (_this select 1) call FUNC(execRemoteFnc); +}; + +// @todo figure out what this does. +[missionNamespace] call FUNC(executePersistent); + + +////////////////////////////////////////////////// +// Check files, previous installed version etc. +////////////////////////////////////////////////// + +private ["_currentVersion", "_previousVersion"]; + +_currentVersion = getText (configFile >> "CfgPatches" >> QUOTE(ADDON) >> "version"); +_previousVersion = profileNamespace getVariable ["ACE_VersionNumberString", ""]; + +// check previous version number from profile +if (_currentVersion != _previousVersion) then { + // do something + + profileNamespace setVariable ["ACE_VersionNumberString", _currentVersion]; +}; + call FUNC(checkFiles); +////////////////////////////////////////////////// +// Set up SettingsInitialized eventhandler +////////////////////////////////////////////////// + +["SettingsInitialized", { + [ + GVAR(checkPBOsAction), + GVAR(checkPBOsCheckAll), + call compile GVAR(checkPBOsWhitelist) + ] call FUNC(checkPBOs) +}] call FUNC(addEventHandler); + // Create a pfh to wait until all postinits are ready and settings are initialized [{ - PARAMS_1(_args); - EXPLODE_1_PVT(_args,_waitingMsgSent); + params ["_args"]; + + _args params ["_waitingMsgSent"]; + // If post inits are not ready then wait if !(SLX_XEH_MACHINE select 8) exitWith {}; // If settings are not initialized then wait - if (isNil QGVAR(settings) || {(!isServer) && (isNil QEGVAR(modules,serverModulesRead))}) exitWith { - if (!_waitingMsgSent) then { + if (isNil QGVAR(settings) || {!isServer && isNil QEGVAR(modules,serverModulesRead)}) exitWith { + if !(_waitingMsgSent) then { _args set [0, true]; ACE_LOGINFO("Waiting on settings from server..."); }; }; - [(_this select 1)] call cba_fnc_removePerFrameHandler; + [_this select 1] call CBA_fnc_removePerFrameHandler; ACE_LOGINFO("Settings received from server."); @@ -152,36 +192,31 @@ call FUNC(checkFiles); //Set init finished and run all delayed functions: GVAR(settingsInitFinished) = true; - diag_log text format ["[ACE] %1 delayed functions running", (count GVAR(runAtSettingsInitialized))]; + ACE_LOGINFO_1(%1 delayed functions running.,count GVAR(runAtSettingsInitialized)) + { - _x params ["_func", "_params"]; - _params call _func; - } forEach GVAR(runAtSettingsInitialized); + (_x select 1) call (_x select 0); + false + } count GVAR(runAtSettingsInitialized); + GVAR(runAtSettingsInitialized) = nil; //cleanup - }, 0, [false]] call CBA_fnc_addPerFrameHandler; -["SettingsInitialized", { - [ - GVAR(checkPBOsAction), - GVAR(checkPBOsCheckAll), - call compile GVAR(checkPBOsWhitelist) - ] call FUNC(checkPBOs) -}] call FUNC(addEventHandler); +/***************************************************************************/ +/***************************************************************************/ +/** everything that only player controlled machines need, goes below this **/ +/***************************************************************************/ +/***************************************************************************/ - -/***************************************************************/ -/***************************************************************/ -/***************************************************************/ -/***************************************************************/ -/***************************************************************/ - -// everything that only player controlled machines need, goes below this if (!hasInterface) exitWith {}; -call COMPILE_FILE(scripts\assignedItemFix); -call COMPILE_FILE(scripts\initScrollWheel); +////////////////////////////////////////////////// +// Set up mouse wheel eventhandler +////////////////////////////////////////////////// + +call COMPILE_FILE(scripts\assignedItemFix);///////////// +call COMPILE_FILE(scripts\initScrollWheel);///////////// DFUNC(mouseZHandler) = { waitUntil {!isNull (findDisplay 46)}; sleep 0.1; @@ -192,142 +227,175 @@ DFUNC(mouseZHandler) = { addMissionEventHandler ["Loaded", {[] spawn FUNC(mouseZHandler)}]; [] spawn FUNC(mouseZHandler); +/* +call FUNC(assignedItemFix); +GVAR(ScrollWheelFrame) = diag_frameno; + +addMissionEventHandler ["Loaded", {call FUNC(mouseZHandler)}]; +call FUNC(mouseZHandler); +*/ +// @todo remove? enableCamShake true; + +////////////////////////////////////////////////// +// Eventhandler to set player names +////////////////////////////////////////////////// + // Set the name for the current player ["playerChanged", { - EXPLODE_2_PVT(_this,_newPlayer,_oldPlayer); + params ["_newPlayer","_oldPlayer"]; if (alive _newPlayer) then { - [_newPlayer] call FUNC(setName) - }; - if (alive _oldPlayer) then { - [_oldPlayer] call FUNC(setName) + [_newPlayer] call FUNC(setName); }; + if (alive _oldPlayer) then { + [_oldPlayer] call FUNC(setName); + }; }] call FUNC(addEventhandler); -GVAR(OldPlayerInventory) = [ACE_player] call FUNC(getAllGear); -GVAR(OldPlayerVisionMode) = currentVisionMode ACE_player; -GVAR(OldZeusDisplayIsOpen) = !(isNull findDisplay 312); -GVAR(OldCameraView) = cameraView; -GVAR(OldPlayerVehicle) = vehicle ACE_player; -GVAR(OldPlayerTurret) = [ACE_player] call FUNC(getTurretIndex); -GVAR(OldPlayerWeapon) = currentWeapon ACE_player; + +////////////////////////////////////////////////// +// Set up numerous eventhanders for player controlled units +////////////////////////////////////////////////// + +// default variables +GVAR(OldPlayerVehicle) = vehicle objNull; +GVAR(OldPlayerTurret) = [objNull] call FUNC(getTurretIndex); +GVAR(OldPlayerWeapon) = currentWeapon objNull; +GVAR(OldPlayerInventory) = [objNull] call FUNC(getAllGear); +GVAR(OldPlayerVisionMode) = currentVisionMode objNull; +GVAR(OldCameraView) = ""; GVAR(OldVisibleMap) = false; +GVAR(OldInventoryDisplayIsOpen) = nil; //@todo check this +GVAR(OldZeusDisplayIsOpen) = false; +GVAR(OldIsCamera) = false; // PFH to raise varios events [{ BEGIN_COUNTER(stateChecker); - private ["_newCameraView", "_newInventoryDisplayIsOpen", "_newPlayerInventory", "_newPlayerTurret", "_newPlayerVehicle", "_newPlayerVisionMode", "_newPlayerWeapon", "_newZeusDisplayIsOpen", "_newVisibleMap"]; - // "playerInventoryChanged" event - _newPlayerInventory = [ACE_player] call FUNC(getAllGear); - if !(_newPlayerInventory isEqualTo GVAR(OldPlayerInventory)) then { - // Raise ACE event locally - GVAR(OldPlayerInventory) = _newPlayerInventory; - ["playerInventoryChanged", [ACE_player, _newPlayerInventory]] call FUNC(localEvent); - }; - - // "playerVisionModeChanged" event - _newPlayerVisionMode = currentVisionMode ACE_player; - if !(_newPlayerVisionMode isEqualTo GVAR(OldPlayerVisionMode)) then { - // Raise ACE event locally - GVAR(OldPlayerVisionMode) = _newPlayerVisionMode; - ["playerVisionModeChanged", [ACE_player, _newPlayerVisionMode]] call FUNC(localEvent); - }; - - // "inventoryDisplayChanged" event - _newInventoryDisplayIsOpen = !(isNull findDisplay 602); - if !(_newInventoryDisplayIsOpen isEqualTo GVAR(OldInventoryDisplayIsOpen)) then { - // Raise ACE event locally - GVAR(OldInventoryDisplayIsOpen) = _newInventoryDisplayIsOpen; - ["inventoryDisplayChanged", [ACE_player, _newInventoryDisplayIsOpen]] call FUNC(localEvent); - }; - - // "zeusDisplayChanged" event - _newZeusDisplayIsOpen = !(isNull findDisplay 312); - if !(_newZeusDisplayIsOpen isEqualTo GVAR(OldZeusDisplayIsOpen)) then { - // Raise ACE event locally - GVAR(OldZeusDisplayIsOpen) = _newZeusDisplayIsOpen; - ["zeusDisplayChanged", [ACE_player, _newZeusDisplayIsOpen]] call FUNC(localEvent); - }; - - // "cameraViewChanged" event - _newCameraView = cameraView; - if !(_newCameraView isEqualTo GVAR(OldCameraView)) then { - // Raise ACE event locally - GVAR(OldCameraView) = _newCameraView; - ["cameraViewChanged", [ACE_player, _newCameraView]] call FUNC(localEvent); - }; + private "_data"; // reuse one variable to reduce number of variables that have to be set to private each frame // "playerVehicleChanged" event - _newPlayerVehicle = vehicle ACE_player; - if !(_newPlayerVehicle isEqualTo GVAR(OldPlayerVehicle)) then { + _data = vehicle ACE_player; + if !(_data isEqualTo GVAR(OldPlayerVehicle)) then { // Raise ACE event locally - GVAR(OldPlayerVehicle) = _newPlayerVehicle; - ["playerVehicleChanged", [ACE_player, _newPlayerVehicle]] call FUNC(localEvent); + GVAR(OldPlayerVehicle) = _data; + ["playerVehicleChanged", [ACE_player, _data]] call FUNC(localEvent); }; // "playerTurretChanged" event - _newPlayerTurret = [ACE_player] call FUNC(getTurretIndex); - if !(_newPlayerTurret isEqualTo GVAR(OldPlayerTurret)) then { + _data = [ACE_player] call FUNC(getTurretIndex); + if !(_data isEqualTo GVAR(OldPlayerTurret)) then { // Raise ACE event locally - GVAR(OldPlayerTurret) = _newPlayerTurret; - ["playerTurretChanged", [ACE_player, _newPlayerTurret]] call FUNC(localEvent); + GVAR(OldPlayerTurret) = _data; + ["playerTurretChanged", [ACE_player, _data]] call FUNC(localEvent); }; // "playerWeaponChanged" event - _newPlayerWeapon = currentWeapon ACE_player; - if (_newPlayerWeapon != GVAR(OldPlayerWeapon)) then { + _data = currentWeapon ACE_player; + if (_data != GVAR(OldPlayerWeapon)) then { // Raise ACE event locally - GVAR(OldPlayerWeapon) = _newPlayerWeapon; - ["playerWeaponChanged", [ACE_player, _newPlayerWeapon]] call FUNC(localEvent); + GVAR(OldPlayerWeapon) = _data; + ["playerWeaponChanged", [ACE_player, _data]] call FUNC(localEvent); + }; + + // "playerInventoryChanged" event + _data = [ACE_player] call FUNC(getAllGear); + if !(_data isEqualTo GVAR(OldPlayerInventory)) then { + // Raise ACE event locally + GVAR(OldPlayerInventory) = _data; + ["playerInventoryChanged", [ACE_player, _data]] call FUNC(localEvent); + }; + + // "playerVisionModeChanged" event + _data = currentVisionMode ACE_player; + if !(_data isEqualTo GVAR(OldPlayerVisionMode)) then { + // Raise ACE event locally + GVAR(OldPlayerVisionMode) = _data; + ["playerVisionModeChanged", [ACE_player, _data]] call FUNC(localEvent); + }; + + // "cameraViewChanged" event + _data = cameraView; + if !(_data isEqualTo GVAR(OldCameraView)) then { + // Raise ACE event locally + GVAR(OldCameraView) = _data; + ["cameraViewChanged", [ACE_player, _data]] call FUNC(localEvent); }; // "visibleMapChanged" event - _newVisibleMap = visibleMap; - if (!_newVisibleMap isEqualTo GVAR(OldVisibleMap)) then { + _data = visibleMap; + if (!_data isEqualTo GVAR(OldVisibleMap)) then { // Raise ACE event locally - GVAR(OldVisibleMap) = _newVisibleMap; - ["visibleMapChanged", [ACE_player, _newVisibleMap]] call FUNC(localEvent); + GVAR(OldVisibleMap) = _data; + ["visibleMapChanged", [ACE_player, _data]] call FUNC(localEvent); + }; + + // "inventoryDisplayChanged" event + _data = !(isNull findDisplay 602); + if !(_data isEqualTo GVAR(OldInventoryDisplayIsOpen)) then { + // Raise ACE event locally + GVAR(OldInventoryDisplayIsOpen) = _data; + ["inventoryDisplayChanged", [ACE_player, _data]] call FUNC(localEvent); + }; + + // "zeusDisplayChanged" event + _data = !(isNull findDisplay 312); + if !(_data isEqualTo GVAR(OldZeusDisplayIsOpen)) then { + // Raise ACE event locally + GVAR(OldZeusDisplayIsOpen) = _data; + ["zeusDisplayChanged", [ACE_player, _data]] call FUNC(localEvent); + }; + + // "activeCameraChanged" event + _data = call FUNC(isfeatureCameraActive); + if !(_data isEqualTo GVAR(OldIsCamera)) then { + // Raise ACE event locally + GVAR(OldIsCamera) = _data; + ["activeCameraChanged", [ACE_player, _data]] call FUNC(localEvent); }; END_COUNTER(stateChecker); - }, 0, []] call CBA_fnc_addPerFrameHandler; -GVAR(OldIsCamera) = false; +////////////////////////////////////////////////// +// Eventhandlers for player controlled machines +////////////////////////////////////////////////// -[{ - - // "activeCameraChanged" event - private ["_isCamera"]; - _isCamera = call FUNC(isfeatureCameraActive); - if !(_isCamera isEqualTo GVAR(OldIsCamera)) then { - // Raise ACE event locally - GVAR(OldIsCamera) = _isCamera; - ["activeCameraChanged", [ACE_player, _isCamera]] call FUNC(localEvent); - }; - -}, 1, []] call CBA_fnc_addPerFrameHandler; // feel free to decrease the sleep ACE_time if you need it. - - -[QGVAR(StateArrested),false,true,QUOTE(ADDON)] call FUNC(defineVariable); +// @todo still needed? +[QGVAR(StateArrested), false, true, QUOTE(ADDON)] call FUNC(defineVariable); ["displayTextStructured", FUNC(displayTextStructured)] call FUNC(addEventhandler); ["displayTextPicture", FUNC(displayTextPicture)] call FUNC(addEventhandler); -["medical_onUnconscious", {if (local (_this select 0) && {!(_this select 1)}) then {[ _this select 0, false, QUOTE(FUNC(loadPerson)), west /* dummy side */] call FUNC(switchToGroupSide);};}] call FUNC(addEventhandler); + +["medical_onUnconscious", { + params ["_unit", "_isUnconscious"]; + + if (local _unit && {!_isUnconscious}) then { + [_unit, false, QFUNC(loadPerson), west /* dummy side */] call FUNC(switchToGroupSide); + }; +}] call FUNC(addEventhandler); + + +////////////////////////////////////////////////// +// Add various canInteractWith conditions +////////////////////////////////////////////////// ["notOnMap", {!visibleMap}] call FUNC(addCanInteractWithCondition); + ["isNotInside", { + params ["_unit", "_target"]; + // Players can always interact with himself if not boarded - vehicle (_this select 0) == (_this select 0) || + vehicle _unit == _unit || // Players can always interact with his vehicle - {vehicle (_this select 0) == (_this select 1)} || + {vehicle _unit == _target} || // Players can always interact with passengers of the same vehicle - {!((_this select 0) isEqualTo (_this select 1)) && {vehicle (_this select 0) == vehicle (_this select 1)}} + {_unit != _target && {vehicle _unit == vehicle _target}} }] call FUNC(addCanInteractWithCondition); // Lastly, do JIP events @@ -337,45 +405,47 @@ if (didJip) then { [{ if((!(isNull player)) && GVAR(settingsInitFinished)) then { ["PlayerJip", [player] ] call FUNC(localEvent); - [(_this select 1)] call cba_fnc_removePerFrameHandler; + [(_this select 1)] call CBA_fnc_removePerFrameHandler; }; }, 0, []] call CBA_fnc_addPerFrameHandler; }; + +////////////////////////////////////////////////// +// CBA key input handling +////////////////////////////////////////////////// + //Device Handler: GVAR(deviceKeyHandlingArray) = []; GVAR(deviceKeyCurrentIndex) = -1; // Register localizations for the Keybinding categories -["ACE3 Equipment", localize LSTRING(ACEKeybindCategoryEquipment)] call cba_fnc_registerKeybindModPrettyName; -["ACE3 Common", localize LSTRING(ACEKeybindCategoryCommon)] call cba_fnc_registerKeybindModPrettyName; -["ACE3 Weapons", localize LSTRING(ACEKeybindCategoryWeapons)] call cba_fnc_registerKeybindModPrettyName; -["ACE3 Movement", localize LSTRING(ACEKeybindCategoryMovement)] call cba_fnc_registerKeybindModPrettyName; -["ACE3 Scope Adjustment", localize LSTRING(ACEKeybindCategoryScopeAdjustment)] call cba_fnc_registerKeybindModPrettyName; -["ACE3 Vehicles", localize LSTRING(ACEKeybindCategoryVehicles)] call cba_fnc_registerKeybindModPrettyName; +["ACE3 Equipment", localize LSTRING(ACEKeybindCategoryEquipment)] call CBA_fnc_registerKeybindModPrettyName; +["ACE3 Common", localize LSTRING(ACEKeybindCategoryCommon)] call CBA_fnc_registerKeybindModPrettyName; +["ACE3 Weapons", localize LSTRING(ACEKeybindCategoryWeapons)] call CBA_fnc_registerKeybindModPrettyName; +["ACE3 Movement", localize LSTRING(ACEKeybindCategoryMovement)] call CBA_fnc_registerKeybindModPrettyName; +["ACE3 Scope Adjustment", localize LSTRING(ACEKeybindCategoryScopeAdjustment)] call CBA_fnc_registerKeybindModPrettyName; +["ACE3 Vehicles", localize LSTRING(ACEKeybindCategoryVehicles)] call CBA_fnc_registerKeybindModPrettyName; -["ACE3 Equipment", QGVAR(openDevice), (localize "STR_ACE_Common_toggleHandheldDevice"), -{ +["ACE3 Equipment", QGVAR(openDevice), (localize "STR_ACE_Common_toggleHandheldDevice"), { [] call FUNC(deviceKeyFindValidIndex); if (GVAR(deviceKeyCurrentIndex) == -1) exitWith {false}; [] call ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 3); true }, {false}, -[0xC7, [false, false, false]], false] call cba_fnc_addKeybind; //Home Key +[0xC7, [false, false, false]], false] call CBA_fnc_addKeybind; //Home Key -["ACE3 Equipment", QGVAR(closeDevice), (localize "STR_ACE_Common_closeHandheldDevice"), -{ +["ACE3 Equipment", QGVAR(closeDevice), (localize "STR_ACE_Common_closeHandheldDevice"), { [] call FUNC(deviceKeyFindValidIndex); if (GVAR(deviceKeyCurrentIndex) == -1) exitWith {false}; [] call ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 4); true }, {false}, -[0xC7, [false, true, false]], false] call cba_fnc_addKeybind; //CTRL + Home Key +[0xC7, [false, true, false]], false] call CBA_fnc_addKeybind; //CTRL + Home Key -["ACE3 Equipment", QGVAR(cycleDevice), (localize "STR_ACE_Common_cycleHandheldDevices"), -{ +["ACE3 Equipment", QGVAR(cycleDevice), (localize "STR_ACE_Common_cycleHandheldDevices"), { [1] call FUNC(deviceKeyFindValidIndex); if (GVAR(deviceKeyCurrentIndex) == -1) exitWith {false}; _displayName = ((GVAR(deviceKeyHandlingArray) select GVAR(deviceKeyCurrentIndex)) select 0); @@ -384,6 +454,6 @@ GVAR(deviceKeyCurrentIndex) = -1; true }, {false}, -[0xC7, [true, false, false]], false] call cba_fnc_addKeybind; //SHIFT + Home Key +[0xC7, [true, false, false]], false] call CBA_fnc_addKeybind; //SHIFT + Home Key GVAR(commonPostInited) = true; From b5b5c761c4b87fb65e365b7d441bb7dd63df7c1b Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 17:09:10 +0200 Subject: [PATCH 25/29] fix missing '' in info log macro --- addons/common/XEH_postInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 9f9824efb5..96c803a409 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -192,7 +192,7 @@ call FUNC(checkFiles); //Set init finished and run all delayed functions: GVAR(settingsInitFinished) = true; - ACE_LOGINFO_1(%1 delayed functions running.,count GVAR(runAtSettingsInitialized)) + ACE_LOGINFO_1("%1 delayed functions running.",count GVAR(runAtSettingsInitialized)) { (_x select 1) call (_x select 0); From 13b487e13b767bab50816e3d891a0d5c21f0b1f8 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 17:13:28 +0200 Subject: [PATCH 26/29] fix missing ; --- addons/common/XEH_postInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 96c803a409..9c494ff859 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -192,7 +192,7 @@ call FUNC(checkFiles); //Set init finished and run all delayed functions: GVAR(settingsInitFinished) = true; - ACE_LOGINFO_1("%1 delayed functions running.",count GVAR(runAtSettingsInitialized)) + ACE_LOGINFO_1("%1 delayed functions running.",count GVAR(runAtSettingsInitialized)); { (_x select 1) call (_x select 0); From 1a4ebdac5160b217993adbd7508a63892b85fc1e Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 17:32:21 +0200 Subject: [PATCH 27/29] more common code cleanup --- addons/common/XEH_postInit.sqf | 19 +++++++++++++++++++ addons/common/XEH_preInit.sqf | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 9c494ff859..2359a50f7e 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -273,11 +273,30 @@ GVAR(OldInventoryDisplayIsOpen) = nil; //@todo check this GVAR(OldZeusDisplayIsOpen) = false; GVAR(OldIsCamera) = false; +// clean up playerChanged eventhandler from preinit and put it in the same PFH as the other events to reduce overhead and guarantee advantageous execution order +if (!isNil QGVAR(PreInit_playerChanged_PFHID)) then { + [GVAR(PreInit_playerChanged_PFHID)] call CBA_fnc_removePerFrameHandler; + GVAR(PreInit_playerChanged_PFHID) = nil; +}; + // PFH to raise varios events [{ BEGIN_COUNTER(stateChecker); private "_data"; // reuse one variable to reduce number of variables that have to be set to private each frame + // "playerChanged" event + _data = call FUNC(player); + if !(_data isEqualTo GVAR(OldPlayerVehicle)) then { + private "_oldPlayer"; + _oldPlayer = ACE_player; + + ACE_player = _data; + uiNamespace setVariable ["ACE_player", _data]; + + // Raise ACE event locally + ["playerChanged", [ACE_player, _oldPlayer]] call FUNC(localEvent); + }; + // "playerVehicleChanged" event _data = vehicle ACE_player; if !(_data isEqualTo GVAR(OldPlayerVehicle)) then { diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 9db3794a81..44c5da6293 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -306,11 +306,11 @@ if (isServer) then { call FUNC(loadSettingsOnServer); }; -ACE_player = player; +ACE_player = objNull; if (hasInterface) then { // PFH to update the ACE_player variable - [{ + GVAR(PreInit_playerChanged_PFHID) = [{ if !(ACE_player isEqualTo (call FUNC(player))) then { private ["_oldPlayer"]; _oldPlayer = ACE_player; From 8503d15c9b64eefeaad95d23bb20c0d8dd8130b3 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 18:37:19 +0200 Subject: [PATCH 28/29] more common code cleanup --- addons/common/XEH_postInit.sqf | 33 ++++----- addons/common/XEH_preInit.sqf | 58 ++++++++------- .../common/functions/fnc_assignedItemFix.sqf | 73 +++++++++++++++++++ .../functions/fnc_handleScrollWheel.sqf | 25 +++++++ .../functions/fnc_handleScrollWheelInit.sqf | 15 ++++ addons/common/scripts/assignedItemFix.sqf | 64 ---------------- addons/common/scripts/initScrollWheel.sqf | 16 ---- addons/main/script_macros.hpp | 2 + 8 files changed, 159 insertions(+), 127 deletions(-) create mode 100644 addons/common/functions/fnc_assignedItemFix.sqf create mode 100644 addons/common/functions/fnc_handleScrollWheel.sqf create mode 100644 addons/common/functions/fnc_handleScrollWheelInit.sqf delete mode 100644 addons/common/scripts/assignedItemFix.sqf delete mode 100644 addons/common/scripts/initScrollWheel.sqf diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 2359a50f7e..e374a7a716 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -215,25 +215,12 @@ if (!hasInterface) exitWith {}; // Set up mouse wheel eventhandler ////////////////////////////////////////////////// -call COMPILE_FILE(scripts\assignedItemFix);///////////// -call COMPILE_FILE(scripts\initScrollWheel);///////////// - -DFUNC(mouseZHandler) = { - waitUntil {!isNull (findDisplay 46)}; sleep 0.1; - findDisplay 46 displayAddEventHandler ["MouseZChanged", QUOTE( _this call GVAR(onScrollWheel) )]; - [false] call FUNC(disableUserInput); -}; - -addMissionEventHandler ["Loaded", {[] spawn FUNC(mouseZHandler)}]; -[] spawn FUNC(mouseZHandler); - -/* call FUNC(assignedItemFix); + GVAR(ScrollWheelFrame) = diag_frameno; - -addMissionEventHandler ["Loaded", {call FUNC(mouseZHandler)}]; -call FUNC(mouseZHandler); -*/ + +addMissionEventHandler ["Loaded", {call FUNC(handleScrollWheelInit)}]; +call FUNC(handleScrollWheelInit); // @todo remove? enableCamShake true; @@ -417,14 +404,20 @@ if (!isNil QGVAR(PreInit_playerChanged_PFHID)) then { {_unit != _target && {vehicle _unit == vehicle _target}} }] call FUNC(addCanInteractWithCondition); + +////////////////////////////////////////////////// +// Set up PlayerJIP eventhandler +////////////////////////////////////////////////// + // Lastly, do JIP events // JIP Detection and event trigger. Run this at the very end, just in case anything uses it +// Note: usage of player is most likely on purpose if (didJip) then { // We are jipping! Get ready and wait, and throw the event [{ - if((!(isNull player)) && GVAR(settingsInitFinished)) then { - ["PlayerJip", [player] ] call FUNC(localEvent); - [(_this select 1)] call CBA_fnc_removePerFrameHandler; + if(!isNull player && GVAR(settingsInitFinished)) then { + ["PlayerJip", [player]] call FUNC(localEvent); + [_this select 1] call CBA_fnc_removePerFrameHandler; }; }, 0, []] call CBA_fnc_addPerFrameHandler; }; diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 44c5da6293..a1f19aab8d 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -1,16 +1,13 @@ // by commy2 #include "script_component.hpp" -//IGNORE_PRIVATE_WARNING("_handleNetEvent", "_handleRequestAllSyncedEvents", "_handleRequestSyncedEvent", "_handleSyncedEvent"); - ADDON = false; -// ACE Common Function - PREP(addCanInteractWithCondition); PREP(addLineToDebugDraw); PREP(addSetting); PREP(addToInventory); +PREP(assignedItemFix); PREP(assignObjectsInList); PREP(ambientBrightness); PREP(applyForceWalkStatus); @@ -82,14 +79,6 @@ PREP(getTargetAzimuthAndInclination); PREP(getTargetDistance); PREP(getTargetObject); PREP(getTurnedOnLights); -PREP(getTurretCommander); -PREP(getTurretConfigPath); -PREP(getTurretCopilot); -PREP(getTurretGunner); -PREP(getTurretIndex); -PREP(getTurrets); -PREP(getTurretsFFV); -PREP(getTurretsOther); PREP(getTurretDirection); PREP(getUavControlPosition); PREP(getVehicleCargo); @@ -102,6 +91,8 @@ PREP(getWindDirection); PREP(getZoom); PREP(goKneeling); PREP(hadamardProduct); +PREP(handleScrollWheel); +PREP(handleScrollWheelInit); PREP(hasItem); PREP(hasMagazine); PREP(headBugFix); @@ -251,6 +242,17 @@ PREP(localEvent); PREP(removeEventHandler); PREP(removeAlLEventHandlers); +// Synchronized Events +PREP(syncedEventPFH); +PREP(addSyncedEventHandler); +PREP(removeSyncedEventHandler); +PREP(requestSyncedEvent); +PREP(syncedEvent); + +PREP(_handleSyncedEvent); +PREP(_handleRequestSyncedEvent); +PREP(_handleRequestAllSyncedEvents); + // other eventhandlers PREP(addActionEventHandler); PREP(addActionMenuEventHandler); @@ -274,17 +276,6 @@ PREP(hashListSelect); PREP(hashListSet); PREP(hashListPush); -// Synchronized Events -PREP(syncedEventPFH); -PREP(addSyncedEventHandler); -PREP(removeSyncedEventHandler); -PREP(requestSyncedEvent); -PREP(syncedEvent); - -PREP(_handleSyncedEvent); -PREP(_handleRequestSyncedEvent); -PREP(_handleRequestAllSyncedEvents); - GVAR(syncedEvents) = HASH_CREATE; //GVARS for execNextFrame and waitAndExec @@ -296,7 +287,7 @@ GVAR(nextFrameBufferB) = []; GVAR(settingsInitFinished) = false; GVAR(runAtSettingsInitialized) = []; -// @TODO: Generic local-managed global-synced objects (createVehicleLocal) +// @todo: Generic local-managed global-synced objects (createVehicleLocal) //Debug ACE_COUNTERS = []; @@ -306,8 +297,15 @@ if (isServer) then { call FUNC(loadSettingsOnServer); }; -ACE_player = objNull; +////////////////////////////////////////////////// +// Set up PlayerChanged eventhandler for pre init +////////////////////////////////////////////////// + +ACE_player = objNull; +uiNamespace setVariable ["ACE_player", objNull]; + +// @todo check if this can be removed if (hasInterface) then { // PFH to update the ACE_player variable GVAR(PreInit_playerChanged_PFHID) = [{ @@ -324,7 +322,11 @@ if (hasInterface) then { }, 0, []] call CBA_fnc_addPerFrameHandler; }; + +////////////////////////////////////////////////// // Time handling +////////////////////////////////////////////////// + ACE_time = diag_tickTime; ACE_realTime = diag_tickTime; ACE_virtualTime = diag_tickTime; @@ -339,6 +341,8 @@ PREP(timePFH); // Init toHex [0] call FUNC(toHex); -ADDON = true; +isHC = !hasInterface && !isDedicated; // deprecated because no tag +missionNamespace setVariable ["ACE_isHC", ACE_isHC]; +uiNamespace setVariable ["ACE_isHC", ACE_isHC]; -isHC = !(hasInterface || isDedicated); +ADDON = true; diff --git a/addons/common/functions/fnc_assignedItemFix.sqf b/addons/common/functions/fnc_assignedItemFix.sqf new file mode 100644 index 0000000000..ed381cfc9b --- /dev/null +++ b/addons/common/functions/fnc_assignedItemFix.sqf @@ -0,0 +1,73 @@ +/* + * Author: commy2 + * Initialized the assigned item fix. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public : No + */ +#include "script_component.hpp" + +private "_config"; + +ACE_isMapEnabled = call {_config = missionConfigFile >> "showMap"; !isNumber _config || {getNumber _config == 1}}; // default value is 1, so do isNumber check first +ACE_isCompassEnabled = call {_config = missionConfigFile >> "showCompass"; !isNumber _config || {getNumber _config == 1}}; +ACE_isWatchEnabled = call {_config = missionConfigFile >> "showWatch"; !isNumber _config || {getNumber _config == 1}}; +ACE_isRadioEnabled = call {_config = missionConfigFile >> "showRadio"; !isNumber _config || {getNumber _config == 1}}; +ACE_isGPSEnabled = call {_config = missionConfigFile >> "showGPS"; !isNumber _config || {getNumber _config == 1}}; + +GVAR(AssignedItems) = []; +GVAR(AssignedItemsInfo) = []; +GVAR(AssignedItemsShownItems) = [ + ACE_isMapEnabled, + ACE_isCompassEnabled, + ACE_isWatchEnabled, + ACE_isRadioEnabled, + ACE_isGPSEnabled +]; + +["playerInventoryChanged", { + params ["_unit", "_assignedItems"]; + + _assignedItems = _assignedItems select 17; + + { + if !(_x in GVAR(AssignedItems)) then { + GVAR(AssignedItems) pushBack _x; + GVAR(AssignedItemsInfo) pushBack toLower getText (configFile >> "CfgWeapons" >> _x >> "ACE_hideItemType"); + }; + + switch (GVAR(AssignedItemsInfo) select (GVAR(AssignedItems) find _x)) do { + case ("map"): { + GVAR(AssignedItemsShownItems) set [0, false]; + }; + case ("compass"): { + GVAR(AssignedItemsShownItems) set [1, false]; + }; + case ("watch"): { + GVAR(AssignedItemsShownItems) set [2, false]; + }; + case ("radio"): { + GVAR(AssignedItemsShownItems) set [3, false]; + }; + case ("gps"): { + GVAR(AssignedItemsShownItems) set [4, false]; + }; + }; + false + } count _assignedItems; + + //systemChat str GVAR(AssignedItemsShownItems); + + GVAR(AssignedItemsShownItems) params ["_showMap", "_showCompass", "_showWatch", "_showRadio", "_showGPS"]; + + showMap _showMap; + showCompass _showCompass; + showWatch _showWatch; + showRadio _showRadio; + showGPS (_showGPS || {cameraOn == getConnectedUAV _unit}); //If player is activly controling a UAV, showGPS controls showing the map (m key) +}] call FUNC(addEventHandler); diff --git a/addons/common/functions/fnc_handleScrollWheel.sqf b/addons/common/functions/fnc_handleScrollWheel.sqf new file mode 100644 index 0000000000..c0b88f9ed7 --- /dev/null +++ b/addons/common/functions/fnc_handleScrollWheel.sqf @@ -0,0 +1,25 @@ +/* + * Author: commy2 + * Handles MouseZChanged event. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public : No + */ +#include "script_component.hpp" + +// prevents a bug that causes the MouseZChanged to trigger N-times, where N is the number of times you consecutively pressed "Restart" instead of "Preview" in the editor +if (GVAR(ScrollWheelFrame) == diag_frameno) exitWith {}; + +GVAR(ScrollWheelFrame) = diag_frameno; + +{ + [_this select 1] call _x; + false +} count ((missionNamespace getVariable ["ACE_EventHandler_ScrollWheel", [-1, [], []]]) select 2); + +nil diff --git a/addons/common/functions/fnc_handleScrollWheelInit.sqf b/addons/common/functions/fnc_handleScrollWheelInit.sqf new file mode 100644 index 0000000000..12f8b5f337 --- /dev/null +++ b/addons/common/functions/fnc_handleScrollWheelInit.sqf @@ -0,0 +1,15 @@ +/* + * Author: commy2 + * Initializes the MouseZChanged eventhandler. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public : No + */ +#include "script_component.hpp" + +(findDisplay 46) displayAddEventHandler ["MouseZChanged", QUOTE(_this call FUNC(handleScrollWheel))]; diff --git a/addons/common/scripts/assignedItemFix.sqf b/addons/common/scripts/assignedItemFix.sqf deleted file mode 100644 index bcf79a3ac1..0000000000 --- a/addons/common/scripts/assignedItemFix.sqf +++ /dev/null @@ -1,64 +0,0 @@ -// by commy2 -#include "script_component.hpp" - -private ["_config"]; - -ACE_isMapEnabled = call {_config = missionConfigFile >> "showMap"; !isNumber _config || {getNumber _config == 1}}; // default value is 1, so do isNumber check first -ACE_isCompassEnabled = call {_config = missionConfigFile >> "showCompass"; !isNumber _config || {getNumber _config == 1}}; -ACE_isWatchEnabled = call {_config = missionConfigFile >> "showWatch"; !isNumber _config || {getNumber _config == 1}}; -ACE_isRadioEnabled = call {_config = missionConfigFile >> "showRadio"; !isNumber _config || {getNumber _config == 1}}; -ACE_isGPSEnabled = call {_config = missionConfigFile >> "showGPS"; !isNumber _config || {getNumber _config == 1}}; - -GVAR(AssignedItems) = []; -GVAR(AssignedItemsInfo) = []; - -["playerInventoryChanged", { - private ["_unit", "_assignedItems", "_shownItems"]; - - _unit = _this select 0; - _assignedItems = _this select 1 select 17; - - _shownItems = [ - ACE_isMapEnabled, - ACE_isCompassEnabled, - ACE_isWatchEnabled, - ACE_isRadioEnabled, - ACE_isGPSEnabled - ]; - - { - if !(_x in GVAR(AssignedItems)) then { - GVAR(AssignedItems) pushBack _x; - GVAR(AssignedItemsInfo) pushBack toLower getText (configFile >> "CfgWeapons" >> _x >> "ACE_hideItemType") - }; - - private "_hideItemType"; - _hideItemType = GVAR(AssignedItemsInfo) select (GVAR(AssignedItems) find _x); - - switch (_hideItemType) do { - case ("map"): { - _shownItems set [0, false]; - }; - case ("compass"): { - _shownItems set [1, false]; - }; - case ("watch"): { - _shownItems set [2, false]; - }; - case ("radio"): { - _shownItems set [3, false]; - }; - case ("gps"): { - _shownItems set [4, false]; - }; - }; - } forEach _assignedItems; - - //systemChat str _shownItems; - - showMap (_shownItems select 0); - showCompass (_shownItems select 1); - showWatch (_shownItems select 2); - showRadio (_shownItems select 3); - showGPS (_shownItems select 4 || {cameraOn == getConnectedUAV _unit}); //If player is activly controling a UAV, showGPS controls showing the map (m key) -}] call FUNC(addEventHandler); diff --git a/addons/common/scripts/initScrollWheel.sqf b/addons/common/scripts/initScrollWheel.sqf deleted file mode 100644 index 78920bb371..0000000000 --- a/addons/common/scripts/initScrollWheel.sqf +++ /dev/null @@ -1,16 +0,0 @@ -// by commy2 -#include "script_component.hpp" - -GVAR(ScrollWheelFrame) = diag_frameno; - -GVAR(onScrollWheel) = { - private ["_scroll"]; - _scroll = _this select 1; - - if (GVAR(ScrollWheelFrame) == diag_frameno) exitWith {}; - GVAR(ScrollWheelFrame) = diag_frameno; - - { - [_scroll] call _x; - } count ((missionNamespace getVariable ["ACE_EventHandler_ScrollWheel", [-1, [], []]]) select 2); -}; diff --git a/addons/main/script_macros.hpp b/addons/main/script_macros.hpp index 41514e4aaf..130c7427d8 100644 --- a/addons/main/script_macros.hpp +++ b/addons/main/script_macros.hpp @@ -97,6 +97,8 @@ // Time functions for accuracy per frame #define ACE_tickTime (ACE_time + (diag_tickTime - ACE_diagTime)) +#define ACE_isHC (!hasInterface && !isDedicated) + #define ACE_LOG(module,level,message) diag_log text ACE_LOGFORMAT(module,level,message) #define ACE_LOGFORMAT(module,level,message) FORMAT_2(QUOTE([ACE] (module) %1: %2),level,message) From 5a5242f1c9a2e2d32c3dcc175044f810f55cca93 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 21 Sep 2015 19:19:49 +0200 Subject: [PATCH 29/29] more common code cleanup --- addons/common/functions/fnc_assignedItemFix.sqf | 2 ++ addons/common/functions/fnc_getItemType.sqf | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/addons/common/functions/fnc_assignedItemFix.sqf b/addons/common/functions/fnc_assignedItemFix.sqf index ed381cfc9b..9f804eaa4d 100644 --- a/addons/common/functions/fnc_assignedItemFix.sqf +++ b/addons/common/functions/fnc_assignedItemFix.sqf @@ -35,6 +35,8 @@ GVAR(AssignedItemsShownItems) = [ _assignedItems = _assignedItems select 17; + GVAR(AssignedItemsShownItems) = [true, true, true, true, true]; + { if !(_x in GVAR(AssignedItems)) then { GVAR(AssignedItems) pushBack _x; diff --git a/addons/common/functions/fnc_getItemType.sqf b/addons/common/functions/fnc_getItemType.sqf index 4d6ee932fa..ec20b46f74 100644 --- a/addons/common/functions/fnc_getItemType.sqf +++ b/addons/common/functions/fnc_getItemType.sqf @@ -15,7 +15,7 @@ params ["_item"]; -private ["_cfgType", "_config", "_type", "_default"]; +private ["_cfgType", "_config", "_type", "_simulation", "_default"]; _cfgType = [_item] call FUNC(getConfigType); @@ -25,6 +25,7 @@ if (_cfgType == "CfgGlasses") exitWith {["item", "glasses"]}; _config = configFile >> _cfgType >> _item; _type = getNumber (_config >> "type"); +_simulation = getText (_config >> "simulation"); if (isNumber (_config >> "ItemInfo" >> "type")) then { _type = getNumber (_config >> "ItemInfo" >> "type"); @@ -63,7 +64,7 @@ switch (true) do { case (_type == 801): {["item", "uniform"]}; case (_type == 2^12): { - switch (toLower getText (_config >> "simulation")) do { + switch (toLower _simulation) do { case ("weapon"): {["weapon", "binocular"]}; case ("binocular"): {["weapon", "binocular"]}; case ("nvgoggles"): {["item", "nvgoggles"]}; @@ -73,6 +74,15 @@ switch (true) do { }; case (_type == 2^16): {["weapon", "vehicle"]}; - case (_type == 2^17): {[_default, "unknown"]}; // ??? + case (_type == 2^17): { + switch (toLower _simulation) do { + case ("itemmap"): {["item", "map"]}; + case ("itemgps"): {["item", "gps"]}; + case ("itemradio"): {["item", "radio"]}; + case ("itemcompass"): {["item", "compass"]}; + case ("itemwatch"): {["item", "watch"]}; + default {[_default, "unknown"]}; + }; + }; default {[_default, "unknown"]}; };