WIP - Various - Use uniqueUnitItems
When merged this pull request will:
- Title.
- Add support for checking against multiple items in common_hasItem.
- Add support for checking against magazines and weapons in common_hasItem.
- Change medical_treatment_hasItem to use common_hasItem.
- Change repair_hasItems to use common_hasItem.
- Change disarming_getAllGearUnit to use uniqueUnitItems.
- Change various functions to use common_hasItem instead of presence of item in uniqueItems array.
- Fix common_useMagazine to return false if magazine is not in unit's inventory.
Requires Arma v2.06.
Should be all of them.
Add support for checking against multiple items in common_hasItem.
may be at header of fnc_hasItem should be noted that it will return true only if unit has all items from passed array.
The old function was just items. This now dumps everything. old
["ACE_fieldDressing","ACE_packingBandage","ACE_morphine","ACE_tourniquet"]
new
["1Rnd_SmokeBlue_Grenade_shell","30Rnd_65x39_caseless_khaki_mag_Tracer","SmokeShell","U_B_T_Soldier_F","ItemWatch","SmokeShellBlue","acc_pointer_IR","SmokeShellGreen","V_PlateCarrierGL_tna_F","ACE_tourniquet","ACE_packingBandage","1Rnd_SmokeOrange_Grenade_shell","ACE_fieldDressing","1Rnd_Smoke_Grenade_shell","16Rnd_9x21_Mag","Binocular","arifle_MX_GL_khk_Hamr_Pointer_F","ItemRadio","CUP_G_TK_RoundGlasses","hgun_P07_khk_F","1Rnd_HE_Grenade_shell","H_HelmetB_Enh_tna_F","NVGoggles_tna_F","30Rnd_65x39_caseless_khaki_mag","ItemCompass","ACE_morphine","MiniGrenade","ItemGPS","Chemlight_green","ItemMap","1Rnd_SmokeGreen_Grenade_shell","optic_Hamr_khk_F","SmokeShellOrange"]
in is pretty fast, but there is still a cost to having to search more things
"ACE_morphine" in ([player] call oldUniqueItems); 0.00425 ms "ACE_morphine" in ([player] call ace_common_fnc_uniqueItems); 0.00502 ms [player, "ACE_morphine"] call ace_common_fnc_hasItem; 0.00955 ms
@PabstMirror 'Twas a mistake on my end. Can switch in condition to (_hash getOrDefault [_item, 0]) > 0, or !(isNil {_hash get _item}), both should be faster due to hashmap's constant lookup time.
There's also the issue of hasItem being an API function, while both in and get are case-sensitive, but current master branch implementation doesn't seem to cover that, so won't in this unless requested.
[player, "ACE_morphine"] call ace_common_fnc_hasItem; 0.00655 ms
[player, player] call ace_attach_fnc_getChildrenActions
0.0687 ms -> 0.115088 ms
has to do a lot forEach loops over things that aren't items
Right. This'll need a refactor, then.
As @PabstMirror highlighted, ace_common_fnc_uniqueItems should only return unique items in the unit's uniform, vest, and backpack.
Also, we never labeled ace_common_fnc_uniqueItems as public but I think a decent number of 3rd party mods use it (including ACRE2). For that reason, I am hesitant towards changing what it returns.