From 9674f732d3705da31094e233cb77d87c8b2e0f82 Mon Sep 17 00:00:00 2001 From: Moritz Schmidt Date: Sat, 4 Jul 2020 15:44:09 +0200 Subject: [PATCH] fix civ loadout setting (#75) * do not completely reset civ layout if uniform & headgear are set * but remove watch in 50%, map in 95% and compass in 99% of all cases * uniform and headgear are now settable independently * fix loadout setter functions NOTE: had to add a delay when setting face. no idea why. --- addons/cars/functions/fnc_setVehicles.sqf | 2 +- addons/loadout/XEH_PREP.hpp | 1 + addons/loadout/XEH_postInit.sqf | 10 ++- .../fnc_applyRandomConfigArrayValue.sqf | 30 +++++++ .../loadout/functions/fnc_civAddLoadout.sqf | 89 ++++++++++++------- addons/loadout/functions/fnc_setBackpacks.sqf | 4 +- addons/loadout/functions/fnc_setClothes.sqf | 2 +- addons/loadout/functions/fnc_setFaces.sqf | 2 +- addons/loadout/functions/fnc_setGoggles.sqf | 2 +- addons/loadout/functions/fnc_setHeadgear.sqf | 2 +- 10 files changed, 104 insertions(+), 40 deletions(-) create mode 100644 addons/loadout/functions/fnc_applyRandomConfigArrayValue.sqf diff --git a/addons/cars/functions/fnc_setVehicles.sqf b/addons/cars/functions/fnc_setVehicles.sqf index 961afc58..d6744beb 100644 --- a/addons/cars/functions/fnc_setVehicles.sqf +++ b/addons/cars/functions/fnc_setVehicles.sqf @@ -2,4 +2,4 @@ params [["_value",[]]]; -[QGVAR(vehicles), _value, 0, "mission"] call CBA_settings_fnc_set; +[QGVAR(vehicles), _value, 1, "mission"] call CBA_settings_fnc_set; diff --git a/addons/loadout/XEH_PREP.hpp b/addons/loadout/XEH_PREP.hpp index e264c25c..0be125a3 100644 --- a/addons/loadout/XEH_PREP.hpp +++ b/addons/loadout/XEH_PREP.hpp @@ -1,3 +1,4 @@ +PREP(applyRandomConfigArrayValue); PREP(civAddLoadout); PREP(initConfig); PREP(setBackpacks); diff --git a/addons/loadout/XEH_postInit.sqf b/addons/loadout/XEH_postInit.sqf index 8812ef0d..0700a2f7 100644 --- a/addons/loadout/XEH_postInit.sqf +++ b/addons/loadout/XEH_postInit.sqf @@ -4,7 +4,6 @@ if (!([QEGVAR(main,enabled)] call CBA_settings_fnc_get)) exitWith { INFO("GRAD civs is disabled. Good bye!"); }; - [QEGVAR(legacy,civ_added), { params [["_civ", objNull, [objNull]]]; assert(!isNull _civ); @@ -12,3 +11,12 @@ if (!([QEGVAR(main,enabled)] call CBA_settings_fnc_get)) exitWith { [_civ] call FUNC(civAddLoadout); }; }] call CBA_fnc_addEventHandler; + +[QGVAR(broadcastFace), { + params [ + ["_unit", objNull, [objNull]], + ["_face", "", [""]] + ]; + if (isNull _unit) exitWith {}; + _unit setFace _face; +}] call CBA_fnc_addEventHandler; diff --git a/addons/loadout/functions/fnc_applyRandomConfigArrayValue.sqf b/addons/loadout/functions/fnc_applyRandomConfigArrayValue.sqf new file mode 100644 index 00000000..dc5ecf32 --- /dev/null +++ b/addons/loadout/functions/fnc_applyRandomConfigArrayValue.sqf @@ -0,0 +1,30 @@ +#include "..\script_component.hpp" + +params [ + ["_configVarname", "", [""]], + ["_args", objNull, [objNull, [], 0, "", false]], + ["_callback", {}, [{}]] +]; + +scopeName "main"; +private _rawValue = [_configVarname] call cba_settings_fnc_get; +private _arrValue = []; +switch (typeName _rawValue) do { + case ("STRING"): { + if (_rawValue == "") then { + breakOut "main"; + }; + _arrValue = parseSimpleArray _rawValue; + }; + case ("ARRAY"): { + _arrValue = _rawValue; + }; + default { + ERROR_2("unexpected type %1 for config %2", typeName _rawValue, _configVarname); + breakOut "main"; + }; +}; + +if (count _arrValue == 0) exitWith {}; + +[_args, (selectRandom _arrValue)] call _callback diff --git a/addons/loadout/functions/fnc_civAddLoadout.sqf b/addons/loadout/functions/fnc_civAddLoadout.sqf index 3e371cb5..cba1d6ff 100644 --- a/addons/loadout/functions/fnc_civAddLoadout.sqf +++ b/addons/loadout/functions/fnc_civAddLoadout.sqf @@ -5,43 +5,68 @@ params [ ]; assert(!isNull _unit); +assert(local _unit); - -private _reclotheHim = { - params ["_unit", "_loadout"]; - - _unit setUnitLoadout _loadout; - private _faces = parseSimpleArray ([QGVAR(faces)] call cba_settings_fnc_get); - if (count _faces > 0) then { - [_unit, selectRandom _faces] remoteExec ["setFace", 0, _unit]; - }; +if (random 1 > 0.5) then { + _unit unlinkItem "ItemWatch"; }; - -private _addBeard = { - params ["_unit"]; - private _goggles = parseSimpleArray ([QGVAR(goggles)] call cba_settings_fnc_get); - if (count _goggles > 0) then { - _unit addGoggles selectRandom _goggles; - }; +if (random 1 > 0.05) then { + _unit unlinkItem "ItemMap"; +}; +if (random 1 > 0.01) then { + _unit unlinkItem "ItemCompass"; }; -private _addBackpack = { - params ["_unit"]; +[ + QGVAR(clothes), + _unit, + { + params ["_unit", "_value"]; + _unit addUniform _value; + } +] call FUNC(applyRandomConfigArrayValue); - private _backpacks = parseSimpleArray ([QGVAR(backpacks)] call cba_settings_fnc_get); - private _backpackProbability = [QGVAR(backpackProbability)] call cba_settings_fnc_get; - if ((_backpackProbability > (random 1)) && {count _backpacks > 0}) then { - _unit addBackpackGlobal selectRandom _backpacks; - }; -}; +[ + QGVAR(headgear), + _unit, + { + params ["_unit", "_value"]; + _unit addHeadgear _value; + } +] call FUNC(applyRandomConfigArrayValue); -private _clothes = parseSimpleArray ([QGVAR(clothes)] call cba_settings_fnc_get); -private _headgear = parseSimpleArray ([QGVAR(headgear)] call cba_settings_fnc_get); -if ((count _clothes > 0) && (count _headgear > 0)) then { - private _unitLoadout = [[],[],[],[selectRandom _clothes,[]],[],[],selectRandom _headgear,"""",[],["""","""","""","""","""",""""]]; - [_unit, _unitLoadout] call _reclotheHim; -}; +[ + QGVAR(faces), + _unit, + { + [ + { + [QGVAR(broadcastFace), _this] call CBA_fnc_globalEventJIP; + }, + _this, + 2 + ] call CBA_fnc_waitAndExecute; + } +] call FUNC(applyRandomConfigArrayValue); -[_unit] call _addBeard; -[_unit] call _addBackpack; +[ + QGVAR(goggles), + _unit, + { + params ["_unit", "_value"]; + _unit addGoggles _value; + } +] call FUNC(applyRandomConfigArrayValue); + +private _backpackProbability = [QGVAR(backpackProbability)] call cba_settings_fnc_get; +if (_backpackProbability > (random 1)) then { + [ + QGVAR(backpacks), + _unit, + { + params ["_unit", "_value"]; + _unit addBackpackGlobal _value; + } + ] call FUNC(applyRandomConfigArrayValue); +}; diff --git a/addons/loadout/functions/fnc_setBackpacks.sqf b/addons/loadout/functions/fnc_setBackpacks.sqf index df394bef..542fc67a 100644 --- a/addons/loadout/functions/fnc_setBackpacks.sqf +++ b/addons/loadout/functions/fnc_setBackpacks.sqf @@ -2,5 +2,5 @@ params [["_value",[]],["_probability",0.5]]; -[QGVAR(backpacks), _value, 0, "mission"] call CBA_settings_fnc_set; -[QGVAR(backpackProbability), _probability, 0, "mission"] call CBA_settings_fnc_set; +[QGVAR(backpacks), str _value, 1, "mission"] call CBA_settings_fnc_set; +[QGVAR(backpackProbability), _probability, 1, "mission"] call CBA_settings_fnc_set; diff --git a/addons/loadout/functions/fnc_setClothes.sqf b/addons/loadout/functions/fnc_setClothes.sqf index 1c82ec4a..fabdc7ec 100644 --- a/addons/loadout/functions/fnc_setClothes.sqf +++ b/addons/loadout/functions/fnc_setClothes.sqf @@ -2,4 +2,4 @@ params [["_value",[]]]; -[QGVAR(clothes), _value, 0, "mission"] call CBA_settings_fnc_set; +[QGVAR(clothes), str _value, 1, "mission"] call CBA_settings_fnc_set; diff --git a/addons/loadout/functions/fnc_setFaces.sqf b/addons/loadout/functions/fnc_setFaces.sqf index 6760e5b3..934ff43a 100644 --- a/addons/loadout/functions/fnc_setFaces.sqf +++ b/addons/loadout/functions/fnc_setFaces.sqf @@ -2,4 +2,4 @@ params [["_value",[]]]; -[QGVAR(faces), _value, 0, "mission"] call CBA_settings_fnc_set; +[QGVAR(faces), str _value, 1, "mission"] call CBA_settings_fnc_set; diff --git a/addons/loadout/functions/fnc_setGoggles.sqf b/addons/loadout/functions/fnc_setGoggles.sqf index c98a74c8..e38838bb 100644 --- a/addons/loadout/functions/fnc_setGoggles.sqf +++ b/addons/loadout/functions/fnc_setGoggles.sqf @@ -2,4 +2,4 @@ params [["_value",[]]]; -[QGVAR(goggles), _value, 0, "mission"] call CBA_settings_fnc_set; +[QGVAR(goggles), str _value, 1, "mission"] call CBA_settings_fnc_set; diff --git a/addons/loadout/functions/fnc_setHeadgear.sqf b/addons/loadout/functions/fnc_setHeadgear.sqf index 337c40e8..524c0359 100644 --- a/addons/loadout/functions/fnc_setHeadgear.sqf +++ b/addons/loadout/functions/fnc_setHeadgear.sqf @@ -2,4 +2,4 @@ params [["_value",[]]]; -[QGVAR(headgear), _value, 0, "mission"] call CBA_settings_fnc_set; +[QGVAR(headgear), str _value, 1, "mission"] call CBA_settings_fnc_set;