Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - Use hashmap for canInteractWith check #10189

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;