-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathfnc_doGroupFlank.sqf
More file actions
115 lines (93 loc) · 3.7 KB
/
fnc_doGroupFlank.sqf
File metadata and controls
115 lines (93 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "script_component.hpp"
/*
* Author: nkenny
* Actualises flanking cycle
*
* Arguments:
* 0: group conducting the flanking <GROUP>
* 1: units list <ARRAY>
* 2: list of group vehicles <ARRAY>
* 3: list of building/enemy positions <ARRAY>
* 4: destination <ARRAY>
*
* Return Value:
* bool
*
* Example:
* [units bob] call lambs_main_fnc_doGroupFlank;
*
* Public: No
*/
params [["_group", grpNull], ["_units", []], ["_vehicles", []], ["_posList", []], ["_overwatch", [0, 0, 0]], ["_teamAlpha", 0]];
// exit!
if !(_group getVariable [QEGVAR(danger,isExecutingTactic), false]) exitWith {false};
// update
_units = _units select { !( _x getVariable [QEGVAR(danger,disableAI), false] ) && { _x call FUNC(isAlive) } && { !isPlayer _x } };
_vehicles = _vehicles select { canFire _x };
// group has reached destination
private _leader = leader _group;
if ( _leader distance2D _overwatch < 4 ) exitWith {
_group setVariable [QEGVAR(danger,isExecutingTactic), false];
_group setVariable [QGVAR(groupMemory), _posList, false];
};
// leader has no friendlies within 45 meters
private _leaderAlone = ( ( _units - crew _leader) findIf { _x distanceSqr _leader < 2025 } ) isEqualTo -1;
{
private _unit = _x;
private _suppressed = (getSuppression _x) > 0.5;
_unit setUnitPos (["MIDDLE", "DOWN"] select (_suppressed || {_unit isEqualTo _leader && _leaderAlone}));
_unit setVariable [QEGVAR(danger,forceMove), !_suppressed];
// move
_unit doMove _overwatch;
_unit setDestination [_overwatch, "LEADER PLANNED", false];
_unit setVariable [QGVAR(currentTask), "Group Flank", GVAR(debug_functions)];
// suppress
private _posASL = AGLToASL (selectRandom _posList);
private _eyePos = eyePos _unit;
_posASL = _eyePos vectorAdd ((_posASL vectorDiff _eyePos) vectorMultiply 0.6);
if (
(_forEachIndex % 2) isEqualTo _teamAlpha
&& {!(_leaderAlone && {isNull (objectParent (effectiveCommander _leader))})}
&& {(currentCommand _unit) isNotEqualTo "Suppress"}
&& {_unit isNotEqualTo (leader _unit)}
&& {[_unit, "VIEW", objNull] checkVisibility [_eyePos, _posASL] isEqualTo 1}
) then {
// shoot
[{_this call FUNC(doSuppress)}, [_unit, _posASL vectorAdd [0, 0, random 1], false], random 2] call CBA_fnc_waitAndExecute;
};
} forEach _units;
// reset alpha status
_teamAlpha = parseNumber (_teamAlpha isEqualTo 0);
// vehicles
_vehicles doWatch (selectRandom _posList);
[_posList, true] call CBA_fnc_shuffle;
{
// loaded vehicles move quickly
if (count (crew _x) > 3 || {_leaderAlone} || { _x isNotEqualTo _leader && { _leader distance2D _overwatch < 35 } } ) exitWith {_vehicles doMove _overwatch;};
// sort out vehicles
private _index = [_x, _posList] call FUNC(checkVisibilityList);
if (
_index isEqualTo -1
) then {
// move up behind leader
private _leaderPos = _leader getPos [35 min (_leader distance2D _x), _overwatch getDir _leader];
if ((vehicle _leader) isEqualTo _x) then {_leaderPos = _x getPos [35, _x getDir _overwatch]};
// check for roads
private _roads = _leaderPos nearRoads 50;
if (_roads isNotEqualTo []) exitWith {_x doMove (ASLToAGL (getPosASL (selectRandom _roads)));};
_x doMove _leaderPos;
} else {
// do suppressive fire
[_x, _posList select _index] call FUNC(doVehicleSuppress);
};
} forEach _vehicles;
// recursive cyclic
if (_units isNotEqualTo [] && { _group getVariable [QEGVAR(danger,isExecutingTactic), false] }) then {
[
{_this call FUNC(doGroupFlank)},
[_group, _units, _vehicles, _posList, _overwatch, _teamAlpha],
11 + random 8
] call CBA_fnc_waitAndExecute;
};
// end
true