-
Notifications
You must be signed in to change notification settings - Fork 149
/
fnc_getNonPresetClass.sqf
60 lines (45 loc) · 2.02 KB
/
fnc_getNonPresetClass.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_getNonPresetClass
Description:
Get ancestor class of a weapon or container which has no preset attachments/contents.
Parameters:
_item - Classname of weapon/container <STRING>
_configRoot - Root config ("CfgWeapons", "CfgVehicles", ...) <STRING> (Default: "CfgWeapons")
Returns:
Ancestor class without preset attachments/contents sub-class on success, "" otherwise <STRING>
Examples:
(begin example)
// Get parent class without preset attachments of a weapon (returns "arifle_mx_f")
_ancestorClass = ["arifle_MX_ACO_pointer_F"] call CBA_fnc_getNonPresetClass;
(end)
Author:
Jonpas
---------------------------------------------------------------------------- */
SCRIPT(getNonPresetClass);
params [["_class", "", [""]], ["_rootConfig", "CfgWeapons", [""]]];
private _config = configFile >> _rootConfig >> _class;
// Invalid class/root config
if (!isClass _config) exitWith {""};
// Create cache if it doesn't exist yet
if (isNil QGVAR(nonPresetClassesCache)) then {
GVAR(nonPresetClassesCache) = [] call CBA_fnc_createNamespace;
};
private _cachedAncestor = GVAR(nonPresetClassesCache) getVariable _class;
if (isNil "_cachedAncestor") then {
_cachedAncestor = "";
if (_rootConfig == "CfgWeapons") then {
// Use CBA_fnc_weaponComponents if weapon
_cachedAncestor = (_class call CBA_fnc_weaponComponents) select 0;
} else {
// Containers
while {isClass _config && {getNumber (_config >> "scope") > 0}} do { // Some preset backpacks are scope = 1
if (count (_config >> "TransportItems") == 0 && {count (_config >> "TransportMagazines") == 0} && {count (_config >> "TransportWeapons") == 0}) exitWith {
_cachedAncestor = configName _config;
};
_config = inheritsFrom _config;
};
};
GVAR(nonPresetClassesCache) setVariable [_class, _cachedAncestor];
};
_cachedAncestor