-
Notifications
You must be signed in to change notification settings - Fork 148
/
fnc_taskPatrol.sqf
82 lines (66 loc) · 2.29 KB
/
fnc_taskPatrol.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
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_taskPatrol
Description:
A function for a group to randomly patrol a parsed radius and location.
Parameters:
- Group (Group or Object)
Optional:
- Position (XYZ, Object, Location or Group)
- Radius (Scalar)
- Waypoint Count (Scalar)
- Waypoint Type (String)
- Behaviour (String)
- Combat Mode (String)
- Speed Mode (String)
- Formation (String)
- Code To Execute at Each Waypoint (String)
- TimeOut at each Waypoint (Array [Min, Med, Max])
Example:
(begin example)
[this, getMarkerPos "objective1", 50] call CBA_fnc_taskPatrol
[this, this, 300, 7, "MOVE", "AWARE", "YELLOW", "FULL", "STAG COLUMN", "this call CBA_fnc_searchNearby", [3, 6, 9]] call CBA_fnc_taskPatrol;
(end)
Returns:
Nil
Author:
Rommel
---------------------------------------------------------------------------- */
params [
["_group", grpNull, [grpNull, objNull]],
["_position", [], [[], objNull, grpNull, locationNull], [2, 3]],
["_radius", 100, [0]],
["_count", 3, [0]]
];
_group = _group call CBA_fnc_getGroup;
if !(local _group) exitWith {}; // Don't create waypoints on each machine
_position = [_position, _group] select (_position isEqualTo []);
_position = _position call CBA_fnc_getPos;
// Clear existing waypoints first
[_group] call CBA_fnc_clearWaypoints;
{
_x enableAI "PATH";
} forEach units _group;
// Can pass parameters straight through to addWaypoint
_this =+ _this;
_this set [2,-1];
if (count _this > 3) then {
_this deleteAt 3;
};
// Using angles create better patrol patterns
// Also fixes weird editor bug where all WP are on same position
private _step = 360 / _count;
private _offset = random _step;
for "_i" from 1 to _count do {
// Gaussian distribution avoids all waypoints ending up in the center
private _rad = _radius * random [0.1, 0.75, 1];
// Alternate sides of circle & modulate offset
private _theta = (_i % 2) * 180 + sin (deg (_step * _i)) * _offset + _step * _i;
_this set [1, _position getPos [_rad, _theta]];
_this call CBA_fnc_addWaypoint;
};
// Close the patrol loop
_this set [1, _position];
_this set [2, _radius];
_this set [3, "CYCLE"];
_this call CBA_fnc_addWaypoint;