-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreak Contact.sqf
More file actions
230 lines (197 loc) · 6.07 KB
/
Break Contact.sqf
File metadata and controls
230 lines (197 loc) · 6.07 KB
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
params ['_group'];
// DEBUG SWITCHES
#define AAW_DEBUG true
#define AAW_DEBUG_LOG if (AAW_DEBUG) then {systemChat _debugMsg; diag_log _debugMsg}
// note --------- REGROUP IS DISABLED
// break contact is test high
// remaining check is moderately high
{
_x params ["_unit"];
// AI BREAK CONTACT OR SURRENDER.
if (!(isPlayer _unit)) then {
_x addEventHandler ["Killed", {
params ["_unit","_killer", "_insti"];
// REMOVE DEAD UNIT FROM ORIGINAL GROUP.
_origGroup = (group _unit);
[_unit] join grpNull;
// CONDITIONALS.
_remaining = (count units _origGroup <= 5);
_chanceBreakContact = (random 10 > 2);
_chanceRegroup = (random 10 > 10);
// IF IN CLOSE CONTACT, SURRENDER
_nearest = leader _origGroup findNearestEnemy position leader _origGroup;
_nearDistance = leader _origGroup distance _nearest <= 125;
private ["_chanceSurrender"];
if (!isNil '_nearest' && {_nearDistance}) then {_chanceSurrender = true};
// ORDER BREAK CONTACT.
if (_remaining && _chanceBreakContact) exitWith {
// DELETE ALL WAYPOINTS
[_origGroup] call ASG_fnc_clearWaypoints;
// FALL BACK TO FRIENDLY FORCES IF AVAILABLE.
if (_chanceRegroup) exitWith {
{
_x params ["_fallbackUnit"];
_fallbackGroup = group _fallbackUnit;
if ((side _x == side leader _origGroup) && (group _x != _origGroup)) exitWith {
_debugMsg = format ["[AI]: Regrouping with: %1", group _x]; AAW_DEBUG_LOG;
{
[_x] join grpNull;
[_x] join _fallbackGroup;
} forEach units _origGroup;
deleteGroup _origGroup;
_fallbackGroup setFormation "WEDGE";
_x move (getPos leader _fallbackGroup);
_x doMove (getPos leader _fallbackGroup);
_x commandFollow leader _fallbackGroup;
};
} forEach (leader _origGroup nearEntities [["Man","Car"], 250]);
};
// GENERATE BREAK CONTACT RENDEZVOUS.
_bcDir = (_killer getDir _unit);
_bcRV = _unit getPos [25, _bcDir];
// ON EACH UNIT IN THE KILLED UNITS GROUP.
{
_x params ["_unit"];
// POP SMOKE.
_unit forceWeaponFire ["SmokeShellMuzzle","SmokeShellMuzzle"];
_x commandWatch objNull;
// DELETE ALL WAYPOINTS
[(group _x)] call ASG_fnc_clearWaypoints;
} forEach (units _origGroup);
// BREAK CONTACT WAYPOINTS
_bcWP = _origGroup addWaypoint [_bcRV, 0];
_bcWP setWaypointBehaviour "AWARE"; // AWARE
_bcWP setWaypointCombatMode "GREEN"; // GREEN
_bcWP setWaypointSpeed "FULL"; // NORMAL
_bcWP setWaypointForceBehaviour true;
_bcWP2 = _origGroup addWaypoint [_bcRV getPos [100, _bcDir], 50];
_bcWP3 = _origGroup addWaypoint [_bcRV getPos [250, _bcDir], 50];
_bcWP3 setWaypointStatements ["true", "
_locGroup = group this;
"];
};
// ORDER SURRENDER.
if (_remaining && _chanceSurrender) then {
_debugMsg = format ["[AI]: %1 surrendering.", _origGroup]; AAW_DEBUG_LOG;
{
_x params ["_unit"];
missionNamespace setVariable [format ["%1Surrender", _unit],
[_unit] spawn {
params ['_unit'];
// SET CAPTIVE
_unit setCaptive true;
// KNEEL.
_unit setUnitPos "Middle";
uiSleep 1;
// DROP PRI WEAPON INTO GROUND HOLDER.
_grWepHolder = createVehicle ["groundWeaponHolder", (position _unit), [], 0, "CAN_COLLIDE"];
_grWepHolder addMagazineCargoGlobal [(currentMagazine _unit), 1];
// DROP ITEMS.
{
if (_forEachindex > 2) then {
_unit action ["DropBag", _grWepHolder, _x];
} else {
if (_x != "") then {
_unit action ["DropWeapon", _grWepHolder, _x];
uiSleep 3;
};
};
} forEach [
(primaryWeapon _unit),
(secondaryWeapon _unit),
(handgunWeapon _unit),
(backPack _unit)
];
sleep 2;
_unit switchMove "amovpknlmstpsnonwnondnon";
// DISABLE UNIT.
_unit stop true;
{_unit disableAI _x} forEach ["MOVE", "AUTOTARGET", "TARGET", "ANIM", "CHECKVISIBLE"];
// SURRENDER ANIMATION.
_unit playMove "AmovPercMstpSnonWnonDnon_AmovPercMstpSsurWnonDnon";
// SURRENDER ADDACTION.
[_unit] call ASG_fnc_powTakeAction;
// NULLIFY
missionNamespace setVariable [format ["%1Surrender", _unit], nil];
}
];
} forEach (units _origGroup);
// CLEAR WAYPOINTS
[] call ASG_fnc_clearWaypoints;
};
}];
};
} forEach units _group;
// DELETE ALL WAYPOINTS.
ASG_fnc_clearWaypoints = {
params ["_origGroup"];
while {(count (waypoints _origGroup)) > 0} do {
deleteWaypoint ((waypoints _origGroup) select 0)
};
};
// ADD TAKE P.O.W. ADDACTION TO A UNIT.
ASG_fnc_powTakeAction = {
params ['_unit'];
_unit addAction [
"Take Prisoner",
"
params ['_target','_caller','_ID','_args'];
_this call ASG_fnc_powTake;
",
nil,
6,
false,
true,
"",
"
_this == leader group _this
",
2,
false
];
};
// ADDACTION CODE FOR TAKING P.O.W.
ASG_fnc_powTake = {
params ['_target','_caller','_ID','_args'];
// RESET STATES AND JOIN TARGET GROUP
{_target enableAI _x} forEach ["MOVE", "AUTOTARGET", "TARGET", "ANIM", "CHECKVISIBLE"];
_target stop false;
[_target] join group _caller;
_target setUnitPos "Auto";
group _caller setFormation 'FILE';
// ADDACTION HANDLING
_target removeAction _ID;
[_target] call ASG_fnc_powRelAction;
};
// ADD RELEASE P.O.W. ADDACTION TO A UNIT.
ASG_fnc_powRelAction = {
params ['_unit'];
_unit addAction [
"Release Prisoner",
"
params ['_target','_caller','_ID','_args'];
_this call ASG_fnc_powRel;
",
nil,
6,
false,
true,
"",
"
_this == leader group _this
",
2,
false
];
};
// ADDACTION CODE FOR RELEASING P.O.W.
ASG_fnc_powRel = {
params ['_target','_caller','_ID','_args'];
// SET STATES AND ANIMS
[_target] join grpNull;
{_target disableAI _x} forEach ["MOVE", "AUTOTARGET", "TARGET", "ANIM", "CHECKVISIBLE"];
_target playMove "AmovPercMstpSnonWnonDnon_AmovPercMstpSsurWnonDnon";
// ADDACTION HANDLING
_target removeAction _id;
[_target] call ASG_fnc_powTakeAction;
};