ACE3 icon indicating copy to clipboard operation
ACE3 copied to clipboard

WIP - Various - Use uniqueUnitItems

Open LinkIsGrim opened this issue 4 years ago • 8 comments

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.

LinkIsGrim avatar Aug 06 '21 21:08 LinkIsGrim

Should be all of them.

LinkIsGrim avatar Aug 07 '21 01:08 LinkIsGrim

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.

severgun avatar Aug 12 '21 14:08 severgun

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 avatar Oct 07 '21 05:10 PabstMirror

@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.

LinkIsGrim avatar Oct 07 '21 05:10 LinkIsGrim

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.

LinkIsGrim avatar Oct 07 '21 05:10 LinkIsGrim

[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

PabstMirror avatar Oct 07 '21 17:10 PabstMirror

Right. This'll need a refactor, then.

LinkIsGrim avatar Oct 07 '21 17:10 LinkIsGrim

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.

mharis001 avatar Oct 07 '21 22:10 mharis001