diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index f2194deb64f..bb2a0c6810a 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -33,9 +33,7 @@ ACE_COUNTERS = []; // Load ace_settings into CBA Settings [] call FUNC(cbaSettings); -GVAR(statusEffect_Names) = []; -GVAR(statusEffect_isGlobal) = []; -GVAR(statusEffect_sendJIP) = []; +GVAR(statusEffects) = createHashMap; GVAR(setHearingCapabilityMap) = []; diff --git a/addons/common/functions/fnc_statusEffect_addType.sqf b/addons/common/functions/fnc_statusEffect_addType.sqf index 5535b0d9145..c733ef52f55 100644 --- a/addons/common/functions/fnc_statusEffect_addType.sqf +++ b/addons/common/functions/fnc_statusEffect_addType.sqf @@ -8,6 +8,7 @@ * 1: Send event globally * 2: Common Effect Reaons to pre-seed durring init * 3: Send event to JIP (requires sending event globally) + * 4: Event name (default: "ace_common_") * * Return Value: * None @@ -18,16 +19,16 @@ * Public: No */ -params [["_name", "", [""]], ["_isGlobal", false, [false]], ["_commonReasonsArray", [], [[]]], ["_sendJIP", false, [false]]]; -TRACE_3("params",_name,_isGlobal,_commonReasonsArray); +params [["_name", "", [""]], ["_isGlobal", false, [false]], ["_commonReasonsArray", [], [[]]], ["_sendJIP", false, [false]], ["_eventName", "", [""]]]; +TRACE_4("params",_name,_isGlobal,_commonReasonsArray,_eventName); +_name = toLowerANSI _name; if (_name == "") exitWith {ERROR_1("addStatusEffect - Bad Name %1",_this)}; -if (_name in GVAR(statusEffect_Names)) exitWith {WARNING_1("addStatusEffect - Effect Already Added (note, will not update global bit) %1",_this)}; +if (_name in GVAR(statusEffects)) exitWith {WARNING_1("addStatusEffect - Effect Already Added (note, will not update global bit) %1",_this)}; if (_sendJIP && !_isGlobal) exitWith {WARNING_1("addStatusEffect - Trying to add non-global JIP effect %1",_this)}; +if (_eventName == "") then { _eventName = format [QGVAR(%1), _name]; }; -GVAR(statusEffect_Names) pushBack _name; -GVAR(statusEffect_isGlobal) pushBack _isGlobal; -GVAR(statusEffect_sendJIP) pushBack _sendJIP; +GVAR(statusEffects) set [_name, [_isGlobal, _sendJIP, _eventName]]; //We add reasons at any time, but more efficenet to add all common ones at one time during init if (isServer && {_commonReasonsArray isNotEqualTo []}) then { diff --git a/addons/common/functions/fnc_statusEffect_resetVariables.sqf b/addons/common/functions/fnc_statusEffect_resetVariables.sqf index a9b6853b9f8..047a4480cbf 100644 --- a/addons/common/functions/fnc_statusEffect_resetVariables.sqf +++ b/addons/common/functions/fnc_statusEffect_resetVariables.sqf @@ -39,6 +39,6 @@ if (_object == _objectRef) exitWith {}; TRACE_2("forced reset defined array on object mismatch",_x,_effectNumber); _object setVariable [_effectVarName, 0, true]; //This always resets to 0 (not -1/nil)! }; -} forEach GVAR(statusEffect_Names); +} forEach GVAR(statusEffects); _object setVariable [QGVAR(statusEffect_object), _object, true]; diff --git a/addons/common/functions/fnc_statusEffect_sendEffects.sqf b/addons/common/functions/fnc_statusEffect_sendEffects.sqf index a4e3f2d2a45..79368945f2c 100644 --- a/addons/common/functions/fnc_statusEffect_sendEffects.sqf +++ b/addons/common/functions/fnc_statusEffect_sendEffects.sqf @@ -21,31 +21,34 @@ TRACE_2("params",_object,_effectName); if (isNull _object) exitWith {}; -{ - if ((_effectName == "") || {_effectName == _x}) then { - private _effectVarName = format [QGVAR(effect_%1), _x]; - private _effectNumber = _object getVariable [_effectVarName, -1]; +if (_effectName == "") exitWith { // Recurse through all possible effects + { + [_object, _x] call FUNC(statusEffect_sendEffects) + } forEach (keys GVAR(statusEffects)); +}; - //We only do anything if the effect has been defined at some point in the game for this unit - TRACE_2("checking if event is nil",_x,_effectNumber); - if (_effectNumber != -1) then { - private _eventName = format [QGVAR(%1), _x]; - switch (true) do { - case (GVAR(statusEffect_sendJIP) select _forEachIndex): { - TRACE_2("Sending Global JIP Event",_object,_effectNumber); - private _jipID = format [QGVAR(effect_%1_%2), _eventName, hashValue _object]; - [_eventName, [_object, _effectNumber], _jipID] call CBA_fnc_globalEventJIP; - [_jipID, _object] call CBA_fnc_removeGlobalEventJIP; - }; - case (GVAR(statusEffect_isGlobal) select _forEachIndex): { - TRACE_2("Sending Global Event",_object,_effectNumber); - [_eventName, [_object, _effectNumber]] call CBA_fnc_globalEvent; - }; - default { - TRACE_2("Sending Target Event",_object,_effectNumber); - [_eventName, [_object, _effectNumber], _object] call CBA_fnc_targetEvent; - }; - }; + +private _effectVarName = format [QGVAR(effect_%1), _effectName]; +private _effectNumber = _object getVariable [_effectVarName, -1]; + +// We only do anything if the effect has been defined at some point in the game for this unit +TRACE_2("checking if event is nil",_effectName,_effectNumber); +if (_effectNumber != -1) then { + (GVAR(statusEffects) get toLowerANSI _effectName) params ["_isGlobal", "_sendJIP", "_eventName"]; + switch (true) do { + case (_sendJIP): { + TRACE_2("Sending Global JIP Event",_object,_effectNumber); + private _jipID = format [QGVAR(effect_%1_%2), _eventName, hashValue _object]; + [_eventName, [_object, _effectNumber], _jipID] call CBA_fnc_globalEventJIP; + [_jipID, _object] call CBA_fnc_removeGlobalEventJIP; + }; + case (_isGlobal): { + TRACE_2("Sending Global Event",_object,_effectNumber); + [_eventName, [_object, _effectNumber]] call CBA_fnc_globalEvent; + }; + default { + TRACE_2("Sending Target Event",_object,_effectNumber); + [_eventName, [_object, _effectNumber], _object] call CBA_fnc_targetEvent; }; }; -} forEach GVAR(statusEffect_Names); +};