From 967ed1b4cf80894f9a8dc65c146e1002569f7232 Mon Sep 17 00:00:00 2001 From: Ken Mikkelsen Date: Sun, 10 Nov 2024 20:28:38 +0100 Subject: [PATCH] Improvements to brainEngage Improve brainEngage by taking advantage of getUnitState Improve brainEngage reimplements behaviour not triggering when stealthed* Fixes doAssault where a unit would sometimes get stuck trying to check a position that the group believed the enemy is-- where it clearly could not be. (such as in the sky)** *Not triggering brainEngage when a unit is sneaking means that the AI become more predictable for player led groups, and unit set to ambush actually remain-ambushing. Those set to sneak will not get mixed commands from their dangerAI **It does this by simply forgetting the enemy, which is somewhat controversial but works very well in the context of group memory (i.e., if it is near a building, it will still have likely places to check). Makes me think we really should make our own getHideFrom function. --- addons/danger/functions/fnc_brainEngage.sqf | 8 +++++--- addons/main/functions/UnitAction/fnc_doAssault.sqf | 6 ++++++ addons/main/functions/UnitAction/fnc_doAssaultMemory.sqf | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/danger/functions/fnc_brainEngage.sqf b/addons/danger/functions/fnc_brainEngage.sqf index 3d7d6928..42a87212 100644 --- a/addons/danger/functions/fnc_brainEngage.sqf +++ b/addons/danger/functions/fnc_brainEngage.sqf @@ -4,7 +4,7 @@ * handles responses while engaging * * Arguments: - * 0: unit doing the avaluation + * 0: unit doing the evaluation * 1: type of data * 2: known target * @@ -32,10 +32,12 @@ private _timeout = time + 0.5; // check if ( isNull _target - || {_unit knowsAbout _target isEqualTo 0} + || {(_unit knowsAbout _target) isEqualTo 0} || {(speed _target) > 20} || {(weapons _unit) isEqualTo []} || {(combatMode _unit) in ["BLUE", "GREEN"]} + || {(behaviour _unit) isEqualTo "STEALTH"} + || {(getUnitState _unit) in ["PLANNING", "BUSY"]} ) exitWith { _timeout + 1 }; @@ -72,7 +74,7 @@ if ( _posASL set [2, 0.5]; _posASL = AGLToASL _posASL }; - _unit forceSpeed 0; + _unit forceSpeed 1; _unit suppressFor 4; [_unit, _posASL vectorAdd [0, 0, 0.8], true] call EFUNC(main,doSuppress); _timeout + 4 diff --git a/addons/main/functions/UnitAction/fnc_doAssault.sqf b/addons/main/functions/UnitAction/fnc_doAssault.sqf index 64108fc0..9a70d8fe 100644 --- a/addons/main/functions/UnitAction/fnc_doAssault.sqf +++ b/addons/main/functions/UnitAction/fnc_doAssault.sqf @@ -52,6 +52,11 @@ private _pos = call { getPosATL _unit }; + // forget targets when too close + if (_unit distance2D _getHide < 1.7) then { + _unit forgetTarget _target; + }; + // select target location _doMove = true; _getHide @@ -62,6 +67,7 @@ private _pos = call { private _group = group _unit; private _groupMemory = _group getVariable [QGVAR(groupMemory), []]; if (_groupMemory isEqualTo []) then { + _buildings pushBack _getHide; _group setVariable [QGVAR(groupMemory), _buildings]; }; }; diff --git a/addons/main/functions/UnitAction/fnc_doAssaultMemory.sqf b/addons/main/functions/UnitAction/fnc_doAssaultMemory.sqf index 842beabd..3a6a1397 100644 --- a/addons/main/functions/UnitAction/fnc_doAssaultMemory.sqf +++ b/addons/main/functions/UnitAction/fnc_doAssaultMemory.sqf @@ -18,7 +18,7 @@ params ["_unit", ["_groupMemory", []]]; // check if stopped -if (!(_unit checkAIFeature "PATH")) exitWith {false}; +if (!(_unit checkAIFeature "PATH") || {(getUnitState _unit) isEqualTo "PLANNING"}) exitWith {false}; // check it private _group = group _unit; @@ -54,7 +54,7 @@ private _pos = _groupMemory select 0; private _distance2D = _unit distance2D _pos; // check for nearby enemy -if (_unit distance2D _nearestEnemy < _distance2D) exitWith { +if (_unit distance2D (_unit getHideFrom _nearestEnemy) < _distance2D) exitWith { [_unit, _nearestEnemy, 12, true] call FUNC(doAssault); };