diff --git a/addons/ai/XEH_PREP.hpp b/addons/ai/XEH_PREP.hpp index 97f2b64e9d7..80c1e452394 100644 --- a/addons/ai/XEH_PREP.hpp +++ b/addons/ai/XEH_PREP.hpp @@ -1,3 +1,5 @@ +PREP(assignNVG); +PREP(assignNVGpfh); PREP(drawCuratorGarrisonPathing); PREP(garrison); PREP(garrisonMove); diff --git a/addons/ai/XEH_postInit.sqf b/addons/ai/XEH_postInit.sqf index 44f3c57472d..fce5152e3d0 100644 --- a/addons/ai/XEH_postInit.sqf +++ b/addons/ai/XEH_postInit.sqf @@ -68,3 +68,11 @@ params ["_unit", "_mode"]; _unit enableGunLights _mode; }] call CBA_fnc_addEventHandler; + + +if (isServer) then { + ["CAManBase", "init", { + // wait for HMD to be assigned so `hmd _unit` works + [FUNC(assignNVG), _this, 1] call CBA_fnc_waitAndExecute; + }] call CBA_fnc_addClassEventHandler; +}; diff --git a/addons/ai/XEH_preInit.sqf b/addons/ai/XEH_preInit.sqf index b47cf6628db..5ec0849ff95 100644 --- a/addons/ai/XEH_preInit.sqf +++ b/addons/ai/XEH_preInit.sqf @@ -6,4 +6,11 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; +if (isServer) then { + GVAR(assignNVGthread) = false; + GVAR(assignNVGstate) = false; +}; + +#include "initSettings.sqf" + ADDON = true; diff --git a/addons/ai/functions/fnc_assignNVG.sqf b/addons/ai/functions/fnc_assignNVG.sqf new file mode 100644 index 00000000000..b513a6edba3 --- /dev/null +++ b/addons/ai/functions/fnc_assignNVG.sqf @@ -0,0 +1,39 @@ +#include "script_component.hpp" +/* + * Author: Jonpas + * Assigns AI first found NVG in their inventory during night time and unassigns it during day time. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * [cursorObject] call ace_ai_fnc_assignNVG + * + * Public: No + */ + +if (!GVAR(assignNVG)) exitWith {}; + +params ["_unit"]; + +if (alive _unit && {!isPlayer _unit}) then { + private _nvg = hmd _unit; + + if (GVAR(assignNVGstate)) then { + if (_nvg == "") then { + private _items = [_unit, false, true, true, true, false, false] call CBA_fnc_uniqueUnitItems; // backpack, vest, uniform + { + if (getText (configFile >> "CfgWeapons" >> _x >> "simulation") == "NVGoggles") exitWith { + _unit assignItem _x; + }; + } forEach _items; + }; + } else { + if (_nvg != "" && {currentVisionMode _unit == 0} && {_unit canAdd _nvg}) then { + _unit unassignItem _nvg; + }; + }; +}; diff --git a/addons/ai/functions/fnc_assignNVGpfh.sqf b/addons/ai/functions/fnc_assignNVGpfh.sqf new file mode 100644 index 00000000000..ad6ad62ea66 --- /dev/null +++ b/addons/ai/functions/fnc_assignNVGpfh.sqf @@ -0,0 +1,27 @@ +#include "script_component.hpp" +/* + * Author: Jonpas + * waitAndExecute Handler for periodic NVG assignment. + * + * Arguments: + * None + + * Return Value: + * None + * + * Example: + * [] call ace_ai_fnc_assignNVGpfh + * + * Public: No + */ +TRACE_1("assignNVGpfh",count allUnits); + +if (!GVAR(assignNVG)) exitWith { TRACE_1("shutdown loop",_this); GVAR(assignNVGthread) = false; }; + +GVAR(assignNVGstate) = sunOrMoon < 1 || {moonIntensity > 0.8}; + +{ + _x call FUNC(assignNVG); +} forEach allUnits; + +[FUNC(assignNVGpfh), [], 300] call CBA_fnc_waitAndExecute; diff --git a/addons/ai/initSettings.sqf b/addons/ai/initSettings.sqf new file mode 100644 index 00000000000..0b2642c7ae2 --- /dev/null +++ b/addons/ai/initSettings.sqf @@ -0,0 +1,19 @@ +private _category = format ["ACE %1", LLSTRING(DisplayName)]; + +[ + QGVAR(assignNVG), "CHECKBOX", + [LSTRING(AssignNVG_DisplayName), LSTRING(AssignNVG_Description)], + _category, + false, + 1, + { + if (isServer) then { + params ["_enabled"]; + if (_enabled && {!GVAR(assignNVGthread)}) then { + TRACE_1("start loop",_this); + GVAR(assignNVGthread) = true; + [FUNC(assignNVGpfh), [], 1] call CBA_fnc_waitAndExecute; + }; + }; + } +] call CBA_fnc_addSetting; diff --git a/addons/ai/stringtable.xml b/addons/ai/stringtable.xml index b8c7887aced..82276304a93 100644 --- a/addons/ai/stringtable.xml +++ b/addons/ai/stringtable.xml @@ -1,6 +1,22 @@ + + AI + AI + IA + IA + AI + SI + ИИ + KI + UI + IA + AI + AI + AI + AI + Invalid position provided. Ungültige Position @@ -65,5 +81,11 @@ Nenalezena žádná budova. Bir yapı bulunamadı + + Auto-Equip NVGs + + + Equips NVG in inventory during night time and unequips it during day time.\nDoes not add NVGs to inventory! +