AI - Add automatic NVG equip/unequip (#9313)

Co-authored-by: Dystopian <sddex@ya.ru>
Co-authored-by: Mike-MF <TyroneMF@hotmail.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
This commit is contained in:
jonpas 2023-09-05 16:20:06 +02:00 committed by GitHub
parent 5417a18d7f
commit 938f421ac3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 124 additions and 0 deletions

View File

@ -1,3 +1,5 @@
PREP(assignNVG);
PREP(assignNVGpfh);
PREP(drawCuratorGarrisonPathing);
PREP(garrison);
PREP(garrisonMove);

View File

@ -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;
};

View File

@ -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;

View File

@ -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 {};
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;
};
};
};

View File

@ -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;

View File

@ -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;

View File

@ -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>
@ -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>