Skip to content

Commit

Permalink
Update fnc_taskRush.sqf (#404)
Browse files Browse the repository at this point in the history
Improve taskRush by taking advantage of the new Eventhandlers introduced in Arma3 since LAMBS Danger's inception.

This gives more aggressive movement and a whole lot more reaction when bullets are shot at the AI.
  • Loading branch information
nk3nny committed Jul 7, 2024
1 parent 721ac5b commit 652f1da
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions addons/wp/functions/fnc_taskRush.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ params [
private _fnc_rushOrders = {
params ["_group", "_target"];

private _distance = (leader _group) distance2D _target;
// Helicopters -- supress it!
if ((_distance < 200) && {vehicle _target isKindOf "Air"}) exitWith {
{
_x commandSuppressiveFire _target;
true
} count (units _group);
private _distance = (leader _group) distance _target;

// Helicopters -- suppress it!
if ((_distance < 200) && {(vehicle _target) isKindOf "Air"}) exitWith {
(units _group) commandSuppressiveFire _target;
};

// Tank -- hide or ready AT
Expand All @@ -56,17 +54,27 @@ private _fnc_rushOrders = {
_x selectWeapon (secondaryWeapon _x);
} else {
_x setUnitPos "DOWN";
_x commandSuppressiveFire _target;
_x doSuppressiveFire _target;
};
true
} count (units _group);
_group enableGunLights "forceOff";
};

// adjust pos
private _posMove = call {
private _posATL = getPosATL _target;
if ((insideBuilding _target) isEqualTo 1 || _distance < 20) exitWith {_posATL};
private _posEmpty = _posATL findEmptyPosition [0, 20, "O_MRAP_02_F"];
if (_posEmpty isEqualTo []) exitWith {_posATL};
_posEmpty
};

// Default -- run for it!
{
_x setUnitPos "UP";
_x doMove (getPosATL _target);
_x forceSpeed -1;
_x setUnitPos (["UP", "MIDDLE"] select ((unitPos _x) isEqualTo "Down"));
_x doMove _posMove;
true
} count (units _group);
_group enableGunLights "forceOn";
Expand All @@ -81,8 +89,31 @@ if (_group isEqualType objNull) then { _group = group _group; };
_group setSpeedMode "FULL";
//_group setFormation "DIAMOND";
_group enableAttack false;
_group allowFleeing 0;
{
_x disableAI "AUTOCOMBAT";
_x disableAI "FSM";

// fired EH
private _firedEH = _x addEventHandler ["Fired", {
params ["_unit"];
_unit forceSpeed 3;
}];

// dodge
private _suppressedEH = _x addEventHandler ["Suppressed", {
params ["_unit", "", "_shooter"];
private _unitPos = unitPos _unit;

// tune stance
if (_unitPos isEqualTo "Down") exitWith {};
if (_unitPos isEqualTo "Middle" && {_unit distance2D _shooter > 30}) exitWith {_unit setUnitPos "DOWN";};
_unit setUnitPos "MIDDLE";
}];

// variables
_x setVariable [QGVAR(eventhandlers), [["Fired", _firedEH], ["Suppressed", _suppressedEH]]];

doStop _x;
true
} count (units _group);
Expand All @@ -94,13 +125,13 @@ _group setVariable [QEGVAR(main,currentTactic), "taskRush", EGVAR(main,debug_fun
waitUntil {

// performance
waitUntil { sleep 1; simulationEnabled leader _group; };
waitUntil { sleep 1; simulationEnabled (leader _group); };

// find
private _target = [_group, _radius, _area, _pos, _onlyPlayers] call EFUNC(main,findClosestTarget);

// act
if (!isNull _target) then {
if (!isNull _target) then {
[_group, _target] call _fnc_rushOrders;
if (EGVAR(main,debug_functions)) then { ["%1 taskRush: %2 targets %3 at %4M", side _group, groupID _group, name _target, floor (leader _group distance2D _target)] call EFUNC(main,debugLog); };
sleep (linearConversion [1000, 2000, (leader _group distance2D _target), _cycle, _cycle * 4, true]);
Expand Down

0 comments on commit 652f1da

Please sign in to comment.