-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfn_taskCQB.sqf
130 lines (107 loc) · 3.95 KB
/
fn_taskCQB.sqf
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// CQB script
// version 0.28b
// by nkenny
/*
Design
Group identifies buildings
Clears them methodically
marks building safe
moves to next building
repeat until no buildings left
Arguments
1, Group or object [Object or Group]
2, Range [Number]
*/
// functions ---
// find buildings
_fn_find = {
_building = nearestobjects [(leader _group), ["house", "strategic", "ruins"], _range, true];
_building = _building select {count (_x buildingPos -1) > 0};
_building = _building select {count (_x getVariable ["LAMBS_CQB_cleared_" + str (side _group), [0, 0]]) > 0};
if (count _building > 0) exitWith {_building select 0};
ObjNull
};
// check for enemies
_fn_enemy = {
private _pos = [getpos _building, getpos leader _group] select isNull _building;
_enemy = (leader _group) findNearestEnemy _pos;
if (isNull _enemy || {_pos distance2d _enemy < 25}) exitWith {_enemy};
leader _group doSuppressiveFire _enemy;
ObjNull
};
// compile actions
_fn_act = {
// deal with close enemy
if (!isNull _enemy) exitWith {
// posture
doStop units _group;
leader _group playAction selectRandom ["gestureAttack", "gestureGo", "gestureGoB"];
// location
_buildingPos = ((nearestBuilding _enemy) buildingPos -1) select {_x distance _enemy < 5};
_buildingPos pushBack getPosATL _enemy;
// act
{_x doMove selectRandom _buildingPos; _x doWatch _enemy; true} count units _group;
};
// clear and check buildings
_buildingPos = _building getVariable ["LAMBS_CQB_cleared_" + str (side _group),(_building buildingPos -1) select {lineIntersects [AGLToASL _x, (AGLToASL _x) vectorAdd [0, 0, 10]]}];
{
// the assault
if ((count _buildingPos > 0) && {unitReady _x}) then {
_x setUnitPos "UP";
_x forceSpeed 3;
_x doMove ((_buildingPos select 0) vectorAdd [0.5 - random 1, 0.5 - random 1, 0]);
// clean list
if (_x distance (_buildingPos select 0) < 30 || {(leader _group isEqualTo _x) && {random 1 > 0.5}}) then {
_buildingPos deleteAt 0;
} else {
// teleport debug (unit sometimes gets stuck due to Arma buildings )
if (lineIntersects [eyePos _x, (eyePos _x) vectorAdd [0, 0, 10]] && {_x distance (_buildingPos select 0) > 45} && {random 1 > 0.6}) then {
_x setVehiclePosition [getPos _x, [], 3.5];
};
};
} else {
// visualisation -- unit is either busy or too far to be effective
_x setUnitPos "MIDDLE";
// unit is ready and outside -- try suppressive fire
if (unitReady _x && {!(lineIntersects [eyePos _x, (eyePos _x) vectorAdd [0, 0, 10]])}) then {
_x doSuppressiveFire _building;
_x doFollow leader _group;
};
};
true
} count units _group;
// update variable
_building setVariable ["LAMBS_CQB_cleared_" + str (side _group), _buildingPos];
};
// functions end ---
// init
params ["_group", ["_range", 50], ["_cycle", 21]];
// sort grp
if (!local _group) exitWith {};
if (_group isEqualType objNull) then {_group = group _group;};
// orders
_group setSpeedMode "FULL";
_group setFormation "FILE";
_group enableAttack false;
_group allowFleeing 0;
{
_x disableAI "AUTOCOMBAT";
_x disableAI "SUPPRESSION";
_x enableIRLasers true;
} foreach units _group;
// loop
while {{alive _x} count units _group > 0} do {
// performance
waitUntil {sleep 1; simulationenabled leader _group};
// find building
_building = call _fn_find;
// find enemy
_enemy = call _fn_enemy;
// act!
if (isNull _building && {isNull _enemy}) exitWith {};
call _fn_act;
// wait
sleep _cycle;
};
// end
true