From 8d83982d86ee756945ea8c569badb574d843a1b6 Mon Sep 17 00:00:00 2001 From: GhostIsSpooky <69561145+Salluci@users.noreply.github.com> Date: Wed, 9 Mar 2022 00:41:56 -0300 Subject: [PATCH] Advanced Fatigue - Improve misc. code (#8800) * add improvements from #8763 * review changes * writing is hard Co-authored-by: BaerMitUmlaut * missing ; Co-authored-by: BaerMitUmlaut --- addons/advanced_fatigue/XEH_postInit.sqf | 5 +++-- addons/advanced_fatigue/XEH_preInit.sqf | 2 +- addons/advanced_fatigue/functions/fnc_addDutyFactor.sqf | 4 +--- .../advanced_fatigue/functions/fnc_getMetabolicCosts.sqf | 2 +- .../advanced_fatigue/functions/fnc_handleStaminaBar.sqf | 2 ++ addons/advanced_fatigue/functions/fnc_mainLoop.sqf | 4 +++- .../advanced_fatigue/functions/fnc_removeDutyFactor.sqf | 8 +------- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/addons/advanced_fatigue/XEH_postInit.sqf b/addons/advanced_fatigue/XEH_postInit.sqf index 5a8b2d4efe..0072bd3ccc 100644 --- a/addons/advanced_fatigue/XEH_postInit.sqf +++ b/addons/advanced_fatigue/XEH_postInit.sqf @@ -30,7 +30,7 @@ if (!hasInterface) exitWith {}; GVAR(ppeBlackout) ppEffectCommit 0.4; // - GVAR updating and initialization ----------------------------------------- - ["unit", FUNC(handlePlayerChanged), true] call CBA_fnc_addPlayerEventHandler; + ["unit", LINKFUNC(handlePlayerChanged), true] call CBA_fnc_addPlayerEventHandler; ["visibleMap", { params ["", "_visibleMap"]; // command visibleMap is updated one frame later @@ -56,7 +56,8 @@ if (!hasInterface) exitWith {}; [1, 3] select (_this getVariable [QEGVAR(dragging,isCarrying), false]); }] call FUNC(addDutyFactor); }; - if (["ACE_Weather"] call EFUNC(common,isModLoaded)) then { + // Weather has an off switch, Dragging & Medical don't. + if (missionNamespace getVariable [QEGVAR(weather,enabled), false]) then { [QEGVAR(weather,temperature), { // 35->1, 45->2 linearConversion [35, 45, (missionNamespace getVariable [QEGVAR(weather,currentTemperature), 25]), 1, 2, true]; }] call FUNC(addDutyFactor); diff --git a/addons/advanced_fatigue/XEH_preInit.sqf b/addons/advanced_fatigue/XEH_preInit.sqf index 12f007ccf6..01b71996db 100644 --- a/addons/advanced_fatigue/XEH_preInit.sqf +++ b/addons/advanced_fatigue/XEH_preInit.sqf @@ -9,7 +9,7 @@ PREP_RECOMPILE_END; #include "initSettings.sqf" GVAR(staminaBarWidth) = 10 * (((safezoneW / safezoneH) min 1.2) / 40); -GVAR(dutyList) = [[], []]; +GVAR(dutyList) = createHashMap; GVAR(setAnimExclusions) = []; ADDON = true; diff --git a/addons/advanced_fatigue/functions/fnc_addDutyFactor.sqf b/addons/advanced_fatigue/functions/fnc_addDutyFactor.sqf index e2f87f3080..f9c8b19889 100644 --- a/addons/advanced_fatigue/functions/fnc_addDutyFactor.sqf +++ b/addons/advanced_fatigue/functions/fnc_addDutyFactor.sqf @@ -18,6 +18,4 @@ params [["_id", "", [""]], ["_factor", 1, [0, {}]]]; if (_id == "" || {_factor isEqualTo 1}) exitWith {}; -GVAR(dutyList) params ["_idList", "_factorList"]; -_idList pushBack _id; -_factorList pushBack _factor, +GVAR(dutyList) set [_id, _factor]; diff --git a/addons/advanced_fatigue/functions/fnc_getMetabolicCosts.sqf b/addons/advanced_fatigue/functions/fnc_getMetabolicCosts.sqf index 0e0ce7de04..1ac10fc26c 100644 --- a/addons/advanced_fatigue/functions/fnc_getMetabolicCosts.sqf +++ b/addons/advanced_fatigue/functions/fnc_getMetabolicCosts.sqf @@ -30,7 +30,7 @@ private _duty = GVAR(animDuty); } else { _duty = _duty * (_unit call _x); }; -} forEach (GVAR(dutyList) select 1); +} forEach (values GVAR(dutyList)); if (GVAR(isSwimming)) then { _terrainGradient = 0; diff --git a/addons/advanced_fatigue/functions/fnc_handleStaminaBar.sqf b/addons/advanced_fatigue/functions/fnc_handleStaminaBar.sqf index 0f4c5d0fa6..f699377f59 100644 --- a/addons/advanced_fatigue/functions/fnc_handleStaminaBar.sqf +++ b/addons/advanced_fatigue/functions/fnc_handleStaminaBar.sqf @@ -31,6 +31,8 @@ if (GVAR(fadeStaminaBar)) then { } else { _staminaBarContainer ctrlSetFade (0.9 * _stamina / 0.8); }; +} else { + _staminaBarContainer ctrlSetFade 0; }; // - Color -------------------------------------------------------------------- diff --git a/addons/advanced_fatigue/functions/fnc_mainLoop.sqf b/addons/advanced_fatigue/functions/fnc_mainLoop.sqf index 1d3b215b54..ef47d939d0 100644 --- a/addons/advanced_fatigue/functions/fnc_mainLoop.sqf +++ b/addons/advanced_fatigue/functions/fnc_mainLoop.sqf @@ -14,7 +14,9 @@ * * Public: No */ -if (!alive ACE_player) exitWith { // Dead people don't breath, Will also handle null (Map intros) + +// Dead people don't breathe, will also handle null (map intros) +if (!alive ACE_player) exitWith { [FUNC(mainLoop), [], 1] call CBA_fnc_waitAndExecute; private _staminaBarContainer = uiNamespace getVariable [QGVAR(staminaBarContainer), controlNull]; _staminaBarContainer ctrlSetFade 1; diff --git a/addons/advanced_fatigue/functions/fnc_removeDutyFactor.sqf b/addons/advanced_fatigue/functions/fnc_removeDutyFactor.sqf index aacba72dd8..030a0a43d0 100644 --- a/addons/advanced_fatigue/functions/fnc_removeDutyFactor.sqf +++ b/addons/advanced_fatigue/functions/fnc_removeDutyFactor.sqf @@ -16,10 +16,4 @@ */ params [["_id", "", [""]]]; -GVAR(dutyList) params ["_idList", "_factorList"]; -private _index = _idList find _id; - -if (_index != -1) then { - _idList deleteAt _index; - _factorList deleteAt _index; -}; +GVAR(dutyList) deleteAt _id;