From d8badad400a6e4ddc67feb150456da125f91a0af Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 10 Feb 2020 21:29:49 +0100 Subject: [PATCH 1/2] add CBA_fnc_switchableAttachments --- addons/accessory/CfgEventHandlers.hpp | 11 +++++ addons/accessory/CfgFunctions.hpp | 7 ++++ addons/accessory/config.cpp | 13 +----- .../accessory/fnc_switchableAttachments.sqf | 41 +++++++++++++++++++ 4 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 addons/accessory/CfgEventHandlers.hpp create mode 100644 addons/accessory/CfgFunctions.hpp create mode 100644 addons/accessory/fnc_switchableAttachments.sqf diff --git a/addons/accessory/CfgEventHandlers.hpp b/addons/accessory/CfgEventHandlers.hpp new file mode 100644 index 000000000..93e3311cf --- /dev/null +++ b/addons/accessory/CfgEventHandlers.hpp @@ -0,0 +1,11 @@ +class Extended_PreStart_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preStart)); + }; +}; + +class Extended_PreInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_preInit)); + }; +}; diff --git a/addons/accessory/CfgFunctions.hpp b/addons/accessory/CfgFunctions.hpp new file mode 100644 index 000000000..0554973a9 --- /dev/null +++ b/addons/accessory/CfgFunctions.hpp @@ -0,0 +1,7 @@ +class CfgFunctions { + class CBA { + class Inventory { + PATHTO_FNC(switchableAttachments); + }; + }; +}; diff --git a/addons/accessory/config.cpp b/addons/accessory/config.cpp index 070c7774f..2aa6e15d2 100644 --- a/addons/accessory/config.cpp +++ b/addons/accessory/config.cpp @@ -14,14 +14,5 @@ class CfgPatches { }; }; -class Extended_PreStart_EventHandlers { - class ADDON { - init = QUOTE(call COMPILE_FILE(XEH_preStart)); - }; -}; - -class Extended_PreInit_EventHandlers { - class ADDON { - init = QUOTE(call COMPILE_FILE(XEH_preInit)); - }; -}; +#include "CfgEventHandlers.hpp" +#include "CfgFunctions.hpp" diff --git a/addons/accessory/fnc_switchableAttachments.sqf b/addons/accessory/fnc_switchableAttachments.sqf new file mode 100644 index 000000000..f6d88c25f --- /dev/null +++ b/addons/accessory/fnc_switchableAttachments.sqf @@ -0,0 +1,41 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_switchableAttachments + +Description: + Returns all attachments the item can eventually switch to. + +Parameters: + 0: _item - Attachment classname + +Returns: + _items - List of switchable items, contains original item. + +Examples: + (begin example) + "acc_pointer_IR" call CBA_fnc_switchableAttachments + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ + +params ["_item"]; + +private _cfgWeapons = configfile >> "CfgWeapons"; +private _config = _cfgWeapons >> _item; + +private _forward = []; +while { + _config = _cfgWeapons >> getText (_config >> "MRT_SwitchItemNextClass"); + isClass _config && {_forward pushBackUnique configName _config != -1} +} do {}; + +private _backward = []; +while { + _config = _cfgWeapons >> getText (_config >> "MRT_SwitchItemPrevClass"); + isClass _config && {_backward pushBackUnique configName _config != -1} +} do {}; + +_forward = _forward + _backward; +_forward arrayIntersect _forward // return From 19d6f24fb2ebe3e375f4283d3b0bd73aa1364bc5 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 11 Feb 2020 07:50:49 +0100 Subject: [PATCH 2/2] Update addons/accessory/fnc_switchableAttachments.sqf Co-Authored-By: Dystopian --- addons/accessory/fnc_switchableAttachments.sqf | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/accessory/fnc_switchableAttachments.sqf b/addons/accessory/fnc_switchableAttachments.sqf index f6d88c25f..1f118ad87 100644 --- a/addons/accessory/fnc_switchableAttachments.sqf +++ b/addons/accessory/fnc_switchableAttachments.sqf @@ -31,6 +31,7 @@ while { isClass _config && {_forward pushBackUnique configName _config != -1} } do {}; +_config = _cfgWeapons >> _item; private _backward = []; while { _config = _cfgWeapons >> getText (_config >> "MRT_SwitchItemPrevClass");