From 5b8fa4d4f18bc8973b72cd19007f4165c895ff95 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Fri, 3 Jun 2016 20:07:49 +0100 Subject: [PATCH] Update common status effect framework Instead of changing the event names to match the new standards and also changing every single call to `FUNC(statusEffect_set)`/`FUNC(statusEffect_get)` I figured it made sense to only change the event names and the internal workings of `FUNC(statusEffect_sendEffects)` to automatically add the appropriate prefix. --- addons/common/XEH_postInit.sqf | 12 ++++++------ addons/common/config.cpp | 11 +++++++---- addons/common/functions/fnc_fixFloating.sqf | 4 ++-- .../common/functions/fnc_statusEffect_addType.sqf | 6 ++---- .../functions/fnc_statusEffect_sendEffects.sqf | 15 +++++---------- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index fc9cf0f7dc..56cb75bb10 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -18,29 +18,29 @@ ////////////////////////////////////////////////// //Status Effect EHs: -["ace_setStatusEffect", {_this call FUNC(statusEffect_set)}] call CBA_fnc_addEventHandler; +[QGVAR(setStatusEffect), {_this call FUNC(statusEffect_set)}] call CBA_fnc_addEventHandler; ["forceWalk", false, ["ACE_SwitchUnits", "ACE_Attach", "ACE_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_Sandbag", "ACE_refuel", "ACE_rearm", "ACE_dragging"]] call FUNC(statusEffect_addType); ["blockSprint", false, []] call FUNC(statusEffect_addType); ["setCaptive", true, [QEGVAR(captives,Handcuffed), QEGVAR(captives,Surrendered), "ace_unconscious"]] call FUNC(statusEffect_addType); ["blockDamage", false, ["fixCollision"]] call FUNC(statusEffect_addType); ["blockEngine", false, ["ACE_Refuel"]] call FUNC(statusEffect_addType); -["ace_forceWalk", { +[QGVAR(forceWalk), { params ["_object", "_set"]; TRACE_2("forceWalk EH",_object,_set); _object forceWalk (_set > 0); }] call CBA_fnc_addEventHandler; -["ace_blockSprint", { //Name reversed from `allowSprint` because we want NOR logic +[QGVAR(blockSprint), { //Name reversed from `allowSprint` because we want NOR logic params ["_object", "_set"]; TRACE_2("blockSprint EH",_object,_set); _object allowSprint (_set == 0); }] call CBA_fnc_addEventHandler; -["setCaptive", { +[QGVAR(setCaptive), { params ["_object", "_set"]; TRACE_2("setCaptive EH",_object,_set); _object setCaptive (_set > 0); }] call CBA_fnc_addEventHandler; -["blockDamage", { //Name reversed from `allowDamage` because we want NOR logic +[QGVAR(blockDamage), { //Name reversed from `allowDamage` because we want NOR logic params ["_object", "_set"]; if ((_object isKindOf "CAManBase") && {(["ace_medical"] call FUNC(isModLoaded))}) then { TRACE_2("blockDamage EH (using medical)",_object,_set); @@ -50,7 +50,7 @@ _object allowDamage (_set == 0); }; }] call CBA_fnc_addEventHandler; -["blockEngine", { +[QGVAR(blockEngine), { params ["_vehicle", "_set"]; _vehicle setVariable [QGVAR(blockEngine), _set > 0, true]; _vehicle engineOn false; diff --git a/addons/common/config.cpp b/addons/common/config.cpp index e0e1ec6600..8803c751ba 100644 --- a/addons/common/config.cpp +++ b/addons/common/config.cpp @@ -15,9 +15,12 @@ class CfgPatches { // This class will be deprecated in version 3.8.0 class ACE_newEvents { - blockSprint = "ace_blockSprint"; - forceWalk = "ace_forceWalk"; - PlayerJip = "ace_playerJip"; + forceWalk = QGVAR(forceWalk); + blockSprint = QGVAR(blockSprint); + setCaptive = QGVAR(setCaptive); + blockDamage = QGVAR(blockDamage); + blockEngine = QGVAR(blockEngine); + useItem = "ace_useItem"; displayTextPicture = "ace_displayTextPicture"; displayTextStructured = "ace_displayTextStructured"; @@ -53,7 +56,7 @@ class ACE_newEvents { fixPosition = "ace_fixPosition"; fixFloating = "ace_fixFloating"; fixCollision = "ace_fixCollision"; - setStatusEffect = "ace_setStatusEffect"; + setStatusEffect = QGVAR(setStatusEffect); SettingChanged = "ace_settingChanged"; HeadbugFixUsed = "ace_headbugFixUsed"; blockDamage = "ace_blockDamage"; diff --git a/addons/common/functions/fnc_fixFloating.sqf b/addons/common/functions/fnc_fixFloating.sqf index 752b5108bb..5a00aa3863 100644 --- a/addons/common/functions/fnc_fixFloating.sqf +++ b/addons/common/functions/fnc_fixFloating.sqf @@ -21,7 +21,7 @@ if (!local _object) exitWith {}; if (_object isKindOf "CAManBase") exitWith {}; //We need to manually set allowDamage to true for setHitIndex to function -["ace_blockDamage", [_object, 0]] call CBA_fnc_localEvent; +[QGVAR(blockDamage), [_object, 0]] call CBA_fnc_localEvent; // save and restore hitpoints, see below why private _hitPointDamages = getAllHitPointsDamage _object; @@ -41,4 +41,4 @@ _object setDamage damage _object; //manually re-enable allowDamage to previous setting (ref statusEffect_funcs) private _effectVarName = format [QGVAR(effect_%1), "blockDamage"]; private _effectNumber = _object getVariable [_effectVarName, 0]; -["ace_blockDamage", [_object, _effectNumber]] call CBA_fnc_localEvent; +[QGVAR(blockDamage), [_object, _effectNumber]] call CBA_fnc_localEvent; diff --git a/addons/common/functions/fnc_statusEffect_addType.sqf b/addons/common/functions/fnc_statusEffect_addType.sqf index afd7ff7be7..b5d6c1e879 100644 --- a/addons/common/functions/fnc_statusEffect_addType.sqf +++ b/addons/common/functions/fnc_statusEffect_addType.sqf @@ -3,7 +3,7 @@ * Adds a status effect that will be handled. * * Arguments: - * 0: Status Effect Name, this should match a corisponding event name + * 0: Status Effect Name, this should match a corresponding event name * 1: Send event globaly * 2: Common Effect Reaons to pre-seed durring init * @@ -30,8 +30,6 @@ GVAR(statusEffect_isGlobal) pushBack _isGlobal; //We add reasons at any time, but more efficenet to add all common ones at one time during init if (isServer && {!(_commonReasonsArray isEqualTo [])}) then { //Switch case to lower: - { - _commonReasonsArray set [_forEachIndex, toLower _x]; - } forEach _commonReasonsArray; + _commonReasonsArray = _commonReasonsArray apply { toLower _x }; missionNamespace setVariable [(format [QGVAR(statusEffects_%1), _name]), _commonReasonsArray, true]; }; diff --git a/addons/common/functions/fnc_statusEffect_sendEffects.sqf b/addons/common/functions/fnc_statusEffect_sendEffects.sqf index 078c6a0338..f82ab10427 100644 --- a/addons/common/functions/fnc_statusEffect_sendEffects.sqf +++ b/addons/common/functions/fnc_statusEffect_sendEffects.sqf @@ -4,7 +4,7 @@ * * Arguments: * 0: Object - * 1: Effect name (or "" or send all) + * 1: Effect name (or "" to send all) * * Return Value: * Nothing @@ -30,18 +30,13 @@ if (isNull _object) exitWith {}; //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]; if (GVAR(statusEffect_isGlobal) select _forEachIndex) then { TRACE_2("Sending Global Event", _object, _effectNumber); - [_x, [_object, _effectNumber]] call CBA_fnc_globalEvent; + [_eventName, [_object, _effectNumber]] call CBA_fnc_globalEvent; } else { - if (local _object) then { - //If local, send directly to bypass network delay of targetEvent call - TRACE_2("Sending Target Local Event", _object, _effectNumber); - [_x, [_object, _effectNumber]] call CBA_fnc_localEvent; - } else { - TRACE_2("Sending Target Non-Local Event", _object, _effectNumber); - [_x, [_object, _effectNumber], [_object]] call CBA_fnc_targetEvent; - }; + TRACE_2("Sending Target Event", _object, _effectNumber); + [_eventName, [_object, _effectNumber], _object] call CBA_fnc_targetEvent; }; }; };