#include "..\script_component.hpp"

/*
 * Author: IDSolutions
 * Checks if a weapon is of a certain type
 *
 * Arguments:
 * 0: Weapon <STRING>
 * 1: Type <NUMBER>
 *
 * Return Value:
 * Is Weapon Type <BOOLEAN>
 *
 * Example:
 * ["arifle_MX_F", 4096] call forge_client_misc_fnc_isWeaponType;
 *
 * Public: Yes
 */

private _weapon = _this select 0;
private _type = _this select 1;
private _typeBits = [];
private _weaponTypeBits = [];
private _result = false;

if (_type < 1 || _weaponType < 1) exitWith { false };

private _typeHolder = _type;
private _weaponType = getNumber (configFile >> "CfgWeapons" >> _weapon >> "type");

while { _typeHolder > 0 } do {
    _typeBits pushBack (_typeHolder % 2);
    _typeHolder = floor (_typeHolder / 2);
};

_typeHolder = _weaponType;

while { _typeHolder > 0 } do {
    _weaponTypeBits pushBack (_typeHolder % 2);
    _typeHolder = floor (_typeHolder / 2);
};

if (count _typeBits > count _weaponTypeBits) exitWith { false };

_result = true;

{
    if (_x == 1 && { weaponTypeBits select _forEachIndex == 0 }) exitWith { _result = false; };
    true
} count (_typeBits);

_result