Skip to content

Commit

Permalink
Common - Use hashmap for canInteractWith check (acemod#10189)
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror authored and blake8090 committed Aug 18, 2024
1 parent 4cf8dd4 commit bcd6aaa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 33 deletions.
2 changes: 2 additions & 0 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ GVAR(showHudHash) = createHashMap;
GVAR(vehicleIconCache) = createHashMap; // for getVehicleIcon
GVAR(wheelSelections) = createHashMap;

GVAR(InteractionConditions) = createHashMap;

GVAR(blockItemReplacement) = false;

// Cache for FUNC(isModLoaded)
Expand Down
15 changes: 1 addition & 14 deletions addons/common/functions/fnc_addCanInteractWithCondition.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,4 @@
params ["_conditionName", "_conditionFunc"];

_conditionName = toLowerANSI _conditionName;

private _conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]];
_conditions params ["_conditionNames", "_conditionFuncs"];

private _index = _conditionNames find _conditionName;

if (_index == -1) then {
_index = count _conditionNames;
};

_conditionNames set [_index, _conditionName];
_conditionFuncs set [_index, _conditionFunc];

GVAR(InteractionConditions) = _conditions;
GVAR(InteractionConditions) set [_conditionName, _conditionFunc];
8 changes: 2 additions & 6 deletions addons/common/functions/fnc_canInteractWith.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ private _owner = _target getVariable [QGVAR(owner), objNull];
if (!isNull _owner && {_unit != _owner}) exitWith {false};

// check general conditions
private _conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]];
_conditions params ["_conditionNames", "_conditionFuncs"];

private _canInteract = true;

{
if (!(_x in _exceptions) && {!([_unit, _target] call (_conditionFuncs select _forEachIndex))}) exitWith {
if (!(_x in _exceptions) && {!([_unit, _target] call _y)}) exitWith {
_canInteract = false;
};
} forEach _conditionNames;
} forEach GVAR(InteractionConditions);

_canInteract
14 changes: 1 addition & 13 deletions addons/common/functions/fnc_removeCanInteractWithCondition.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,4 @@
params ["_conditionName"];

_conditionName = toLowerANSI _conditionName;

private _conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]];

_conditions params ["_conditionNames", "_conditionFuncs"];

private _index = _conditionNames find _conditionName;

if (_index == -1) exitWith {};

_conditionNames deleteAt _index;
_conditionFuncs deleteAt _index;

GVAR(InteractionConditions) = _conditions;
GVAR(InteractionConditions) deleteAt _conditionName;

0 comments on commit bcd6aaa

Please sign in to comment.