-
Notifications
You must be signed in to change notification settings - Fork 148
/
fnc_searchNearby.sqf
72 lines (56 loc) · 2.21 KB
/
fnc_searchNearby.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
/* ----------------------------------------------------------------------------
Function: CBA_fnc_searchNearby
Description:
A function for a group to search a nearby building.
Parameters:
- Group (Group or Object)
Example:
(begin example)
[group player] call CBA_fnc_searchNearby
(end)
Returns:
Nil
Author:
Rommel, SilentSpike
---------------------------------------------------------------------------- */
params ["_group"];
_group = _group call CBA_fnc_getGroup;
if !(local _group) exitWith {}; // Don't create waypoints on each machine
private _building = nearestBuilding (leader _group);
if ((leader _group) distanceSqr _building > 250e3) exitWith {};
[_group, _building] spawn {
params ["_group", "_building"];
private _leader = leader _group;
// Add a waypoint to regroup after the search
_group lockWP true;
private _wp = _group addWaypoint [getPosASL _leader, -1, currentWaypoint _group];
private _cond = "({unitReady _x || !(alive _x)} count thisList) == count thisList";
private _comp = format ["this setFormation '%1'; this setBehaviour '%2'; deleteWaypoint [group this, currentWaypoint (group this)];", formation _group, behaviour _leader];
_wp setWaypointStatements [_cond, _comp];
// Prepare group to search
_group setBehaviour "Combat";
_group setFormDir ([_leader, _building] call BIS_fnc_dirTo);
// Leader will only wait outside if group larger than 2
if (count (units _group) <= 2) then {
_leader = objNull;
};
// Search while there are still available positions
private _positions = _building buildingPos -1;
while {_positions isNotEqualTo []} do {
// Update units in case of death
private _units = (units _group) - [_leader];
// Abort search if the group has no units left
if (_units isEqualTo []) exitWith {};
// Send all available units to the next available position
{
if (_positions isEqualTo []) exitWith {};
if (unitReady _x) then {
private _pos = _positions deleteAt 0;
_x commandMove _pos;
sleep 2;
};
} forEach _units;
sleep 0.25;
};
_group lockWP false;
};