Improve checking of unit items (#6350)

* Add uniqueItems function

* Optimize dogtag children actions function

* Optimize getDetonators item search

* Store CfgWeapons lookup in getDetonators

* Update items to use new function

* Update items to use new function 2

* More optimization of uniqueItems function

* Update items to use new function 3
This commit is contained in:
mharis001 2018-09-17 15:03:28 -04:00 committed by PabstMirror
parent 7988622635
commit 803d497d8a
29 changed files with 95 additions and 61 deletions

View File

@ -43,6 +43,6 @@ private _magazines = magazines _player;
private _action = [_x, _displayName, _picture, {[{_this call FUNC(attach)}, _this] call CBA_fnc_execNextFrame}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _target];
};
} forEach ([_player, false] call CBA_fnc_uniqueUnitItems);
} forEach (_player call EFUNC(common,uniqueItems));
_actions

View File

@ -20,7 +20,7 @@ params ["_unit", "_target"];
//Check sides, Player has cableTie, target is alive and not already handcuffed
(GVAR(allowHandcuffOwnSide) || {(side _unit) != (side _target)}) &&
{"ACE_CableTie" in (items _unit)} &&
{"ACE_CableTie" in (_unit call EFUNC(common,uniqueItems))} &&
{alive _target} &&
{!(_target getVariable [QGVAR(isHandcuffed), false])} &&
{

View File

@ -178,6 +178,7 @@ PREP(toHex);
PREP(toNumber);
PREP(unhideUnit);
PREP(uniqueElements);
PREP(uniqueItems);
PREP(unloadPerson);
PREP(unloadPersonLocal);
PREP(unmuteUnit);

View File

@ -261,6 +261,11 @@ TRACE_1("adding unit playerEH to set ace_player",isNull cba_events_oldUnit);
ACE_player = (_this select 0);
}, true] call CBA_fnc_addPlayerEventHandler;
// Clear uniqueItems cache on loadout change
["loadout", {
GVAR(uniqueItemsCache) = nil;
}] call CBA_fnc_addPlayerEventHandler;
GVAR(OldIsCamera) = false;
[{

View File

@ -18,4 +18,4 @@
params [["_unit", objNull, [objNull]], ["_item", "", [""]]];
_item in items _unit
_item in (_unit call EFUNC(common,uniqueItems))

View File

@ -0,0 +1,39 @@
/*
* Author: mharis001
* Returns list of unique items in a unit's inventory.
* Items are cached if unit is ACE_player.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Items <ARRAY>
*
* Example:
* [_player] call ace_common_fnc_uniqueItems
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit"];
private _fnc_getItems = {
private _items = (getItemCargo uniformContainer _unit) select 0;
_items append ((getItemCargo vestContainer _unit) select 0);
_items append ((getItemCargo backpackContainer _unit) select 0);
_items arrayIntersect _items
};
// Use cached items list if unit is ACE_player
if (_unit isEqualTo ACE_player) then {
private _items = GVAR(uniqueItemsCache);
if (isNil "_items") then {
_items = call _fnc_getItems;
GVAR(uniqueItemsCache) = _items;
};
+_items
} else {
call _fnc_getItems;
};

View File

@ -22,7 +22,7 @@ private _return = false;
if !(_vehicleUsage) then {
if (_item != "") then {
if (_item in items _unit) then {
if (_item in (_unit call EFUNC(common,uniqueItems))) then {
_unit removeItem _item;
_return = true;
} else {

View File

@ -36,7 +36,7 @@ class CfgVehicles {
condition = "true";
statement = "";
exceptions[] = {"isNotSwimming", "isNotInside", "isNotSitting"};
insertChildren = QUOTE(_this call DFUNC(addDogtagActions));
insertChildren = QUOTE(_player call DFUNC(addDogtagActions));
};
};
};

View File

@ -1,42 +1,33 @@
/*
* Author: SzwedzikPL
* Creates one action per dogtag.
* Author: SzwedzikPL, mharis001
* Returns children actions for checking dogtags in player's inventory.
*
* Arguments:
* 0: Target <OBJECT>
* 1: Player <OBJECT>
* 0: Player <OBJECT>
*
* Return Value:
* Children actions <ARRAY>
* Actions <ARRAY>
*
* Example:
* _childrenActions = [unit, player] call ace_dogtags_fnc_addDogtagActions
* [_player] call ace_dogtags_fnc_addDogtagActions
*
* Public: No
*/
#include "script_component.hpp"
params ["_target", "_player"];
params ["_player"];
//Get all dogtags and their ids
private _unitDogtags = [];
private _unitDogtagIDs = [];
{
private _id = getNumber (configFile >> "CfgWeapons" >> _x >> QGVAR(tagID));
if (_id > 0) then {
_unitDogtags pushBack _x;
_unitDogtagIDs pushBack _id;
};
} forEach items _player;
//Create action children for all dogtags
private _cfgWeapons = configFile >> "CfgWeapons";
private _actions = [];
{
private _displayName = getText (configFile >> "CfgWeapons" >> _x >> "displayName");
private _picture = getText (configFile >> "CfgWeapons" >> _x >> "picture");
private _action = [_x, _displayName, _picture, {_this call FUNC(checkDogtagItem)}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player];
} forEach _unitDogtags;
{
private _config = _cfgWeapons >> _x;
if (getNumber (_config >> QGVAR(tagID)) > 0) then {
private _displayName = getText (_config >> "displayName");
private _picture = getText (_config >> "picture");
private _action = [_x, _displayName, _picture, {_this call FUNC(checkDogtagItem)}, {true}, {}, _x] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player];
};
} forEach (_player call EFUNC(common,uniqueItems));
_actions

View File

@ -24,7 +24,7 @@ if (isNull _explosive) exitWith {
deleteVehicle _target;
false
};
if (vehicle _unit != _unit || {!("ACE_DefusalKit" in (items _unit))}) exitWith {false};
if (vehicle _unit != _unit || {!("ACE_DefusalKit" in (_unit call EFUNC(common,uniqueItems)))}) exitWith {false};
if (GVAR(RequireSpecialist) && {!([_unit] call EFUNC(Common,isEOD))}) exitWith {false};

View File

@ -1,25 +1,22 @@
/*
* Author: Garth 'L-H' de Wet
* Returns all the detonators of the unit
* Author: Garth 'L-H' de Wet, mharis001
* Returns all detonators the given unit has.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Configs of all detonators <ARRAY>
* Config names of detonators <ARRAY>
*
* Example:
* _detonators = [player] call ACE_Explosives_fnc_getDetonators;
* [_player] call ace_explosives_fnc_getDetonators
*
* Public: Yes
*/
#include "script_component.hpp"
// IGNORE_PRIVATE_WARNING(_detonators);
params ["_unit"];
TRACE_1("params",_unit);
TRACE_1("Getting detonators",_unit);
private _result = (items _unit) select {getNumber (ConfigFile >> "CfgWeapons" >> _x >> QGVAR(Detonator)) == 1};
_result = _result arrayIntersect _result;
_result
private _cfgWeapons = configFile >> "CfgWeapons";
(_unit call EFUNC(common,uniqueItems)) select {getNumber (_cfgWeapons >> _x >> QGVAR(Detonator)) == 1};

View File

@ -25,7 +25,7 @@ if (_unit == ace_player) then {
};
// Exit if no item
if (({_x == "ACE_DeadManSwitch"} count (items _unit)) == 0) exitWith {};
if !("ACE_DeadManSwitch" in (_unit call EFUNC(common,uniqueItems))) exitWith {};
private _range = getNumber (configFile >> "CfgWeapons" >> "ACE_DeadManSwitch" >> QGVAR(range));
private _deadman = [_unit, "DeadManSwitch"] call FUNC(getPlacedExplosives);

View File

@ -18,4 +18,4 @@
params ["_caller", "_target"];
("ACE_UAVBattery" in (items _caller)) && {(fuel _target) < 1} && {(speed _target) < 1} && {!(isEngineOn _target)} && {(_target distance _caller) <= 4}
("ACE_UAVBattery" in (_caller call EFUNC(common,uniqueItems))) && {(fuel _target) < 1} && {(speed _target) < 1} && {!(isEngineOn _target)} && {(_target distance _caller) <= 4}

View File

@ -24,6 +24,6 @@ private _flashlights = [];
if (isText (configFile >> "CfgWeapons" >> _x >> "ItemInfo" >> "FlashLight" >> "ACE_Flashlight_Colour")) then {
_flashlights pushBackUnique _x;
};
} forEach (items _unit);
} forEach (_unit call EFUNC(common,uniqueItems));
_flashlights

View File

@ -24,6 +24,6 @@ visibleMap &&
} forEach (assignedItems ACE_player);
false
} &&
{"ACE_MapTools" in (items ACE_player)} &&
{"ACE_MapTools" in (ACE_player call EFUNC(common,uniqueItems))} &&
{!GVAR(mapTool_isDragging)} &&
{!GVAR(mapTool_isRotating)}

View File

@ -21,7 +21,7 @@ params ["_control", "_mousePosX", "_mousePosY"];
TRACE_3("params",_control,_mousePosX,_mousePosY);
// If have no map tools, then exit
if (((isNull ACE_player) || {!("ACE_MapTools" in items ACE_player)})) exitWith {
if (((isNull ACE_player) || {!("ACE_MapTools" in (ACE_player call EFUNC(common,uniqueItems)))})) exitWith {
false
};

View File

@ -17,7 +17,7 @@
params ["_theMap"];
if ((GVAR(mapTool_Shown) == 0) || {!("ACE_MapTools" in items ACE_player)}) exitWith {};
if ((GVAR(mapTool_Shown) == 0) || {!("ACE_MapTools" in (ACE_player call EFUNC(common,uniqueItems)))}) exitWith {};
private _rotatingTexture = "";
private _textureWidth = 0;

View File

@ -5,7 +5,7 @@ if (!hasInterface) exitWith {};
//Add deviceKey entry:
private _conditonCode = {
("ACE_microDAGR" in (items ACE_player))
"ACE_microDAGR" in (ACE_player call EFUNC(common,uniqueItems))
};
private _toggleCode = {
if !([ACE_player, objNull, ["notOnMap", "isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {};

View File

@ -22,12 +22,12 @@ _returnValue = switch (_showType) do {
case (DISPLAY_MODE_CLOSED): { true }; //Can always close
case (DISPLAY_MODE_HIDDEN): { true }; //Can always hide
case (DISPLAY_MODE_DIALOG): {
("ACE_microDAGR" in (items ACE_player)) && {[ACE_player, objNull, ["notOnMap", "isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)}
("ACE_microDAGR" in (ACE_player call EFUNC(common,uniqueItems))) && {[ACE_player, objNull, ["notOnMap", "isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)}
};
case (DISPLAY_MODE_DISPLAY): {
//Can't have minimap up while zoomed in on foot, but allow drivers to use while in "Gunner" to handle non-3d vehicles like most tanks
((cameraView != "GUNNER") || {(vehicle ACE_player != ACE_player) && {driver vehicle ACE_player == ACE_player}}) &&
{"ACE_microDAGR" in (items ACE_player)} &&
{"ACE_microDAGR" in (ACE_player call EFUNC(common,uniqueItems))} &&
{[ACE_player, objNull, ["notOnMap", "isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)}
};
default { false };

View File

@ -73,7 +73,7 @@ if ((_oldShowMode == DISPLAY_MODE_CLOSED) && {GVAR(currentShowMode) != DISPLAY_M
[{
params ["_args", "_idPFH"];
_args params ["_player"];
if ((isNull ACE_player) || {!alive ACE_player} || {ACE_player != _player} || {!("ACE_microDAGR" in (items ACE_player))} || {GVAR(currentShowMode) == DISPLAY_MODE_CLOSED}) then {
if ((isNull ACE_player) || {!alive ACE_player} || {ACE_player != _player} || {!("ACE_microDAGR" in (ACE_player call EFUNC(common,uniqueItems)))} || {GVAR(currentShowMode) == DISPLAY_MODE_CLOSED}) then {
//Close Display if still open:
if (GVAR(currentShowMode) != DISPLAY_MODE_CLOSED) then {
[DISPLAY_MODE_CLOSED] call FUNC(openDisplay);

View File

@ -18,4 +18,4 @@
params ["_vehicle", "_player"];
"ACE_RangeTable_82mm" in (items _player);
"ACE_RangeTable_82mm" in (_player call EFUNC(common,uniqueItems));

View File

@ -17,6 +17,6 @@
params ["_unit"];
if !("ACE_Sandbag_empty" in items _unit) exitWith {false};
if !("ACE_Sandbag_empty" in (_unit call EFUNC(common,uniqueItems))) exitWith {false};
_unit call EFUNC(common,canDig)

View File

@ -19,7 +19,7 @@
params ["_unit"];
if (_unit getVariable [QGVAR(isDeploying), false]) then {
if !("ACE_Sandbag_empty" in items _unit) then {
if !("ACE_Sandbag_empty" in (_unit call EFUNC(common,uniqueItems))) then {
[_unit] call FUNC(deployCancel);
};
};

View File

@ -18,7 +18,7 @@
params ["_trench", "_unit"];
if !("ACE_EntrenchingTool" in items _unit) exitWith {false};
if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) exitWith {false};
if ((_trench getVariable [QGVAR(progress), 0]) >= 1) exitWith {false};
// Prevent removing/digging trench by more than one person

View File

@ -17,6 +17,6 @@
params ["_unit"];
if !("ACE_EntrenchingTool" in items _unit) exitWith {false};
if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) exitWith {false};
_unit call EFUNC(common,canDig)

View File

@ -18,7 +18,7 @@
params ["_trench", "_unit"];
if !("ACE_EntrenchingTool" in items _unit) exitWith {false};
if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) exitWith {false};
// Prevent removing/digging trench by more than one person
if (_trench getVariable [QGVAR(digging), false]) exitWith {false};

View File

@ -19,7 +19,7 @@
params ["_unit"];
if (_unit getVariable [QGVAR(isPlacing), false]) then {
if !("ACE_EntrenchingTool" in items _unit) then {
if !("ACE_EntrenchingTool" in (_unit call EFUNC(common,uniqueItems))) then {
[_unit] call FUNC(placeCancel);
};
};

View File

@ -25,11 +25,12 @@ if (isNull _veh) exitWith {ERROR("null vehicle"); false};
private _returnValue = false;
//Master can open anything "no matter what"
if ("ACE_key_master" in (items _unit)) then {_returnValue = true};
private _items = _unit call EFUNC(common,uniqueItems);
if ("ACE_key_master" in _items) then {_returnValue = true};
//Check side key
private _sideKeyName = [_veh] call FUNC(getVehicleSideKey);
if (_sideKeyName in (items _unit)) then {_returnValue = true};
if (_sideKeyName in _items) then {_returnValue = true};
//Check custom keys
private _customKeys = _veh getVariable [QGVAR(customKeys), []];

View File

@ -30,7 +30,7 @@ if (isNull _veh) exitWith {ERROR("null vehicle"); false};
if ((locked _veh) == 0) exitWith {false};
//need lockpick item
if (!("ACE_key_lockpick" in (items _unit))) exitWith {false};
if !("ACE_key_lockpick" in (_unit call EFUNC(common,uniqueItems))) exitWith {false};
private _vehLockpickStrenth = _veh getVariable[QGVAR(lockpickStrength), GVAR(DefaultLockpickStrength)];
if (!(_vehLockpickStrenth isEqualType 0)) exitWith {ERROR("ACE_vehicleLock_LockpickStrength invalid"); false};