diff --git a/addons/advanced_fatigue/XEH_postInit.sqf b/addons/advanced_fatigue/XEH_postInit.sqf index 6abf520b64..56dcb71372 100644 --- a/addons/advanced_fatigue/XEH_postInit.sqf +++ b/addons/advanced_fatigue/XEH_postInit.sqf @@ -2,22 +2,22 @@ if (!hasInterface) exitWith {}; -[missionNamespace, "ACE_setCustomAimCoef", QUOTE(ADDON), { - private _unit = ACE_player; - private _fatigue = _unit getVariable [QGVAR(aimFatigue), 0]; - - switch (stance _unit) do { +["baseline", { + private _fatigue = ACE_player getVariable [QGVAR(aimFatigue), 0]; + switch (stance ACE_player) do { case ("CROUCH"): { - (1.0 + _fatigue ^ 2 * 0.1) * GVAR(swayFactor) + (1.0 + _fatigue ^ 2 * 0.1) }; case ("PRONE"): { - (1.0 + _fatigue ^ 2 * 2.0) * GVAR(swayFactor) + (1.0 + _fatigue ^ 2 * 2.0) }; default { - (1.5 + _fatigue ^ 2 * 3.0) * GVAR(swayFactor) + (1.5 + _fatigue ^ 2 * 3.0) }; }; -}] call EFUNC(common,arithmeticSetSource); +}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor); + +["multiplier", {GVAR(swayFactor)}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor); // recheck weapon inertia after weapon swap, change of attachments or switching unit ["weapon", {[ACE_player] call FUNC(getWeaponInertia)}, true] call CBA_fnc_addPlayerEventHandler; diff --git a/addons/advanced_fatigue/functions/fnc_handleEffects.sqf b/addons/advanced_fatigue/functions/fnc_handleEffects.sqf index e9452c8c2c..4c453784b4 100644 --- a/addons/advanced_fatigue/functions/fnc_handleEffects.sqf +++ b/addons/advanced_fatigue/functions/fnc_handleEffects.sqf @@ -94,6 +94,3 @@ if (_overexhausted) then { }; _unit setVariable [QGVAR(aimFatigue), _fatigue]; - -private _aimCoef = [missionNamespace, "ACE_setCustomAimCoef", "max"] call EFUNC(common,arithmeticGetResult); -_unit setCustomAimCoef _aimCoef; diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 9da48c3993..eb0fd41440 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -10,6 +10,7 @@ PREP(readSettingsFromParamsArray); PREP(actionKeysNamesConverted); PREP(addCanInteractWithCondition); PREP(addLineToDebugDraw); +PREP(addSwayFactor); PREP(addToInventory); PREP(addWeapon); PREP(assignedItemFix); @@ -181,6 +182,7 @@ PREP(statusEffect_sendEffects); PREP(statusEffect_set); PREP(stringCompare); PREP(stringToColoredText); +PREP(swayLoop); PREP(switchPersistentLaser); PREP(switchToGroupSide); PREP(throttledPublicVariable); diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 43bea6242f..ae56a59961 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -476,6 +476,23 @@ GVAR(reloadMutex_lastMagazines) = []; GVAR(reloadMutex_lastMagazines) = _mags; }, true] call CBA_fnc_addPlayerEventHandler; +////////////////////////////////////////////////// +// Start the sway loop +////////////////////////////////////////////////// +["CBA_settingsInitialized", { + [{ + // frame after settingsInitialized to ensure all other addons have added their factors + if ((GVAR(swayFactorsBaseline) + GVAR(swayFactorsMultiplier)) isNotEqualTo []) then { + call FUNC(swayLoop) + }; + // check for pre-3.16 sway factors being added + if (!isNil {missionNamespace getVariable "ACE_setCustomAimCoef"}) then { + WARNING("ACE_setCustomAimCoef no longer supported - use ace_common_fnc_addSwayFactor"); + WARNING_1("source: %1",(missionNamespace getVariable "ACE_setCustomAimCoef") apply {_x}); + }; + }] call CBA_fnc_execNextFrame; +}] call CBA_fnc_addEventHandler; + ////////////////////////////////////////////////// // Set up PlayerJIP eventhandler ////////////////////////////////////////////////// diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 95f61fa7a1..efe9b10c0c 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -19,6 +19,9 @@ GVAR(isModLoadedCache) = createHashMap; GVAR(settingsInitFinished) = false; GVAR(runAtSettingsInitialized) = []; +GVAR(swayFactorsBaseline) = []; +GVAR(swayFactorsMultiplier) = []; + // @todo: Generic local-managed global-synced objects (createVehicleLocal) //Debug diff --git a/addons/common/functions/fnc_addSwayFactor.sqf b/addons/common/functions/fnc_addSwayFactor.sqf new file mode 100644 index 0000000000..ea2273f0f9 --- /dev/null +++ b/addons/common/functions/fnc_addSwayFactor.sqf @@ -0,0 +1,35 @@ +#include "script_component.hpp" +/* + * Author: LinkIsGrim + * Adds a factor to player sway calculation + * + * Arguments: + * 0: Type of factor, "baseline" or "multiplier" + * 1: Factor function, must return number + * 2: Factor ID, unique to type + * + * Return Value: + * Factor added + * + * Example: + * ["baseline", {1}, "ace_common"] call ace_common_fnc_addSwayFactor + * + * Public: Yes +*/ +params ["_type", "_code", "_id"]; + +_type = toLower _type; + +if !(_type in ["baseline", "multiplier"]) exitWith { ERROR_2("%1-%2 type unsupported",_type,_id); false }; + +if !((call _code) isEqualType 0) exitWith { ERROR_2("%1-%2 bad return type",_type,_id); false }; + +[missionNamespace, format ["ACE_setCustomAimCoef_%1", _type], _id, _code] call FUNC(arithmeticSetSource); + +if (_type isEqualTo "baseline") then { + GVAR(swayFactorsBaseline) pushBackUnique [_id]; +} else { + GVAR(swayFactorsMultiplier) pushBackUnique [_id]; +}; + +true diff --git a/addons/common/functions/fnc_swayLoop.sqf b/addons/common/functions/fnc_swayLoop.sqf new file mode 100644 index 0000000000..ab2266b1f5 --- /dev/null +++ b/addons/common/functions/fnc_swayLoop.sqf @@ -0,0 +1,30 @@ +#include "script_component.hpp" +/* + * Author: LinkIsGrim + * Calculates and applies final sway coefficient from sway factors + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * call ace_common_fnc_swayLoop + * + * Public: No +*/ + +private _baseline = 1; +if (GVAR(swayFactorsBaseline) isNotEqualTo []) then { + _baseline = 1 max ([missionNamespace, "ACE_setCustomAimCoef_baseline", "max"] call EFUNC(common,arithmeticGetResult)); +}; + +private _multiplier = 1; +if (GVAR(swayFactorsMultiplier) isNotEqualTo []) then { + _multiplier = [missionNamespace, "ACE_setCustomAimCoef_multiplier", "product"] call EFUNC(common,arithmeticGetResult); +}; + +ACE_player setCustomAimCoef (_baseline * _multiplier); + +[FUNC(swayLoop), [], 1] call CBA_fnc_waitAndExecute diff --git a/addons/medical/XEH_postInit.sqf b/addons/medical/XEH_postInit.sqf index 89c3ced877..23c90b2579 100644 --- a/addons/medical/XEH_postInit.sqf +++ b/addons/medical/XEH_postInit.sqf @@ -5,9 +5,15 @@ if (!hasInterface) exitWith {}; -[missionNamespace, "ACE_setCustomAimCoef", QUOTE(ADDON), { - (linearConversion [0, 1, GET_PAIN_PERCEIVED(ACE_player), 1, 5, true]) + (ACE_player getVariable [QEGVAR(medical_engine,aimFracture), 0]) -}] call EFUNC(common,arithmeticSetSource); +// Fractures affect base sway, pain makes it worse +["baseline", { + ACE_player getVariable [QEGVAR(medical_engine,aimFracture), 0] +}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor); + +// Max pain = 5x sway +["multiplier", { + 1 + (GET_PAIN_PERCEIVED(ACE_player) * 4) +}, QUOTE(ADDON)] call EFUNC(common,addSwayFactor); #ifdef DEBUG_MODE_FULL call compile preprocessFileLineNumbers QPATHTOF(dev\reportSettings.sqf);