Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI - Add automatic NVG equip/unequip #9313

Merged
merged 15 commits into from
Sep 5, 2023
2 changes: 2 additions & 0 deletions addons/ai/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PREP(assignNVG);
PREP(assignNVGpfh);
PREP(drawCuratorGarrisonPathing);
PREP(garrison);
PREP(garrisonMove);
Expand Down
8 changes: 8 additions & 0 deletions addons/ai/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@
params ["_unit", "_mode"];
_unit enableGunLights _mode;
}] call CBA_fnc_addEventHandler;


if (isServer) then {
["CAManBase", "init", {
jonpas marked this conversation as resolved.
Show resolved Hide resolved
// wait for HMD to be assigned so `hmd _unit` works
[FUNC(assignNVG), _this, 1] call CBA_fnc_waitAndExecute;
}] call CBA_fnc_addClassEventHandler;
};
7 changes: 7 additions & 0 deletions addons/ai/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
39 changes: 39 additions & 0 deletions addons/ai/functions/fnc_assignNVG.sqf
Original file line number Diff line number Diff line change
@@ -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 <OBJECT>
*
* Return Value:
* None
*
* Example:
* [cursorObject] call ace_ai_fnc_assignNVG
*
* Public: No
*/

if (!GVAR(assignNVG)) exitWith {};
jonpas marked this conversation as resolved.
Show resolved Hide resolved

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;
};
};
};
27 changes: 27 additions & 0 deletions addons/ai/functions/fnc_assignNVGpfh.sqf
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 19 additions & 0 deletions addons/ai/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions addons/ai/stringtable.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACE">
<Package name="AI">
<Key ID="STR_ACE_AI_DisplayName">
<English>AI</English>
<Chinese>AI</Chinese>
<French>IA</French>
<Spanish>IA</Spanish>
<Italian>AI</Italian>
<Polish>SI</Polish>
<Russian>ИИ</Russian>
<German>KI</German>
<Czech>UI</Czech>
<Portuguese>IA</Portuguese>
<Korean>AI</Korean>
<Chinesesimp>AI</Chinesesimp>
<Japanese>AI</Japanese>
<Turkish>AI</Turkish>
</Key>
<Key ID="STR_ACE_AI_GarrisonInvalidPosition">
<English>Invalid position provided.</English>
<German>Ungültige Position</German>
Expand Down Expand Up @@ -65,5 +81,11 @@
<Czech>Nenalezena žádná budova.</Czech>
<Turkish>Bir yapı bulunamadı</Turkish>
</Key>
<Key ID="STR_ACE_AI_AssignNVG_DisplayName">
<English>Auto-Equip NVGs</English>
</Key>
<Key ID="STR_ACE_AI_AssignNVG_Description">
<English>Equips NVG in inventory during night time and unequips it during day time.\nDoes not add NVGs to inventory!</English>
</Key>
</Package>
</Project>