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
1 change: 1 addition & 0 deletions addons/ai/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREP(assignNVG);
PREP(drawCuratorGarrisonPathing);
PREP(garrison);
PREP(garrisonMove);
Expand Down
5 changes: 5 additions & 0 deletions addons/ai/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@
params ["_unit", "_mode"];
_unit enableGunLights _mode;
}] call CBA_fnc_addEventHandler;


if (isServer) then {
call FUNC(assignNVG);
};
2 changes: 2 additions & 0 deletions addons/ai/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

#include "initSettings.sqf"

ADDON = true;
45 changes: 45 additions & 0 deletions addons/ai/functions/fnc_assignNVG.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "script_component.hpp"
/*
* Author: Jonpas
* Assigns AI first found NVG in their inventory during night time and unassigns it during day time.
* Calls itself periodically.
*
* Arguments:
* None
jonpas marked this conversation as resolved.
Show resolved Hide resolved

jonpas marked this conversation as resolved.
Show resolved Hide resolved
* Return Value:
* None
*
* Example:
* [] call ace_ai_fnc_assignNVG
jonpas marked this conversation as resolved.
Show resolved Hide resolved
*
* Public: No
*/

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

private _equip = sunOrMoon < 1 || moonIntensity > 0.8;

{
private _unit = _x;
if (alive _unit && !isPlayer _unit) then {
private _nvg = hmd _unit;

if (_equip) 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;
};
};
};
} forEach allUnits;

[FUNC(assignNVG), 300] call CBA_fnc_waitAndExecute;
10 changes: 10 additions & 0 deletions addons/ai/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
private _category = format ["ACE %1", localize LSTRING(DisplayName)];
jonpas marked this conversation as resolved.
Show resolved Hide resolved

[
QGVAR(assignNVG), "CHECKBOX",
[LSTRING(AssignNVG_DisplayName), LSTRING(AssignNVG_Description)],
_category,
false,
1,
FUNC(assignNVG)
jonpas marked this conversation as resolved.
Show resolved Hide resolved
] call CBA_fnc_addSetting;
9 changes: 9 additions & 0 deletions addons/ai/stringtable.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACE">
<Package name="AI">
<Key ID="STR_ACE_AI_DisplayName">
<English>AI</English>
</Key>
<Key ID="STR_ACE_AI_GarrisonInvalidPosition">
<English>Invalid position provided.</English>
<German>Ungültige Position</German>
Expand Down Expand Up @@ -65,5 +68,11 @@
<Czech>Nenalezena žádná budova.</Czech>
<Turkish>Bir yapı bulunamadı</Turkish>
</Key>
<Key ID="STR_ACE_AI_AssignNVG_DisplayName">
<English>Assign NVG</English>
jonpas marked this conversation as resolved.
Show resolved Hide resolved
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
</Key>
<Key ID="STR_ACE_AI_AssignNVG_Description">
<English>Assigns NVG in AI's inventory during night time and unassigns it during day time.</English>
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
</Key>
</Package>
</Project>