Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve compatibleItems, fix Arsenal 'ghost optics' #373

Merged
merged 2 commits into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions addons/jr/CfgFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

class CfgFunctions {
// replace broken vanilla function with a working one
class A3_Bootcamp {
class Inventory {
class compatibleItems {
file = QPATHTOF(fnc_compatibleItems.sqf);
};
};
};
class CBA {
class Inventory {
class compatibleItems {
description = "Get list of compatible attachments for a weapon";
file = QPATHTOF(fnc_compatibleItems.sqf);
};
};
};
};
12 changes: 1 addition & 11 deletions addons/jr/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ class CfgPatches {
};
};

class CfgFunctions {
class CBA {
class JR {
class compatibleItems {
description = "Get list of compatible attachments for a weapon";
file = QUOTE(PATHTOF(fnc_compatibleItems.sqf));
};
};
};
};

#include "jr_classes.hpp"
#include "cfgweapons.hpp"
#include "CfgFunctions.hpp"
51 changes: 32 additions & 19 deletions addons/jr/fnc_compatibleItems.sqf
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
/*
Author: Karel Moricky
Enhanced by Robalo
Caching added by joko // Jonas
/* ----------------------------------------------------------------------------
Function: CBA_fnc_compatibleItems

Description:
Return all compatible weapon attachments
Description:
Return all compatible weapon attachments.

Parameter(s):
0: STRING - weapon class
1: STRING - optional, accessory type: number (101 - muzzle, 201 - optic, 301 - pointer, 302 - bipod)
Parameters:
_weapon - A weapons class name <STRING>
_typefilter - Optional filter. Can be "muzzle", "optic", "pointer" or "bipod". <STRING, NUMBER>

Returns:
ARRAY of STRINGs
Returns:
Class names of attachments compatible with weapon <ARRAY>

Examples:
Examples:
(begin example)
_acclist = ["LMG_Mk200_F"] call CBA_fnc_compatibleItems;
_muzzleacclist = ["LMG_Mk200_F", 101] call CBA_fnc_compatibleItems;
*/
_muzzleacclist = ["LMG_Mk200_F", "muzzle"] call CBA_fnc_compatibleItems;
(end)

Author:
Original by Karel Moricky, Enhanced by Robalo, jokoho, commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"
params [["_weapon", "", [""]], ["_typefilter", 0]];
SCRIPT(compatibleItems);

params [["_weapon", "", [""]], ["_typefilter", nil, ["", 0]]];

if (_weapon == "") exitWith {[]};

if (isNil QGVAR(namespace)) then {
GVAR(namespace) = call CBA_fnc_createNamespace;
};

private _compatibleItems = GVAR(namespace) getVariable _weapon;

if (isNil "_compatibleItems") then {
_compatibleItems = [];
private _cfgWeapon = configFile >> "CfgWeapons" >> _weapon;

if (isClass _cfgWeapon) then {
{
private _cfgCompatibleItems = _x >> "compatibleItems";

if (isArray _cfgCompatibleItems) then {
{
#ifndef LINUX_BUILD
Expand All @@ -40,7 +49,7 @@ if (isNil "_compatibleItems") then {
if !(_x in _compatibleItems) then {_compatibleItems pushBack _x};
#endif
nil
} count (getArray _cfgCompatibleItems);
} count getArray _cfgCompatibleItems;
} else {
if (isClass _cfgCompatibleItems) then {
{
Expand All @@ -56,17 +65,21 @@ if (isNil "_compatibleItems") then {
};
};
nil
} count configProperties [_cfgWeapon >> "WeaponSlotsInfo","isclass _x"];
} count configProperties [_cfgWeapon >> "WeaponSlotsInfo", "isclass _x"];

GVAR(namespace) setVariable [_weapon, _compatibleItems]; //save entry in cache
} else {
["'%1' not found in CfgWeapons",_weapon] call bis_fnc_error;
["'%1' not found in CfgWeapons", _weapon] call bis_fnc_error;
};
};

if (_typefilter == 0) then { //return
if (isNil "_typefilter") then { //return
+ _compatibleItems
} else {
if (_typefilter isEqualType "") then {
_typefilter = [-1, 101, 201, 301, 302] param [["", "muzzle", "optic", "pointer", "bipod"] find _typefilter, -1];
};

#ifndef LINUX_BUILD
_compatibleItems select {_typefilter == getNumber (configFile >> "CfgWeapons" >> _x >> "itemInfo" >> "type")}
#else
Expand Down
10 changes: 6 additions & 4 deletions addons/linux/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
}

class CfgFunctions {
class A3_Bootcamp {
class Inventory {
F_FILEPATH(jr,compatibleItems);
};
};
class CBA {
class Entities {
F_FILEPATH(common,getAlive);
Expand All @@ -21,6 +26,7 @@ class CfgFunctions {
F_FILEPATH(common,dropWeapon);
F_FILEPATH(common,dropMagazine);
F_FILEPATH(common,addBinocularMagazine);
F_FILEPATH(jr,compatibleItems);
};

class Events {
Expand All @@ -33,10 +39,6 @@ class CfgFunctions {
F_FILEPATH(hashes,hashCreate);
};

class JR {
F_FILEPATH(jr,compatibleItems);
};

class XEH {
F_FILEPATH(xeh,compileEventHandlers);
};
Expand Down