From 3a6b5af8c63a56fc491b18bae1b111efe58f2303 Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 6 Aug 2019 16:51:50 +0200 Subject: [PATCH 1/8] Add randomizeFacewear to common CfgFunctions --- addons/common/CfgFunctions.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index d8283148e..fde194db6 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -77,6 +77,7 @@ class CfgFunctions { PATHTO_FNC(binocularMagazine); PATHTO_FNC(addBinocularMagazine); PATHTO_FNC(removeBinocularMagazine); + PATHTO_FNC(randomizeFacewear); }; class Cargo { From 35f0f44e8818400e3fabea4f22cbd8da344a0385 Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 6 Aug 2019 17:04:37 +0200 Subject: [PATCH 2/8] Add CBA_fnc_randomizeFacewear --- addons/common/fnc_randomizeFacewear.sqf | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 addons/common/fnc_randomizeFacewear.sqf diff --git a/addons/common/fnc_randomizeFacewear.sqf b/addons/common/fnc_randomizeFacewear.sqf new file mode 100644 index 000000000..03a074955 --- /dev/null +++ b/addons/common/fnc_randomizeFacewear.sqf @@ -0,0 +1,44 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_randomizeFacewear + +Description: + Add config defined weighted random facewear to unit. + Working 'allowedFacewear' replacement for BIS_fnc_unitHeadgear. + +Parameters: + _unit - unit + +Returns: + true on success, false on error + +Examples: + (begin example) + [unit] call CBA_fnc_randomizeFacewear + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +SCRIPT(randomizeFacewear); + +params [["_unit", objNull]]; + +if (isNull _unit) exitWith { + TRACE_1("unit is null",_unit); + false +}; + +if (!local _unit || {!(_unit getVariable ["BIS_enableRandomization", true])}) exitWith {true}; + +private _allowedFacewear = getArray (configFile >> "CfgVehicles" >> typeOf _unit >> "allowedFacewear"); + +if (_allowedFacewear isEqualTo []) exitWith {true}; + +private _facewear = selectRandomWeighted _allowedFacewear; + +if (_facewear == "None") then { + removeGoggles _unit; +} else { + _unit addGoggles _facewear; +}; From 7c631df52865a56de2061d7ca2bb2493cd698ed8 Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 6 Aug 2019 17:19:40 +0200 Subject: [PATCH 3/8] Run randomizeFacewear on all units --- addons/common/XEH_preInit.sqf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index a407a7831..a90284d73 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -71,4 +71,7 @@ activateAddons GVAR(addons); }]; }] call CBA_fnc_addClassEventHandler; +// Working replacement for 'allowedFacewear' BIS_fnc_unitHeadgear +["CAManBase", "InitPost", CBA_fnc_randomizeFacewear] call CBA_fnc_addClassEventHandler; + ADDON = true; From c0cee7e9cf1c6a9ee8556c8612c953a62afe8052 Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 6 Aug 2019 19:13:19 +0200 Subject: [PATCH 4/8] Prefix allowedFacewear --- addons/common/XEH_preInit.sqf | 2 +- addons/common/fnc_randomizeFacewear.sqf | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index a90284d73..b9e762ed3 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -71,7 +71,7 @@ activateAddons GVAR(addons); }]; }] call CBA_fnc_addClassEventHandler; -// Working replacement for 'allowedFacewear' BIS_fnc_unitHeadgear +// Facewear randomization ["CAManBase", "InitPost", CBA_fnc_randomizeFacewear] call CBA_fnc_addClassEventHandler; ADDON = true; diff --git a/addons/common/fnc_randomizeFacewear.sqf b/addons/common/fnc_randomizeFacewear.sqf index 03a074955..245a07e84 100644 --- a/addons/common/fnc_randomizeFacewear.sqf +++ b/addons/common/fnc_randomizeFacewear.sqf @@ -4,7 +4,7 @@ Function: CBA_fnc_randomizeFacewear Description: Add config defined weighted random facewear to unit. - Working 'allowedFacewear' replacement for BIS_fnc_unitHeadgear. + Uses same config as headgearList[]. Parameters: _unit - unit @@ -31,13 +31,13 @@ if (isNull _unit) exitWith { if (!local _unit || {!(_unit getVariable ["BIS_enableRandomization", true])}) exitWith {true}; -private _allowedFacewear = getArray (configFile >> "CfgVehicles" >> typeOf _unit >> "allowedFacewear"); +private _allowedFacewear = getArray (configFile >> "CfgVehicles" >> typeOf _unit >> "CBA_allowedFacewear"); if (_allowedFacewear isEqualTo []) exitWith {true}; private _facewear = selectRandomWeighted _allowedFacewear; -if (_facewear == "None") then { +if (_facewear == "") then { removeGoggles _unit; } else { _unit addGoggles _facewear; From ca565432ba0dd3366a49730bb1214767aa334413 Mon Sep 17 00:00:00 2001 From: jonpas Date: Wed, 7 Aug 2019 21:19:50 +0200 Subject: [PATCH 5/8] Apply suggestions from code review Co-Authored-By: commy2 --- addons/common/fnc_randomizeFacewear.sqf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/common/fnc_randomizeFacewear.sqf b/addons/common/fnc_randomizeFacewear.sqf index 245a07e84..47dd56e09 100644 --- a/addons/common/fnc_randomizeFacewear.sqf +++ b/addons/common/fnc_randomizeFacewear.sqf @@ -14,13 +14,12 @@ Returns: Examples: (begin example) - [unit] call CBA_fnc_randomizeFacewear + [unit] call CBA_fnc_randomizeFacewear; (end) Author: commy2 ---------------------------------------------------------------------------- */ -SCRIPT(randomizeFacewear); params [["_unit", objNull]]; From 2d8218dc87ffc53f64f0c3a948da15d01c2fbba8 Mon Sep 17 00:00:00 2001 From: jonpas Date: Thu, 15 Aug 2019 13:36:49 +0200 Subject: [PATCH 6/8] Rename to CBA_facewearList, Add example configs --- addons/common/fnc_randomizeFacewear.sqf | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/common/fnc_randomizeFacewear.sqf b/addons/common/fnc_randomizeFacewear.sqf index 47dd56e09..ccea87093 100644 --- a/addons/common/fnc_randomizeFacewear.sqf +++ b/addons/common/fnc_randomizeFacewear.sqf @@ -4,7 +4,12 @@ Function: CBA_fnc_randomizeFacewear Description: Add config defined weighted random facewear to unit. - Uses same config as headgearList[]. + + CBA_facewearList[] = {}; // default: ignore and use facewear from BIS_fnc_unitHeadgear instead + CBA_facewearList[] = {"", 1}; // no facewear, delete and overwrite facewear from BIS_fnc_unitHeadgear + + // 40% no facewear, 30% balaclava, 30% bandana. Weighted randomization: Sum of propabilites must not necessarily equal 1. + CBA_facewearList[] = {"", 0.4, "G_Balaclava_blk", 0.3, "G_Bandanna_blk", 0.3}; Parameters: _unit - unit @@ -21,23 +26,25 @@ Author: commy2 ---------------------------------------------------------------------------- */ -params [["_unit", objNull]]; +params [["_unit", objNull, [objNull]]]; if (isNull _unit) exitWith { - TRACE_1("unit is null",_unit); + WARNING_1("Unit [%1] is null",_unit); false }; if (!local _unit || {!(_unit getVariable ["BIS_enableRandomization", true])}) exitWith {true}; -private _allowedFacewear = getArray (configFile >> "CfgVehicles" >> typeOf _unit >> "CBA_allowedFacewear"); +private _facewearList = getArray (configFile >> "CfgVehicles" >> typeOf _unit >> "CBA_facewearList"); -if (_allowedFacewear isEqualTo []) exitWith {true}; +if (_facewearList isEqualTo []) exitWith {true}; -private _facewear = selectRandomWeighted _allowedFacewear; +private _facewear = selectRandomWeighted _facewearList; if (_facewear == "") then { removeGoggles _unit; } else { _unit addGoggles _facewear; }; + +true From 94c5a0689c8ba2f47cd0b22e4eac9ba76b6f2679 Mon Sep 17 00:00:00 2001 From: jonpas Date: Sat, 7 Sep 2019 13:57:34 +0200 Subject: [PATCH 7/8] Support disableRandomization array --- addons/common/fnc_randomizeFacewear.sqf | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/common/fnc_randomizeFacewear.sqf b/addons/common/fnc_randomizeFacewear.sqf index ccea87093..65a3da4d2 100644 --- a/addons/common/fnc_randomizeFacewear.sqf +++ b/addons/common/fnc_randomizeFacewear.sqf @@ -33,14 +33,21 @@ if (isNull _unit) exitWith { false }; -if (!local _unit || {!(_unit getVariable ["BIS_enableRandomization", true])}) exitWith {true}; +// Disabled conditions +if (!local _unit) exitWith {true}; -private _facewearList = getArray (configFile >> "CfgVehicles" >> typeOf _unit >> "CBA_facewearList"); +private _randomizationDisabled = getArray (missionConfigFile >> "disableRandomization") findIf { + _unit isKindOf _x || {(vehicleVarName _unit) isEqualTo _x} +} != -1; + +if (_randomizationDisabled || {!(_unit getVariable ["BIS_enableRandomization", true])}) exitWith {true}; +// Get list +private _facewearList = getArray (configFile >> "CfgVehicles" >> typeOf _unit >> "CBA_facewearList"); if (_facewearList isEqualTo []) exitWith {true}; +// Apply private _facewear = selectRandomWeighted _facewearList; - if (_facewear == "") then { removeGoggles _unit; } else { From 13cc2e0bde9f6809738a6bd3fd4bfa1524605331 Mon Sep 17 00:00:00 2001 From: jonpas Date: Sat, 7 Sep 2019 20:40:17 +0200 Subject: [PATCH 8/8] Support empty string or None Co-Authored-By: commy2 --- addons/common/fnc_randomizeFacewear.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/fnc_randomizeFacewear.sqf b/addons/common/fnc_randomizeFacewear.sqf index 65a3da4d2..f14fdd655 100644 --- a/addons/common/fnc_randomizeFacewear.sqf +++ b/addons/common/fnc_randomizeFacewear.sqf @@ -48,7 +48,7 @@ if (_facewearList isEqualTo []) exitWith {true}; // Apply private _facewear = selectRandomWeighted _facewearList; -if (_facewear == "") then { +if ((toLower _facewear) in ["", "none"]) then { removeGoggles _unit; } else { _unit addGoggles _facewear;