-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker.sqf
277 lines (214 loc) · 9.33 KB
/
tracker.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/* ******************** Defines ***************** */
#define INFANTRY_MIN_TIME 175
#define INFANTRY_VAR 10
// Initial wait before drone tracking starts
#define INITIAL_WAIT initialDroneDelay
// Delay after drones are turned online and the first check is done
#define MIN_FIRST_TRACKING_DELAY 5
#define RAND_FIRST_TRACKING_DELAY 8
#define MAX_CHANCE 100
#define INFANTRY_CHANCE 20
// This is the time when any manned vehicles will be captured & tracked
#define VEHICLE_MIN_TIME 35
#define VEHICLE_VAR 10
// The time when only old vehicles are being checked, and no new vehicles are being added to the list
#define VEHICLE_SWEETSPOT 10
#define ROAD_DISTANCE 8
#define VEHICLE_MIN_CHANCE 30
#define VEHICLE_SPEED_CHANCE_MULT 0.475
#define VEHICLE_ROAD_CHANCE 30
#define SPOT_COUNT_VAR "mh_drone_spotcount"
#define SPOT_POSITION_VAR "mh_drone_spotposition"
#define SPOT_DISTANCE 115
/* ******************** End defines ***************** */
droneTrackerMarkers = ["drone_marker_1", "drone_marker_2", "drone_marker_3", "drone_marker_4", "drone_marker_5", "drone_marker_6", "drone_marker_7", "drone_marker_8", "drone_marker_9", "drone_marker_10"];
private _timeUntilTracking = round (INITIAL_WAIT/60);
[[[west, "HQ"], format ["Drone are being configured and we will start monitoring the area in about %1 minutes.", _timeUntilTracking]], "sideChat", west] call Bis_fnc_mp;
[[[east, "HQ"], format [ "NATO drones are coming online and will be tracking your movements in about %1 minutes.", _timeUntilTracking ]], "sideChat", east] call Bis_fnc_mp;
sleep INITIAL_WAIT;
[[[west, "HQ"], "Drone coverage is now online, first reports will be available momentarily."], "sideChat", west] call Bis_fnc_mp;
[[[east, "HQ"], "Be advised, we are receiving information that drone coverage is being turned online."], "sideChat", east] call Bis_fnc_mp;
sleep (MIN_FIRST_TRACKING_DELAY + (random RAND_FIRST_TRACKING_DELAY));
//diag_log "Drones are online";
nextVehicleCheckUnits = [ ];
//==================================================
// Infantry checker
//==================================================
[] spawn {
private ["_trackerMarker"];
_trackerMarker = compileFinal preprocessFileLineNumbers "trackerMarker.sqf";
while{true} do
{
private["_detected"];
_detected = false;
private["_units"];
_units = [east, { private["_pl"]; _pl = _this select 0; alive _pl && (vehicle _pl == _pl); }] call Mh_fnc_getSideUnits;
//diag_log (format ["Infantry check started for %1", _units]);
private ["_chance"];
_chance = INFANTRY_CHANCE;
{
private ["_spotCount", "_spotPosition"];
_spotCount = _x getVariable [SPOT_COUNT_VAR, 0];
_spotPosition = _x getVariable [SPOT_POSITION_VAR, [0,0,0]];
private ["_rand"];
_rand = floor random (MAX_CHANCE + 1);
//diag_log format ["Checking %1 with random %2 and chance %3", name _x, _rand, _chance];
private["_trackerRet"];
_trackerRet = [_x, detectionRadius / (2 ^ _spotCount), _rand, _chance + _spotCount * (MAX_CHANCE - _chance)] call _trackerMarker;
if(_trackerRet select 0) then
{
_detected = true;
private["_pos"];
_pos = _trackerRet select 1;
[[[West, "HQ"], format ["Hostile on foot spotted around grid %1", mapGridPosition _pos]], "sideChat", west] call Bis_fnc_mp;
if(_spotCount == 0 || (_spotPosition distance (getPos _x)) <= SPOT_DISTANCE) then
{
_x setVariable [SPOT_POSITION_VAR, getPos _x];
_x setVariable [SPOT_COUNT_VAR, _spotCount + 1];
}
else
{
_x setVariable [SPOT_COUNT_VAR, 0];
};
sleep 2;
}
else
{
_x setVariable [SPOT_COUNT_VAR, 0];
};
} forEach _units;
private["_sleep"];
_sleep = INFANTRY_MIN_TIME + (random INFANTRY_VAR);
//diag_log format ["Drones sleeping: %1", _sleep];
if(!_detected) then
{
[[[West, "HQ"], "Drone operators report no hostiles."], "sideChat", west] call Bis_fnc_mp;
};
sleep _sleep;
};
};
//==================================================
// Vehicle checker
//==================================================
[] spawn {
private ["_trackerMarker"];
_trackerMarker = compile preprocessFileLineNumbers "trackerMarker.sqf";
private["_checkAllVehicles"];
_checkAllVehicles = {
private["_vehicleCheck"];
_vehicleCheck = {
private ["_veh"];
_veh = _this select 0;
private["_speed", "_roadChecks", "_totalChecks"];
_speed = _veh getVariable ["mh_drone_sumspeed", 0];
_roadChecks = _veh getVariable ["mh_drone_roadchecks", 0];
_totalChecks = _veh getVariable ["mh_drone_totalchecks", 0];
_veh setVariable ["mh_drone_sumspeed", _speed + (abs (speed _veh))];
_veh setVariable ["mh_drone_totalchecks", _totalChecks + 1];
private["_road"];
_road = [getPos _veh, ROAD_DISTANCE, []] call BIS_fnc_nearestRoad;
if(!(isNull _road) || (isOnRoad getPosATL _veh)) then
{
_veh setVariable ["mh_drone_roadchecks", _roadChecks + 1];
};
};
private["_oldVehicles"];
_oldVehicles = _this select 0;
private ["_units"];
_units = [east, { private["_pl"]; _pl = _this select 0; alive _pl && vehicle _pl != _pl; }] call Mh_fnc_getSideUnits;
{
private ["_vh"];
_vh = vehicle _x;
if(!(_vh in _oldVehicles) && !(_vh in nextVehicleCheckUnits)) then
{
nextVehicleCheckUnits pushBack _vh;
};
} forEach _units;
private["_vehicles"];
_vehicles = nextVehicleCheckUnits + _oldVehicles;
if(count _vehicles > 0) then
{
//diag_log format ["Vehicle check on %1", _vehicles];
{
[_x] call _vehicleCheck;
} forEach _vehicles;
};
};
private ["_counter", "_sleepTime"];
_sleepTime = 2.5;
while {true} do
{
//diag_log "New vehicle check launched";
_counter = floor ((VEHICLE_MIN_TIME + random VEHICLE_VAR)/_sleepTime);
private["_i"];
for "_i" from 0 to _counter do
{
[[]] call _checkAllVehicles;
sleep _sleepTime;
};
private ["_oldVehicles"];
_oldVehicles = nextVehicleCheckUnits;
nextVehicleCheckUnits = [ ];
//diag_log "Sweetspot enabled";
_counter = floor (VEHICLE_SWEETSPOT/_sleepTime);
for "_i" from 0 to _counter do
{
[_oldVehicles] call _checkAllVehicles;
sleep _sleepTime;
};
// Mark vehicles here
// Calculate chance & markers
//diag_log "Marking vehicles";
private ["_detected"];
_detected = false;
{
if(isNull _x) then
{
diag_log "Attempted a check on null";
}
else
{
private ["_totalChecks"];
_totalChecks = _x getVariable ["mh_drone_totalchecks", 0];
if(_totalChecks == 0) then
{
diag_log "TotalChecks set to 0!";
}
else
{
private["_avgSpeed", "_checksPerc"];
_avgSpeed = (_x getVariable["mh_drone_sumspeed", 0]) / _totalChecks;
_checksPerc = (_x getVariable["mh_drone_roadchecks", 0]) / _totalChecks;
//diag_log (format["Executing a check for: Total Checks - %1 AvgSpeed - %2 ChecksPerc - %3", _totalChecks, _avgSpeed, _checksPerc]);
private["_chance"];
_chance = VEHICLE_MIN_CHANCE + _avgSpeed * VEHICLE_SPEED_CHANCE_MULT + VEHICLE_ROAD_CHANCE * _checksPerc;
private["_rand"];
_rand = floor (random MAX_CHANCE);
//diag_log (format["Chance is %1, randomed %2", _chance, _rand]);
private["_trackerRet"];
_trackerRet = [_x, detectionRadiusVehicle, _rand, _chance] call _trackerMarker;
if(_trackerRet select 0) then
{
private ["_vehType"];
_vehType = "Manned";
if(count crew _x == 0) then
{
_vehType = "Abandoned";
};
_detected = true;
[[[West, "HQ"], format ["%1 vehicle spotted at grid %2.", _vehType, mapGridPosition (_trackerRet select 1)] ], "sideChat", west] call Bis_fnc_mp;
sleep 2;
};
_x setVariable ["mh_drone_sumspeed", 0];
_x setVariable ["mh_drone_roadchecks", 0];
_x setVariable ["mh_drone_totalchecks", 0];
};
};
} forEach _oldVehicles;
if(!_detected) then
{
[[[West, "HQ"], "No vehicle activity spotted."], "sideChat", west] call Bis_fnc_mp;
};
};
// End while loop
};