From 876424695e49485bca18d592f94f98f85bfd5a51 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 15 Mar 2015 09:02:11 +0100 Subject: [PATCH] solve canInteract conflicts, fix #198 --- addons/common/XEH_preInit.sqf | 2 + .../fnc_addCanInteractWithConditon.sqf | 38 ++++++++++++++++ .../common/functions/fnc_canInteractWith.sqf | 44 +++++++++++++++++-- addons/common/functions/fnc_claim.sqf | 39 +++++++++++----- addons/common/functions/fnc_owned.sqf | 19 ++++++-- .../fnc_removeCanInteractWithConditon.sqf | 34 ++++++++++++++ 6 files changed, 158 insertions(+), 18 deletions(-) create mode 100644 addons/common/functions/fnc_addCanInteractWithConditon.sqf create mode 100644 addons/common/functions/fnc_removeCanInteractWithConditon.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index c71232a55a..4eb107ce37 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -7,6 +7,7 @@ ADDON = false; PREP(addActionEventHandler); PREP(addActionMenuEventHandler); PREP(addCameraEventHandler); +PREP(addCanInteractWithConditon); PREP(addCustomEventHandler); PREP(addLineToDebugDraw); PREP(addMapMarkerCreatedEventHandler); @@ -147,6 +148,7 @@ PREP(receiveRequest); PREP(removeActionEventHandler); PREP(removeActionMenuEventHandler); PREP(removeCameraEventHandler); +PREP(removeCanInteractWithConditon); PREP(removeCustomEventHandler); PREP(removeMapMarkerCreatedEventHandler); PREP(removeScrollWheelEventHandler); diff --git a/addons/common/functions/fnc_addCanInteractWithConditon.sqf b/addons/common/functions/fnc_addCanInteractWithConditon.sqf new file mode 100644 index 0000000000..99815a08a7 --- /dev/null +++ b/addons/common/functions/fnc_addCanInteractWithConditon.sqf @@ -0,0 +1,38 @@ +/* + * Author: commy2 + * + * Add a condition that gets checked by ace_common_fnc_canInteractWith. + * + * Arguments: + * 0: The conditions id. Used to remove later or as exception name. An already existing name overwrites. (String) + * 1: The condition to check. format of "_this" is "[_player, _target]". (Code) + * + * Return Value: + * Unit can interact? + * + */ +#include "script_component.hpp" + +private ["_conditionName", "_conditionFunc"]; + +_conditionName = toLower (_this select 0); +_conditionFunc = _this select 1; + +private ["_conditions", "_conditionNames", "_conditionFuncs"]; + +_conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]]; + +_conditionNames = _conditions select 0; +_conditionFuncs = _conditions select 1; + +private "_index"; +_index = _conditionNames find _conditionName; + +if (_index == -1) then { + _index = count _conditionNames; +}; + +_conditionNames set [_index, _conditionName]; +_conditionFuncs set [_index, _conditionFunc]; + +GVAR(InteractionConditions) = [_conditionNames, _conditionFuncs]; diff --git a/addons/common/functions/fnc_canInteractWith.sqf b/addons/common/functions/fnc_canInteractWith.sqf index 9c5405452e..5e69f670e3 100644 --- a/addons/common/functions/fnc_canInteractWith.sqf +++ b/addons/common/functions/fnc_canInteractWith.sqf @@ -1,11 +1,47 @@ -// by commy2 +/* + * Author: commy2 + * + * Check if the unit can interact. + * + * Arguments: + * 0: The player. (Object) + * 1: The interaction target. objNull to ignore. (Object) + * 2: Exceptions. What general conditions are to skip? (Array) + * + * Return Value: + * Unit can interact? + * + */ #include "script_component.hpp" -private ["_unit", "_target", "_owner"]; +private ["_unit", "_target", "_exceptions"]; _unit = _this select 0; _target = _this select 1; +_exceptions = _this select 2; -_owner = _target getVariable ["ACE_isUsedBy", objNull]; +// exit if the target is not free to interact +private "_owner"; +_owner = _target getVariable [QGVAR(owner), objNull]; -isNull _owner || {_unit == _owner} || {!isPlayer _owner} +if (!isNull _owner && {_unit != _owner} && {!([_owner] call FUNC(isPlayer))}) exitWith {false}; + +// check general conditions + +private ["_conditions", "_conditionNames", "_conditionFuncs"]; + +_conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]]; + +_conditionNames = _conditions select 0; +_conditionFuncs = _conditions select 1; + +private "_canInteract"; +_canInteract = true; + +{ + if (!(_x in _exceptions) && {!([_unit, _target] call (_conditionFuncs select _forEachIndex))}) exitWith { + _canInteract = false; + }; +} forEach _conditionNames; + +_canInteract diff --git a/addons/common/functions/fnc_claim.sqf b/addons/common/functions/fnc_claim.sqf index cf960ac462..73317ee876 100644 --- a/addons/common/functions/fnc_claim.sqf +++ b/addons/common/functions/fnc_claim.sqf @@ -1,7 +1,20 @@ -// by commy2 +/* + * Author: commy2 + * + * Unit claims the ownership over an object. This is used to prevent multiple players from draging the same ammo box or using up the same wheel when repairing etc. + * + * Arguments: + * 0: Unit that claims another object. ObjNull to remove claim. (Object) + * 1: The object that gets claimed. (Object) + * 2: Lock the claimed object aswell? (Bool) + * + * Return Value: + * NONE + * + */ #include "script_component.hpp" -private ["_unit", "_target", "_lockTarget", "_owner"]; +private ["_unit", "_target", "_lockTarget"]; _unit = _this select 0; _target = _this select 1; @@ -9,20 +22,26 @@ _lockTarget = _this select 2; if (isNil "_lockTarget") then {_lockTarget = false}; -_owner = _target getVariable ["ACE_isUsedBy", objNull]; +private "_owner"; +_owner = _target getVariable [QGVAR(owner), objNull]; if (!isNull _owner && {!isNull _unit} && {_unit != _owner}) then { diag_log text "[ACE] ERROR: Claiming already owned object."; }; -_target setVariable ["ACE_isUsedBy", _unit, true]; +// transfer this immediately +_target setVariable [QGVAR(owner), _unit, true]; +// lock target object if (_lockTarget) then { - if (!isNull _unit) then { - [_target, "{_locked = locked _this; _this setVariable ['ACE_lockStatus', _locked]; _this lock 2}", _target] call FUNC(execRemoteFnc); - } else { - [_target, "{_this lock (_this getVariable ['ACE_lockStatus', locked _this])}", _target] call FUNC(execRemoteFnc); - }; + if (!isNull _unit) then { + ["lockVehicle", _target, _target] call FUNC(targetEvent); + } else { + ["unlockVehicle", _target, _target] call FUNC(targetEvent); + }; }; -//systemChat str locked _target; systemChat str (_target getVariable ['ACE_lockStatus', locked _target]); +/* +systemChat str locked _target; +systemChat str (_target getVariable [QGVAR(lockStatus), locked _target]); +*/ diff --git a/addons/common/functions/fnc_owned.sqf b/addons/common/functions/fnc_owned.sqf index 4fa1dbeb98..5588c23781 100644 --- a/addons/common/functions/fnc_owned.sqf +++ b/addons/common/functions/fnc_owned.sqf @@ -1,8 +1,19 @@ -// by commy2 +/* + * Author: commy2 + * + * Counterpart of ace_common_fnc_claim. Check if the given object is claimed by another unit. + * + * Arguments: + * 0: Any object. (Object) + * + * Return Value: + * Is this object claimed by someone? + * + */ #include "script_component.hpp" -private "_object"; +private "_target"; -_object = _this select 0; +_target = _this select 0; -!isNull (_object getVariable ["ACE_isUsedBy", objNull]) +!isNull (_target getVariable [QGVAR(owner), objNull]) diff --git a/addons/common/functions/fnc_removeCanInteractWithConditon.sqf b/addons/common/functions/fnc_removeCanInteractWithConditon.sqf new file mode 100644 index 0000000000..6cfd751c4c --- /dev/null +++ b/addons/common/functions/fnc_removeCanInteractWithConditon.sqf @@ -0,0 +1,34 @@ +/* + * Author: commy2 + * + * Remove a condition that gets checked by ace_common_fnc_canInteractWith. + * + * Arguments: + * 0: The conditions id. (String) + * + * Return Value: + * Unit can interact? + * + */ +#include "script_component.hpp" + +private "_conditionName"; + +_conditionName = toLower (_this select 0); + +private ["_conditions", "_conditionNames", "_conditionFuncs"]; + +_conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]]; + +_conditionNames = _conditions select 0; +_conditionFuncs = _conditions select 1; + +private "_index"; +_index = _conditionNames find _conditionName; + +if (_index == -1) exitWith {}; + +_conditionNames deleteAt _index; +_conditionFuncs deleteAt _index; + +GVAR(InteractionConditions) = [_conditionNames, _conditionFuncs];