Skip to content

Commit

Permalink
Improved Engagement (#352)
Browse files Browse the repository at this point in the history
Added 'half step' movement to doGroupAssault and doAssaultMemory to force movement
Improved tacticsAssault timings, and prevents useless positions to be added
Improved tactical assessment when assaulting
Improved units about to fire rockets are prevented from dodging
Fixed Units set to hold fire, stopped, or ordered to remain stealthy will no longer clear buildings
Fixed potential 'shooting into air' occurrences
Fixed situations where AI would ignore enemies behind them!
Misc performance improvements
  • Loading branch information
nk3nny authored Feb 18, 2024
1 parent 515f2d9 commit 418291f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
7 changes: 6 additions & 1 deletion addons/danger/functions/fnc_brainAssess.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ params ["_unit", "", "", ["_target", objNull]];
private _timeout = time + 3;

// check if stopped
if (!(_unit checkAIFeature "PATH")) exitWith {_timeout};
if (
!(_unit checkAIFeature "PATH")
|| {((behaviour _unit)) isEqualTo "STEALTH"}
|| {(currentCommand _unit) isEqualTo "STOP"}
|| {(combatMode _unit) in ["BLUE", "GREEN"]}
) exitWith {_timeout};

// group memory
private _groupMemory = (group _unit) getVariable [QEGVAR(main,groupMemory), []];
Expand Down
10 changes: 7 additions & 3 deletions addons/danger/functions/fnc_brainEngage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ if (
_timeout + 1.4
};

// set low stance
_unit setUnitPosWeak "MIDDLE";

// far, try to suppress
if (
_distance < 500
Expand All @@ -64,11 +67,12 @@ if (
&& {_type isEqualTo DANGER_CANFIRE}
) exitWith {
private _posASL = ATLtoASL (_unit getHideFrom _target);
if (((ASLtoAGL _posASL) select 2) > 6) exitWith {
_timeout + 3
if (((ASLtoAGL _posASL) select 2) > 6) then {
_posASL = ASLtoAGL _posASL;
_posASL set [2, 0.5];
_posASL = AGLToASL _posASL
};
_unit forceSpeed 0;
_unit setUnitPosWeak "MIDDLE";
_unit suppressFor 4;
[_unit, _posASL vectorAdd [0, 0, 0.8], true] call EFUNC(main,doSuppress);
_timeout + 4
Expand Down
6 changes: 3 additions & 3 deletions addons/danger/functions/fnc_tacticsAssault.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private _housePos = [];
_group setVariable [QEGVAR(main,groupMemory), _housePos];

// add base position
_housePos pushBack _target;
if (_housePos isEqualTo []) then {_housePos pushBack _target;};

// set tasks
_unit setVariable [QEGVAR(main,currentTarget), _target, EGVAR(main,debug_functions)];
Expand All @@ -103,7 +103,7 @@ if (!GVAR(disableAutonomousSmokeGrenades)) then {
[_unit, _target] call EFUNC(main,doSmoke);

// grenadier smoke
[{_this call EFUNC(main,doUGL)}, [_units, _target, "shotSmokeX"], 3] call CBA_fnc_waitAndExecute;
[{_this call EFUNC(main,doUGL)}, [_units, _target, "shotSmoke"], 3] call CBA_fnc_waitAndExecute;
};

// ready group
Expand All @@ -117,7 +117,7 @@ _units doWatch objNull;
} foreach (_units select {getSuppression _x < 0.7 && {needReload _x > 0.6}});

// execute function
[_cycle, _units, _housePos] call EFUNC(main,doGroupAssault);
[{_this call EFUNC(main,doGroupAssault)}, [_cycle, _units, _housePos], 2 + random 3] call CBA_fnc_waitAndExecute;

// debug
if (EGVAR(main,debug_functions)) then {
Expand Down
4 changes: 2 additions & 2 deletions addons/danger/functions/fnc_tacticsAssess.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ if !(_enemies isEqualTo [] || {_unitCount < random 4}) then {
&& {_inside || {_x call EFUNC(main,isIndoor)}}
};
if (_nearIndoorTarget != -1) exitWith {
_plan append [TACTICS_GARRISON, TACTICS_ASSAULT, TACTICS_ASSAULT];
_plan append [TACTICS_ASSAULT, TACTICS_ASSAULT];
_pos = _unit getHideFrom (_enemies select _nearIndoorTarget);
};

Expand All @@ -136,7 +136,7 @@ if !(_enemies isEqualTo [] || {_unitCount < random 4}) then {
private _currentWP = _waypoints select ((currentWaypoint _group) min ((count _waypoints) - 1));
private _holdWP = ((waypointType _currentWP) isEqualTo "HOLD") && {(waypointPosition _currentWP) distance2D _unit < RANGE_MID};
if (_holdWP) exitWith {
_plan append [TACTICS_GARRISON, TACTICS_HIDE];
_plan append [TACTICS_HIDE, TACTICS_HIDE];
_pos = waypointPosition _currentWP;
breakOut "conditionScope";
};
Expand Down
23 changes: 8 additions & 15 deletions addons/main/functions/GroupAction/fnc_doGroupAssault.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,22 @@ private _targetPos = _pos select 0;
{
// get unit
private _unit = _x;
private _assaultPos = _targetPos;

// manoeuvre
_unit forceSpeed 3;
_unit setUnitPos (["UP", "MIDDLE"] select (getSuppression _x isNotEqualTo 0));
_unit setUnitPos (["UP", "MIDDLE"] select ((getSuppression _x) isNotEqualTo 0 || {_unit distance2D _assaultPos > 8}));
_unit setVariable [QGVAR(currentTask), format ["Group Assault (%1c - %2p)", _cycle, count _pos], GVAR(debug_functions)];
_unit setVariable [QEGVAR(danger,forceMove), true];

// check enemy
/*
private _enemy = _unit findNearestEnemy _unit;
if (
_unit distance2D _enemy < 12
&& {(vehicle _enemy) isKindOf "CAManBase"}
&& {_enemy call FUNC(isAlive)}
) then {
_targetPos = getPosATL _enemy;
_unit forceSpeed 2;
// modify movement (if far)
if (_unit distanceSqr _assaultPos > 400 && {!([_unit] call FUNC(isIndoor))}) then {
_assaultPos = _unit getPos [20, _unit getDir _assaultPos];
};
*/

// set movement
if (((expectedDestination _unit) select 0) distance2D _targetPos > 1) then {
_unit doMove _targetPos;
if (((expectedDestination _unit) select 0) distance2D _assaultPos > 1) then {
_unit doMove _assaultPos;
_unit setDestination [_assaultPos, "LEADER PLANNED", true];
};

// remove positions
Expand Down
7 changes: 5 additions & 2 deletions addons/main/functions/UnitAction/fnc_doAssault.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ _unit setVariable [QGVAR(currentTask), "Assault", GVAR(debug_functions)];
private _getHide = _unit getHideFrom _target;

// check visibility
private _vis = [objNull, "VIEW", objNull] checkVisibility [eyePos _unit, aimPos _target] isNotEqualTo 0;
private _vis = [objNull, "VIEW", objNull] checkVisibility [eyePos _unit, aimPos _target] isEqualTo 1;
private _buildings = [];
private _pos = call {

// can see target!
if (_vis) exitWith {getPosATL _target};
if (_vis) exitWith {
_unit lookAt (aimPos _target);
getPosATL _target
};

// near buildings
private _buildings = [_getHide, _range, true, false] call FUNC(findBuildings);
Expand Down
24 changes: 14 additions & 10 deletions addons/main/functions/UnitAction/fnc_doAssaultMemory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,43 @@ if (_groupMemory isEqualTo []) then {
};

// exit or sort it!
_groupMemory = _groupMemory select {(leader _unit) distance2D _x < 150 && {_unit distance _x > 1.5}};
_groupMemory = _groupMemory select {(leader _unit) distanceSqr _x < 20164 && {_unit distanceSqr _x > 2.25}};
if (_groupMemory isEqualTo []) exitWith {
_group setVariable [QGVAR(groupMemory), [], false];
false
};

// check for enemy get position
private _nearestEnemy = _unit findNearestEnemy _unit;
private _vis = [objNull, "VIEW", objNull] checkVisibility [eyePos _unit, aimPos _nearestEnemy] isNotEqualTo 0;
if (
(vehicle _nearestEnemy) isKindOf "CAManBase"
&& {_vis || {_unit distance2D _nearestEnemy < 12 && {(round (getposATL _unit select 2)) isEqualTo (round ((getPosATL _nearestEnemy) select 2))}}}
(_unit distanceSqr _nearestEnemy < 5041)
&& {(vehicle _nearestEnemy) isKindOf "CAManBase"}
&& {[objNull, "VIEW", objNull] checkVisibility [eyePos _unit, aimPos _nearestEnemy] isEqualTo 1 || {_unit distanceSqr _nearestEnemy < 64 && {(round (getposATL _unit select 2)) isEqualTo (round ((getPosATL _nearestEnemy) select 2))}}}
) exitWith {
[_unit, _nearestEnemy, 8, false] call FUNC(doAssault);
_unit setUnitPosWeak "MIDDLE";
[_unit, _nearestEnemy, 12, true] call FUNC(doAssault);
};

// sort positions from nearest to furthest prioritising positions on the same floor
_groupMemory = _groupMemory apply {[(round (getposATL _unit select 2)) isEqualTo (round (_x select 2)), _x distanceSqr _unit, _x]};
private _unitATL2 = round (getPosATL _unit select 2);
_groupMemory = _groupMemory apply {[_unitATL2 isEqualTo (round (_x select 2)), _x distanceSqr _unit, _x]};
_groupMemory sort true;
_groupMemory = _groupMemory apply {_x select 2};

// get distance
private _pos = _groupMemory select 0;
private _distance2D = _unit distance2D _pos;
private _indoor = _unit call FUNC(isIndoor);
if (_distance2D > 20 && {!_indoor}) then {
_pos = _unit getPos [20, _unit getDir _pos];
};
if (_pos isEqualType objNull) then {_pos = getPosATL _pos;};

// variables
_unit setVariable [QGVAR(currentTarget), _pos, GVAR(debug_functions)];
_unit setVariable [QGVAR(currentTask), "Assault (sympathetic)", GVAR(debug_functions)];

// set stance
_unit setUnitPosWeak (["UP", "MIDDLE"] select (getSuppression _unit > 0.7 || {_unit call FUNC(isIndoor)}));
_unit setUnitPosWeak (["UP", "MIDDLE"] select (_indoor || {_distance2D > 8} || {(getSuppression _unit) isNotEqualTo 0}));

// set speed
[_unit, _pos] call FUNC(doAssaultSpeed);
Expand All @@ -69,11 +73,11 @@ if (_distance2D < 7) then {_unit setVariable ["ace_medical_ai_lastFired", CBA_mi

// execute move
_unit doMove _pos;
_unit setDestination [_pos, "LEADER PLANNED", _unit distance2D _pos < 18];
_unit setDestination [_pos, "LEADER PLANNED", _indoor];

// update variable
if (RND(0.95)) then {_groupMemory deleteAt 0;};
_groupMemory = _groupMemory select {[objNull, "VIEW", objNull] checkVisibility [eyePos _unit, (AGLToASL _x) vectorAdd [0, 0, 0.5]] isEqualTo 0};
_groupMemory = _groupMemory select {_unit distanceSqr _x < 25 && {[objNull, "VIEW", objNull] checkVisibility [eyePos _unit, (AGLToASL _x) vectorAdd [0, 0, 0.5]] isEqualTo 0}};

// variables
_group setVariable [QGVAR(groupMemory), _groupMemory, false];
Expand Down
1 change: 1 addition & 0 deletions addons/main/functions/UnitAction/fnc_doDodge.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if (
GVAR(disableAIDodge)
|| {!(_unit checkAIFeature "MOVE")}
|| {!(_unit checkAIFeature "PATH")}
|| {!((currentWeapon _unit) isEqualTo (primaryWeapon _unit))}
) exitWith {false};

// dodge
Expand Down

0 comments on commit 418291f

Please sign in to comment.