/
fn_analyzeTargets.sqf
288 lines (221 loc) · 10.2 KB
/
fn_analyzeTargets.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
278
279
280
281
282
283
284
285
286
287
if (!isServer) exitWith {};
private [ "_condition", "_targetlist", "_mklist", "_ActualTargets", "_cntC", "_target", "_mkname", "_i","_vehicleClass","_HQ_side"];
_HQ_side = _this select 0;
_mklist = _this select 1;
//If a unit has recently been within 50 meter of a target location in _tobecleared,
//then if the time he has been there is more recent then the target, its called cleared.
_ClearedDistance = 50;
//AFter this period of time the target is automaticly cleared. (will not be searched by the ai).
_TArgetAutoCleared = 1200;
//This sets how long a position of a unit is stored in the breadcrumb system.
//Each set 'breadcrumb' holds a time and a location. As long as the breadcrumb is there, it will be use dto blacklist a location for possible patrolling.
//Also will it be used to 'clear' target locations. If a unit has recently been there, then we can savely say that it is clear.
_LiveTimeBreadcrumb = 300;
_targetlist = [];
//if (MCC_GAIA_DEBUG) then{[_HQ_side,"HQ"] sidechat "Gathering Intelligence......Waitout."; };
//
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Phase 1: Gather TArgets, drop breadcrumbs
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
_ActualTargets = [];
_RecentTargets = [];
_OldTargets = [];
_ToBeCleared = [];
_NearTargets = [];
_OldTargetInfo = [];
_NewTargetInfo = [];
{
if (
//Seems like allgroups opens up with all sorts of empty groups, better check it
((side _x) == _HQ_side)
and
(count(units _x)>0)
)
then
{
_unit = leader _x;
//sleep 2;
//player globalchat format ["%1, %2, %3",(position _unit),_unit,_x];
//Place a breadcrumb
_vehicleClass = tolower (gettext (configFile >> "CfgVehicles" >> typeof (vehicle _unit) >> "vehicleClass"));
//Except for air, as air is not 'clearing the ground'
if ((_vehicleClass != "air")) then
{
//Now where ever a unit has last been, place a breadcrumb (so even static guards).
// This is used for making the patrols as optimized as possible. We try to avoid those positions.
switch (_HQ_side) do
{
case west : {MCC_GAIA_BREADCRUMBS_WEST = MCC_GAIA_BREADCRUMBS_WEST + [[(position _unit),time]];};
case east : {MCC_GAIA_BREADCRUMBS_EAST = MCC_GAIA_BREADCRUMBS_EAST + [[(position _unit),time]];};
case independent: {MCC_GAIA_BREADCRUMBS_INDEP = MCC_GAIA_BREADCRUMBS_INDEP + [[(position _unit),time]];};
case civilian : {MCC_GAIA_BREADCRUMBS_CIV = MCC_GAIA_BREADCRUMBS_CIV + [[(position _unit),time]];};
};
};
{
_Target_Pos = _x select 0;
_Target_PosAcc= _x select 5;
_Target_Side = _x select 2;
_Target = _x select 4;
if (
_Target_Side!= _HQ_side
and
((_Target_Side getFriend _HQ_side)<0.6)
and
alive(leader(group _Target))
and
!captive(_target)
and
//How sure are we? For now accuracy of 18 seems to work ok
_Target_PosAcc < 18
and
(_Target iskindof "AllVehicles")
//and
//If the lead has a clear LOS to a unit, that is valid enough (might expand later to check on all members)
//([_unit,_Target,1500] call GAIA_fnc_hasLineOfSight)
)
then
{
_Target setVariable ["GAIA_TargetInfo", [time,_Target_Pos,_Target_posAcc], false];
};
}foreach (_unit neartargets 1500);
};
} forEach AllGroups;
//
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Phase 3: Update Target Lists
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//if (MCC_GAIA_DEBUG) then {[_HQ_side,"HQ"] sidechat "Updating the targetlist."; };
{
if (
(((side _x) getFriend _HQ_side)<0.6)
)
then
{
//[_HQ_side,"HQ"] sidechat "Found!";
_OldTargetInfo = [];
_targetlist = [];
_OldTargetInfo = _x getVariable ["GAIA_TargetInfo",[]];
if (count(_OldTargetInfo)>0 ) then
{
_OldTarget_Time = time - (_OldTargetInfo select 0);
switch (true) do
{
case (_OldTarget_Time<60) : {_ActualTargets = _ActualTargets + [_x];};
case (_OldTarget_Time<200) : {_RecentTargets = _RecentTargets + [_x];};
case (_OldTarget_Time<360) : {_OldTargets = _OldTargets + [_x];};
case (_OldTarget_Time<_TargetAutoCleared) : {_ToBeCleared = _ToBeCleared + [_x];};
};
};
};
} forEach allUnits+vehicles;
// Debug to be cleared case (name the unit a)
//a setVariable ["GAIA_TargetInfo", [(time -400),(position a),1], false];
//_ToBeCleared = _ToBeCleared + [a];
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Phase 4: Send _ToBeCleared locations to Cleared if a unit has recently been there.
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
for [{_i=0},{_i < count _ToBeCleared},{_i=_i+1}] do
{
//Get the position of this dude
_OldTargetInfo = (_ToBeCleared select _i) getVariable ["GAIA_TargetInfo",[]];
//Check if we are in clear range and if so, clear this dude
if ([(_OldTargetInfo select 1),_HQ_side ] call GAIA_fnc_isCleared) then
{
(_ToBeCleared select _i) setVariable ["GAIA_TargetInfo", [(time-_TArgetAutoCleared),(_OldTargetInfo select 1),(_OldTargetInfo select 2)], false];
}
};
//
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Phase 5: Share Target Lists
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
switch (_HQ_side) do
{
case west : {MCC_GAIA_TARGETS_WEST = [_ActualTargets,_RecentTargets,_OldTargets,_ToBeCleared];};
case east : {MCC_GAIA_TARGETS_EAST = [_ActualTargets,_RecentTargets,_OldTargets,_ToBeCleared];};
case independent: {MCC_GAIA_TARGETS_INDEP = [_ActualTargets,_RecentTargets,_OldTargets,_ToBeCleared];};
case civilian : {MCC_GAIA_TARGETS_CIV = [_ActualTargets,_RecentTargets,_OldTargets,_ToBeCleared];};
};
//
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Phase 6: Clear Outdated Breadcrumps
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
switch (_HQ_side) do
{
case west : {
for [{_i=0},{_i < count MCC_GAIA_BREADCRUMBS_WEST},{_i=_i+1}] do
{
if ((time-((MCC_GAIA_BREADCRUMBS_WEST select _i) select 1))>_LiveTimeBreadcrumb) then
{
MCC_GAIA_BREADCRUMBS_WEST set [_i, "REMOVE"];
MCC_GAIA_BREADCRUMBS_WEST = MCC_GAIA_BREADCRUMBS_WEST - ["REMOVE"];
}
};
};
case east : {
for [{_i=0},{_i < count MCC_GAIA_BREADCRUMBS_EAST},{_i=_i+1}] do
{
if ((time-((MCC_GAIA_BREADCRUMBS_EAST select _i) select 1))>_LiveTimeBreadcrumb) then
{
MCC_GAIA_BREADCRUMBS_EAST set [_i, "REMOVE"];
MCC_GAIA_BREADCRUMBS_EAST = MCC_GAIA_BREADCRUMBS_EAST - ["REMOVE"];
}
};
};
case independent: {
for [{_i=0},{_i < count MCC_GAIA_BREADCRUMBS_INDEP},{_i=_i+1}] do
{
if ((time-((MCC_GAIA_BREADCRUMBS_INDEP select _i) select 1))>_LiveTimeBreadcrumb) then
{
MCC_GAIA_BREADCRUMBS_INDEP set [_i, "REMOVE"];
MCC_GAIA_BREADCRUMBS_INDEP = MCC_GAIA_BREADCRUMBS_INDEP - ["REMOVE"];
}
};
};
case civilian: {
for [{_i=0},{_i < count MCC_GAIA_BREADCRUMBS_CIV},{_i=_i+1}] do
{
if ((time-((MCC_GAIA_BREADCRUMBS_CIV select _i) select 1))>_LiveTimeBreadcrumb) then
{
MCC_GAIA_BREADCRUMBS_CIV set [_i, "REMOVE"];
MCC_GAIA_BREADCRUMBS_CIV = MCC_GAIA_BREADCRUMBS_CIV - ["REMOVE"];
}
};
};
};
//
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Phase 7: If debug is enabled, then show markers on the map
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
if (MCC_GAIA_DEBUG and _HQ_side==(Side player)) then
{
hint format ["Actual Targets: %1, Recent Targets: %2, Old Targets: %3,TBC: %4", _ActualTargets,_RecentTargets,_OldTargets,_tobecleared];
{
deleteMarkerLocal _x;
}
foreach _mklist;
_mklist = [];
{
_mkname = "mk" + str(_x);
createMarkerLocal [_mkname, getPos _x ];
_mklist = _mklist + [_mkname];
switch true do
{
case ( _x isKindOf "Man" ) : {_mkname setMarkerTypeLocal "b_inf";};
case ( _x isKindOf "Car" ) : {_mkname setMarkerTypeLocal "c_car";};
case ( _x isKindOf "Motorcycle" ) : {_mkname setMarkerTypeLocal "b_car";};
case ( _x isKindOf "Tank" ) : {_mkname setMarkerTypeLocal "b_armor";};
case ( _x isKindOf "Air" ) : {_mkname setMarkerTypeLocal "b_air";};
case ( _x isKindOf "Ship" ) : {_mkname setMarkerTypeLocal "b_naval";};
case ( _x isKindOf "StaticWeapon" ) : {_mkname setMarkerTypeLocal "b_installation";};
};
_OldTargetInfo = _x getVariable ["GAIA_TargetInfo",[]];
_mkname setMarkerPosLocal (_OldTargetInfo select 1);
_mkname setMarkerDirLocal getDir _x;
_mkname setMarkerAlphaLocal (1 - getDammage _x);
if (_x in _ActualTargets) then {_mkname setMarkerColorLocal "ColorGreen" };
if (_x in _RecentTargets) then {_mkname setMarkerColorLocal "ColorOrange" };
if (_x in _OldTargets) then {_mkname setMarkerColorLocal "ColorRed" };
if (_x in _ToBeCleared) then {_mkname setMarkerColorLocal "ColorWhite" };
}forEach _ActualTargets+_RecentTargets+_OldTargets+_ToBeCleared;
};
_mklist