Repository navigation
Expand file tree
/
Copy pathTaskSystem (1).sqf
More file actions
1076 lines (841 loc) · 44.6 KB
/
Copy pathTaskSystem (1).sqf
File metadata and controls
1076 lines (841 loc) · 44.6 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
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define HARPY_GROUP units Harpy
// Declaration for base structures
/*
TaskLocation structure:
{
constructor: {
// _location: Array or String - [X,Y,Z] ATL position, or string containing map marker name
params ["_location", "_name"];
},
position: [x,y,z] ATL,
name: "Display Name of the location"
}
*/
wolf_tasksystem_decl_TaskLocation = [
["#create", {
params ["_location", "_name"];
if (_location isEqualType "") then {
// Location is a map marker name
_self set ["position", getMarkerPos _location];
} else {
// Location is XYZ coordinate
_self set ["position", _location];
};
_self set ["name", _name]
}]
];
/*
TaskType structure
{
taskType: "typeName",
canBeInitial: true, // Whether this can be a start task, if false then it can only be started via a continuation
possibleLocations: [TaskLocation structure, ...], // Multiple possible locations for this task
// This is set to automatically launch a new task once this one is finished
// For example a dropoff task, that should be started after a delivery task
// The new task will receive the ID of the previous task
// Can be empty string to be "any type of task". Leave un-set to not have a continuation task
continuationType: "taskType name" or TaskInstance or nil,
createTask: {
// _previousTask: TaskInstance (optional) - Instance of the previous task, that this task is supposed to be a followup for
// _targetLocation: TaskLocation - One of the locations that was listed in the possibleLocations entry
params ["_previousTask", "_targetLocation"];
// Returns Task Instance structure
},
onStart: {
// Create BIS_fnc_task, tell user the task has started
},
completionCondition: {
// Condition whether task is completed, is called regularly
// Must return true or false
},
onComplete: {
// Called when task is completed. Should set the BIS_fnc_task to completed
},
}
*/
wolf_tasksystem_decl_TaskType = [
["taskType", ""],
["canBeInitial", true],
["possibleLocations", []],
["getContinuationType", { }],
["createTask", { }],
["onStart", { }],
["completionCondition", { true }],
["onComplete", { }]
];
/*
TaskInstance structure
{
taskType: TaskType structure,
taskID: "Unique Task ID used for bis_fnc_task*"
location: [x,y,z] or "mapMarkerName",
// This is set to automatically launch a new task once this one is finished
// For example a dropoff task, that should be started after a delivery task
// The new task will receive the ID of the previous task
// Can be empty string to be "any type of task". Leave un-set to not have a continuation task
continuationType: "taskType name" or TaskInstance,
// Some parameters can overwrite the ones defined in tasktype. For their types look at the TaskType structure definition above
continuationType: nil,
start: {},
completionCondition: {}
onComplete: {}
}
*/
wolf_tasksystem_decl_TaskInstance = [
["taskType", nil], // Reference to TaskType structure
["taskID", ""], // Will be set by constructor
["#create", {
// Generate a new task id, it must be unique, to accomplish that we simply hash some data that is always different
private _timeHash = hashValue [systemTimeUTC, diag_tickTime];
_self set ["taskID", format["task_%1", _timeHash]];
}],
// It is possible to override these with custom ones, by default we just forward the call to the taskType
["getContinuationType", { call ((_self get "taskType") get "getContinuationType"); }],
["onStart", { call ((_self get "taskType") get "onStart"); }],
["completionCondition", { call ((_self get "taskType") get "completionCondition"); }],
["onComplete", { call ((_self get "taskType") get "onComplete"); }]
];
// Basic task system functions
wolf_tasksystem_fnc_createTaskLocation = {
params ["_location", "_name"];
// _location is [x,y,z] in ATL format, or a string of a marker name
createHashMapObject [wolf_tasksystem_decl_TaskLocation, [_location, _name]];
};
wolf_tasksystem_activeTasks = [];
wolf_tasksystem_taskTypes = createHashMap;
wolf_tasksystem_fnc_registerTaskType = {
params ["_newTaskType"];
wolf_tasksystem_taskTypes set [_newTaskType get "taskType", _newTaskType];
};
wolf_tasksystem_fnc_selectTaskType = {
params [["_filter", "", ["", []]]];
// _filter has a couple options
// Empty string - Any "initial" task type
// string - name of a specific taskType
// TaskType instance - Just return that instance, we already selected what we want...
// Array of string or TaskType instance - select a random one from that array
if (_filter isEqualTo "") exitWith {
// Any initial task, try to find one at a unused location
// Collect all possible locations from all task types
// Only tasks that can be initial, not continuation tasks
private _initialTaskTypes = ((values wolf_tasksystem_taskTypes) select {_x get "canBeInitial"});
private _possibleLocations = [];
{
// _x: TaskType
//actually isEqualRef would be better here, but pushBackUnique uses isEqualTo internally, probably doesn't matter
_possibleLocations insert [-1, _x get "possibleLocations", true];
} forEach _initialTaskTypes;
// Try to filter out locations of already active tasks, to not have multiple tasks starting at same location
// Find them by iterating wolf_tasksystem_activeTasks, and getting their locations
private _possibleLocationsExcludingActiveTasks = _possibleLocations - (wolf_tasksystem_activeTasks apply {_x get "location"});
// We might fail if too many tasks are active, in that case just allow creating a task at a duplicated location
if (_possibleLocationsExcludingActiveTasks isNotEqualTo []) then { _possibleLocations = _possibleLocationsExcludingActiveTasks; };
// Select a random location for our new task
private _targetLocation = selectRandom _possibleLocations;
// Now find all possible tasks, that support this location (this can never fail, its atleast one)..
private _possibleTasks = _initialTaskTypes select {_targetLocation in (_x get "possibleLocations")};
// ... and select a random one
[selectRandom _possibleTasks, _targetLocation]
};
if (_filter isEqualType "") exitWith {
// Find specific type by its name
private _newTaskType = wolf_tasksystem_taskTypes get _filter;
if (isNil "_newTaskType") exitWith {[nil, nil]};
private _targetLocation = selectRandom (_newTaskType get "possibleLocations");
[_newTaskType, _targetLocation]
};
if (_filter isEqualType []) exitWith {
_possibleTypes = (_filter apply { _x call wolf_tasksystem_fnc_selectTaskType; });
// Find specific type by its name
selectRandom _possibleTypes // A random one of all the possibilities
};
[nil, nil]; // Huh?
};
wolf_tasksystem_fnc_startNewTask = {
params ["_newTaskType", "_targetLocation", "_previousTask"];
// Create the task
private _newTaskInstance = _newTaskType call ["createTask", [_previousTask, _targetLocation]];
// Add to active
wolf_tasksystem_activeTasks pushBack _newTaskInstance;
// Start
_newTaskInstance call ["onStart"];
};
wolf_tasksystem_fnc_updateActiveTasks = {
{
// _x: TaskInstance
// Check if complete
private _isCompleted = _x call ["completionCondition"];
diag_log ["task completed?", (_x get "taskType") get "taskType", _isCompleted];
if (_isCompleted) then { // Don't care about uncompleted tasks
diag_log ["task completed", (_x get "taskType") get "taskType"];
// Task is completed, remove it from active, finish it, check for continuation
wolf_tasksystem_activeTasks deleteAt (wolf_tasksystem_activeTasks find _x);
_x call ["onComplete"];
// Continuation?
private _continuation = _x call ["getContinuationType"];
if (isNil "_continuation") then { continue; }; // No continuation, we're done with this
(_continuation call wolf_tasksystem_fnc_selectTaskType) params ["_newTaskType", "_targetLocation"];
if (isNil "_newTaskType") then { continue; }; // Couldn't find anything to continue with
[_newTaskType, _targetLocation, _x] call wolf_tasksystem_fnc_startNewTask;
};
} forEachReversed wolf_tasksystem_activeTasks; // Reversed because we're deleting elements
};
wolf_tasksystem_fnc_createRandomTask = {
// select any initial task type
("" call wolf_tasksystem_fnc_selectTaskType) params ["_newTaskType", "_targetLocation"];
if (isNil "_newTaskType") exitWith {}; // Couldn't find anything to start?
[_newTaskType, _targetLocation, nil] call wolf_tasksystem_fnc_startNewTask;
};
// Delivery locations for both cargo and squads
// Define Pickup Locations
SUPPLY_PORT = [[14260.3,13074.3,1.56451], "Supply Port"] call wolf_tasksystem_fnc_createTaskLocation;
AIRFIELD = [[14638.5,16754.9,0], "Airfield"] call wolf_tasksystem_fnc_createTaskLocation;
FIELD_HOSPITAL = [[14412.9,18996.9,3.8147e-06], "Field Hospital"] call wolf_tasksystem_fnc_createTaskLocation;
LZ_GAMMA = [[10414,18962,-2.28882e-05], "LZ Gamma"] call wolf_tasksystem_fnc_createTaskLocation;
LZ_WHISKEY = [[9533.26,15139.6,0], "LZ Whiskey"] call wolf_tasksystem_fnc_createTaskLocation;
// Define Delivery Locations
DELIVERY_CHARLIE = [[11578.2,11908.5,1.90735e-06], "Charlie"] call wolf_tasksystem_fnc_createTaskLocation; //#TODO Replace with actual coordinates or map marker name
DELIVERY_PAPA = [[18642.4,16935.2,0], "Papa"] call wolf_tasksystem_fnc_createTaskLocation;
DELIVERY_QUEBEC = [[17598.9,17246.5,1.52588e-05], "Quebec"] call wolf_tasksystem_fnc_createTaskLocation;
DELIVERY_ROMEO = [[12280.1,8910.93,-1.52588e-05], "Romeo"] call wolf_tasksystem_fnc_createTaskLocation;
DELIVERY_YANKEE = [[9749.67,15871.5,0], "Yankee"] call wolf_tasksystem_fnc_createTaskLocation;
DELIVERY_JULIET = [[17733.8,14980,-7.62939e-06], "Juliet"] call wolf_tasksystem_fnc_createTaskLocation;
// Define task types
// Cargo pickup, different kinds of cargo boxes
private _taskPickupCargo = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskType], // Inherit the base TaskType definitions
// Now we customize the parts we want to overwrite
["taskType", "pickupCargo"], // Name of our type (must be unique across all task types)
["possibleLocations", [SUPPLY_PORT, AIRFIELD]],
// Pickup cargo task has special parameter of what kind of cargo is to be picked up, we define that here
// [classname, display name]
["possibleCargoTypes", [
["ACE_Box_Ammo", "Ammo"],
["FlexibleTank_01_forest_F", "Fuel"],
["Box_Cargo_Grey_RF", "Spare Parts"],
["ACE_Box_Misc", "General Supplies"]
]],
// taskType that will automatically start, once this task has completed
["getContinuationType", {"deliverCargo"}],
// Function called to create a new task of this type
["createTask", {
params ["_previousTask", "_targetLocation"];
// Pickup missions never have a previous task, so we just ignore it
// Pickup cargo task has special parameter of what kind of cargo is to be picked up, we select that now
private _cargoType = selectRandom (_self get "possibleCargoTypes");
private _taskInstance = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskInstance], // Inherit the base TaskInstance definitions
["taskType", _self], // Task type must always be passed along
["location", _targetLocation],
["cargoType", _cargoType] // _cargoType = [classname, display name]
]
];
_taskInstance;
}],
// Task execution is started, create assets, notify player about task
["onStart", {
// _self is a TaskInstance
diag_log ["onStart", _self];
(_self get "cargoType") params ["_cargoClass", "_cargoName"];
private _locationName = (_self get "location") get "name";
private _locationPosition = (_self get "location") get "position";
private _markerText = format["Pick up %1 from %2", _cargoName, _locationName];
// Create Task, only for members of Harpy group
[Harpy, _self get "taskID", ["Pickup cargo from the specified location", _markerText], _locationPosition, "AUTOASSIGNED", 1, true, "takeoff", true] call BIS_fnc_taskCreate;
// Spawn Crate
private _crate = createVehicle [_cargoClass, _locationPosition, [], 0, "CAN_COLLIDE"];
_crate setPosATL _locationPosition;
_self set ["cargoCrate", _crate]; // Store crate reference
// Purple Smoke Handler for Crates
private _smokeHandler = [_self] spawn {
params ["_task"]; // _task: TaskInstance
private _crate = _task get "cargoCrate";
// Wait until players are close enough to target
waitUntil {
{ _x distance _crate < 1500 } count HARPY_GROUP > 0
};
"SmokeShellPurple" createVehicle getPosATL _crate;
//#TODO there could be a while loop here, that waits until cargo is picked up, and repeatedly pops the smoke unless units are already right next to cargo
// It can be a while true loop, this script will get killed when the task is completed
};
_self set ["smokeHandler", _smokeHandler];
// Task Success Handler using ACE event
["ace_cargoLoaded", {
params ["_item", "_vehicle"];
_thisArgs params ["_task"]; // _task: TaskInstance
if (_item isEqualTo (_task get "cargoCrate")) then {
_task set ["isCompleted", true]; // This will be caught by the completion handler
["ace_cargoLoaded", _thisId] call CBA_fnc_removeEventHandler; // We don't need this eventhandler anymore
call wolf_tasksystem_fnc_updateActiveTasks; // Trigger global task system update, so player instantly gets notification
};
}, _self] call CBA_fnc_addEventHandlerArgs;
}],
["completionCondition", {
// _self is a TaskInstance
_self getOrDefault ["isCompleted", false] // This is set by ACE event
}],
["onComplete", {
// _self is a TaskInstance
[_self get "taskID", "SUCCEEDED", true] call BIS_fnc_taskSetState;
// Kill the smoke handler if it's still running.
terminate (_self get "smokeHandler");
}]
]
];
_taskPickupCargo call wolf_tasksystem_fnc_registerTaskType;
// Medical cargo is the same as cargo pickup, except that it only happens from one specific location and only has one type of cargo
private _taskPickupCargoMedical = createHashMapObject [
[
["#base", _taskPickupCargo], // Inherit everything from the cargo pickup type
// Overwrite some parameters that are different from cargo pickup
["taskType", "pickupCargoMedical"], // Name of our type (must be unique across all task types)
["possibleLocations", [FIELD_HOSPITAL]], // Can only be picked up at field hospital
// [classname, display name]
["possibleCargoTypes", [
["ACE_medicalSupplyCrate_advanced", "Medical Supplies"] // Can only be a medical box
]]
]
];
_taskPickupCargoMedical call wolf_tasksystem_fnc_registerTaskType;
// Deliver cargo (needs to be used as continuation of pickup cargo task), to random location (locations depend on type of cargo that was picked up)
private _taskDeliverCargo = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskType], // Inherit the base TaskType definitions
// Now we customize the parts we want to overwrite
["taskType", "deliverCargo"], // Name of our type (must be unique across all task types)
["canBeInitial", false], // This task can only be started as continuation (cannot delivery something without picking it up first)
["possibleLocations", [SUPPLY_PORT, AIRFIELD]],
["getContinuationType", { }], // After this task the chain ends
// Function called to create a new task of this type
["createTask", {
params ["_previousTask", "_targetLocation"];
// Delivery missions always have a previous task, we need them to find out what we are delivering
// Assert _previousTask != nil
// Assert ((_previousTask get "taskType") get "taskType") in ["pickupCargo", "pickupCargoMedical"]
private _previousType = ((_previousTask get "taskType") get "taskType");
// We ignore the randomly selected target location that we get.
// Because the task system doesn't know that we have specific dropoff locations for the cargo types
// Different pickup types have different sets of dropoff locations
private _possibleDropOffLocations = switch (_previousType) do {
case "pickupCargo": {
// depends on cargo type
private _cargoType = _previousTask get "cargoType"; // _cargoType = [classname, display name]
switch (_cargoType select 1) do {
case "Ammo": {[DELIVERY_QUEBEC, DELIVERY_ROMEO, DELIVERY_YANKEE, DELIVERY_JULIET]};
case "Fuel": {[DELIVERY_CHARLIE, DELIVERY_PAPA]};
case "Spare Parts": {[DELIVERY_CHARLIE, DELIVERY_PAPA]};
case "General Supplies": {[DELIVERY_YANKEE, DELIVERY_JULIET]};
default {[]}; //#TODO can't be empty here, we need _SOME_ location.
};
};
case "pickupCargoMedical": {[DELIVERY_YANKEE, DELIVERY_JULIET]};
default {[]};
};
private _targetLocation = selectRandom _possibleDropOffLocations;
private _taskInstance = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskInstance], // Inherit the base TaskInstance definitions
["taskType", _self], // Task type must always be passed along
["location", _targetLocation],
["previousTask", _previousTask],
["cargoCrate", _previousTask get "cargoCrate"] // Pass along the cargo crate, that the pickup task had created
]
];
_taskInstance;
}],
// Task execution is started, create assets, notify player about task
["onStart", {
// _self is a TaskInstance
((_self get "previousTask") get "cargoType") params ["_cargoClass", "_cargoName"];
private _locationName = (_self get "location") get "name";
private _locationPosition = (_self get "location") get "position";
private _markerText = format["Deliver %1 to %2", _cargoName, _locationName];
// Create Task, only for members of Harpy group
[Harpy, _self get "taskID", ["Deliver cargo to the specified location", _markerText], _locationPosition, "AUTOASSIGNED", 1, true, "land", true] call BIS_fnc_taskCreate;
// Purple Smoke Handler for Delivery
private _smokeHandler = [_self] spawn {
params ["_task"]; // _task: TaskInstance
private _deliveryLocation = (_task get "location") get "position";
// Wait until players are close enough to target
waitUntil {
{ _x distance _deliveryLocation < 1500 } count HARPY_GROUP > 0
};
"SmokeShellPurple" createVehicle _deliveryLocation;
//#TODO there could be a while loop here, that waits until cargo is picked up, and repeatedly pops the smoke unless units are already right next to cargo
// It can be a while true loop, this script will get killed when the task is completed
};
_self set ["smokeHandler", _smokeHandler];
// Task Success Handler using ACE event
["ace_cargoUnloaded", {
params ["_item", "_vehicle", "_unloadType"];
_thisArgs params ["_task"]; // _task: TaskInstance
private _crate = (_task get "cargoCrate");
private _deliveryLocation = (_task get "location") get "position";
if (_item isEqualTo _crate && {_crate distance _deliveryLocation < 50}) then {
_task set ["isCompleted", true]; // This will be caught by the completion handler
["ace_cargoUnloaded", _thisId] call CBA_fnc_removeEventHandler; // We don't need this eventhandler anymore
call wolf_tasksystem_fnc_updateActiveTasks; // Trigger global task system update, so player instantly gets notification
[_crate] spawn {
params ["_crate"];
sleep 120; //#TODO instead wait for delivery crew to be further away?
deleteVehicle _crate;
};
};
}, _self] call CBA_fnc_addEventHandlerArgs;
}],
["completionCondition", {
// _self is a TaskInstance
_self getOrDefault ["isCompleted", false] // This is set by ACE event
}],
["onComplete", {
// _self is a TaskInstance
[_self get "taskID", "SUCCEEDED", true] call BIS_fnc_taskSetState;
// Kill the smoke handler if it's still running.
terminate (_self get "smokeHandler");
}]
]
];
_taskDeliverCargo call wolf_tasksystem_fnc_registerTaskType;
// Spawn a squad at location, wait for them to be picked up with vehicle
private _taskPickupSquad = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskType], // Inherit the base TaskType definitions
// Now we customize the parts we want to overwrite
["taskType", "pickupSquad"], // Name of our type (must be unique across all task types)
["possibleLocations", [SUPPLY_PORT, AIRFIELD]],
// taskType that will automatically start, once this task has completed
["getContinuationType", {"deliverSquad"}],
// Function called to create a new task of this type
["createTask", {
params ["_previousTask", "_targetLocation"];
// Pickup missions never have a previous task, so we just ignore it
private _taskInstance = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskInstance], // Inherit the base TaskInstance definitions
["taskType", _self], // Task type must always be passed along
["location", _targetLocation]
]
];
diag_log format["Task created: %1", _taskInstance];
_taskInstance;
}],
// Task execution is started, create assets, notify player about task
["onStart", {
// _self is a TaskInstance
diag_log format["Task onStart: %1", _self];
(_self get "cargoType") params ["_cargoClass", "_cargoName"];
private _locationName = (_self get "location") get "name";
private _locationPosition = (_self get "location") get "position";
private _markerText = format["Pick up Squad from %1", _locationName];
// Create Task, only for members of Harpy group
[Harpy, _self get "taskID", ["Pickup squad from the specified location", _markerText], _locationPosition, "AUTOASSIGNED", 1, true, "getin", true] call BIS_fnc_taskCreate;
// Spawn Squad
private _group = createGroup west;
for "_i" from 1 to 8 do {
private _unit = _group createUnit ["B_Soldier_F", _locationPosition, [], 0, "FORM"];
};
_group setFormDir random 360;
_self set ["squadGroup", _group];
// Purple Smoke Handler for Squad
private _smokeHandler = [_self] spawn {
params ["_task"]; // _task: TaskInstance
private _group = _task get "squadGroup";
// Wait until players are close enough to target
waitUntil {
{ _x distance (leader _group) < 1500 } count HARPY_GROUP > 0
};
"SmokeShellPurple" createVehicle getPosATL (leader _group);
//#TODO there could be a while loop here, that waits until cargo is picked up, and repeatedly pops the smoke unless units are already right next to cargo
// It can be a while true loop, this script will get killed when the task is completed
};
_self set ["smokeHandler", _smokeHandler];
// Squad Pickup Handler
[_self] spawn {
params ["_task"]; // _task: TaskInstance
private _group = _task get "squadGroup";
// wait for delivery to be close
waitUntil {
{ _x distance (leader _group) < 50 } count HARPY_GROUP > 0
//#TODO for helicopter, wait for actually landed? not 50m above group?
};
// Tell all units to get in
// For that we first need to find the vehicle that we are supposed to be picked up with
// Find all possible vehicles (All that are driven by harpy group members)
private _possibleVehicles = (HARPY_GROUP apply { objectParent _x }) select {!isNull _x};
// No duplicates
_possibleVehicles = _possibleVehicles arrayIntersect _possibleVehicles;
// Filter vehicles that are close enough (Needs to be a bit larger than the distance we check above, as the player unit is usually infront of the vehicle)
_possibleVehicles = _possibleVehicles select { _x distance (leader _group) < 70 };
private _targetVehicle = _possibleVehicles select 0; //#TODO what do we do if we didn't find one? We should probably loop this with a waitUntil
// Tell units to get into the target vehicle
{ _x assignAsCargo _targetVehicle; [_x] orderGetIn true } forEach units _group;
// Wait for all units to be in vehicle (0 units outside of a vehicle) //#TODO this could be moved into completionCondition?
waitUntil { sleep 1; ({ isNull objectParent _x } count units _group) == 0 };
_task set ["isCompleted", true]; // This will be caught by the completion handler
diag_log format["Task after setting isCompleted to true: %1", _task];
call wolf_tasksystem_fnc_updateActiveTasks; // Trigger global task system update, so player instantly gets notification
};
}],
["completionCondition", {
// _self is a TaskInstance
diag_log format["Checking completion condition for task: %1", _self];
_self getOrDefault ["isCompleted", false] // This is set by ACE event
}],
["onComplete", {
// _self is a TaskInstance
diag_log format["Completing task: %1", _self];
[_self get "taskID", "SUCCEEDED", true] call BIS_fnc_taskSetState;
// Kill the smoke handler if it's still running.
terminate (_self get "smokeHandler");
}]
]
];
_taskPickupSquad call wolf_tasksystem_fnc_registerTaskType;
// This is essentially the same as deliver cargo, but the completion condition is different
//#TODO refactor this so we can inherit from deliver cargo and only change completion condition?
private _taskDeliverSquad = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskType], // Inherit base TaskType definitions
["taskType", "deliverSquad"], // Unique task type
["canBeInitial", false], // Must be a follow-up task
["possibleLocations", [DELIVERY_YANKEE, DELIVERY_JULIET]], // Drop-off locations
// Create a new task instance
["createTask", {
params ["_previousTask", "_targetLocation"];
private _taskInstance = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskInstance], // Inherit base TaskInstance definitions
["taskType", _self], // Store task type reference
["location", _targetLocation],
["previousTask", _previousTask],
["squadGroup", _previousTask get "squadGroup"] // Carry over squad from pickup task
]
];
_taskInstance;
}],
// Task execution starts: create task, set up logic
["onStart", {
private _location = (_self get "location") get "position";
private _locationName = (_self get "location") get "name";
private _markerText = format["Deliver Squad to %1", _locationName];
// Create Task, only for Harpy group
[Harpy, _self get "taskID", ["Transport Squad", _markerText], _location, "AUTOASSIGNED", 1, true, "getout", true] call BIS_fnc_taskCreate;
// Purple Smoke Signal at drop-off
private _smokeHandler = [_self] spawn {
params ["_task"];
private _deliveryLocation = (_task get "location") get "position";
waitUntil { { _x distance _deliveryLocation < 1500 } count HARPY_GROUP > 0 };
"SmokeShellPurple" createVehicle _deliveryLocation;
};
_self set ["smokeHandler", _smokeHandler];
// Unload Squad
[_self] spawn {
params ["_task"];
private _group = _task get "squadGroup";
private _deliveryLocation = (_task get "location") get "position";
// Get the helicopter
private _deliveryVehicle = vehicle leader _group;
// Ensure the helicopter is close to drop-off and landed
waitUntil {
(_deliveryVehicle distance2D _deliveryLocation < 50) &&
(abs ((getPosATL _deliveryVehicle) select 2 - (_deliveryLocation select 2)) < 10) &&
(speed _deliveryVehicle < 2)
};
// Order units to disembark safely
{ unassignVehicle _x; doGetOut _x; } forEach units _group;
// Wait until all soldiers have left the helicopter
waitUntil { ({ !isNull objectParent _x } count (units _group)) == 0 };
_task set ["isCompleted", true]; // ✅ Task completes when soldiers exit
call wolf_tasksystem_fnc_updateActiveTasks;
// Delay squad deletion
[_group] spawn {
params ["_group"];
sleep 120; // Wait 120 seconds before deletion
{ deleteVehicle _x; } forEach units _group;
deleteGroup _group;
};
};
}],
["completionCondition", {
_self getOrDefault ["isCompleted", false] // ✅ Completes when squad exits vehicle
}],
["onComplete", {
[_self get "taskID", "SUCCEEDED", true] call BIS_fnc_taskSetState;
terminate (_self get "smokeHandler"); // Kill smoke signal
}]
]
];
_taskDeliverSquad call wolf_tasksystem_fnc_registerTaskType;
//Spawns a Vehicle from a predefined set of locations
private _taskPickupVehicle = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskType], // Inherit the base TaskType definitions
["taskType", "pickupVehicle"], // Unique name for this task type
["possibleLocations", [SUPPLY_PORT, AIRFIELD]], // Pickup locations
["getContinuationType", { "deliverVehicle" }], // Continuation task
// Function called to create a new task instance
["createTask", {
params ["_previousTask", "_targetLocation"];
// Select a random vehicle type to transport
private _vehicleClass = selectRandom ["B_Pickup_mmg_rf", "B_Pickup_Comms_rf", "B_LSV_01_unarmed_F", "B_LSV_01_armed_F", "B_LSV_01_AT_F", "rhsusf_mrzr4_d"];
private _taskInstance = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskInstance], // Inherit the base TaskInstance definitions
["taskType", _self], // Store the reference to TaskType
["location", _targetLocation],
["vehicleClass", _vehicleClass]
]
];
_taskInstance;
}],
// Task execution starts: spawn the vehicle, create the task, set up logic
["onStart", {
private _location = (_self get "location") get "position";
private _locationName = (_self get "location") get "name";
private _vehicleClass = _self get "vehicleClass";
private _markerText = format["Pick up Vehicle from %1", _locationName];
// Create Task, only for members of Harpy group
[Harpy, _self get "taskID", ["Pick up Vehicle from the specified location", _markerText], _location, "AUTOASSIGNED", 1, true, "container", true] call BIS_fnc_taskCreate;
// Adjust spawn position (1m above ground)
private _spawnPos = [_location select 0, _location select 1, (_location select 2) + 1];
// Now create the vehicle at the adjusted position
private _vehicle = createVehicle [_vehicleClass, _spawnPos, [], 0, "NONE"];
_self set ["vehicle", _vehicle]; // Store vehicle reference
// Wait until a Harpy helicopter is close enough
[_self] spawn {
params ["_task"];
private _vehicle = _task get "vehicle";
waitUntil {
{ _x distance _vehicle < 100 } count HARPY_GROUP > 0
};
};
}],
// Completion condition: Vehicle must be attached to any helicopter or inside cargo
["completionCondition", {
private _vehicle = _self get "vehicle";
!isNull ropeAttachedTo _vehicle || !isNull isVehicleCargo _vehicle
}],
// Task completion: mark as succeeded and store the transporting heli
["onComplete", {
[_self get "taskID", "SUCCEEDED", true] call BIS_fnc_taskSetState;
private _vehicle = _self get "vehicle";
}]
]
];
_taskPickupVehicle call wolf_tasksystem_fnc_registerTaskType;
// Continuation task for delivering a vehicle to a specific location
private _taskDeliverVehicle = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskType], // Inherit the base TaskType definitions
["taskType", "deliverVehicle"], // Unique name for this task type
["canBeInitial", false], // This task can only be started as a continuation
["possibleLocations", [DELIVERY_JULIET, DELIVERY_YANKEE]], // Delivery locations
// Function called to create a new task instance
["createTask", {
params ["_previousTask", "_targetLocation"];
private _taskInstance = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskInstance], // Inherit the base TaskInstance definitions
["taskType", _self], // Store the reference to TaskType
["location", _targetLocation],
["previousTask", _previousTask],
["vehicle", _previousTask get "vehicle"] // Pass along the transported vehicle
]
];
_taskInstance;
}],
// Task execution starts: create the task, set up logic
["onStart", {
private _location = (_self get "location") get "position";
private _locationName = (_self get "location") get "name";
private _vehicle = _self get "vehicle";
private _vehicleClass = _self get "vehicleClass";
private _markerText = format["Deliver Vehicle to %1", _locationName];
// Create Task, only for members of Harpy group
[Harpy, _self get "taskID", ["Deliver Vehicle to the specified location", _markerText], _location, "AUTOASSIGNED", 1, true, "container", true] call BIS_fnc_taskCreate;
}],
// Completion condition: The vehicle must be detached or not inside of vehicle cargo space and within 50m of the target
["completionCondition", {
private _vehicle = _self get "vehicle";
private _targetLocation = (_self get "location") get "position";
private _isAttached = (!isNull ropeAttachedTo _vehicle) || (!isNull isVehicleCargo _vehicle);
private _isInRange = _vehicle distance _targetLocation < 50;
!_isAttached && _isInRange
}],
// Task completion: mark as succeeded
["onComplete", {
[_self get "taskID", "SUCCEEDED", true] call BIS_fnc_taskSetState;
// Get the vehicle reference
private _vehicle = _self get "vehicle";
// Spawn a separate script that deletes the vehicle after 120 seconds
[_vehicle] spawn {
params ["_vehicle"];
sleep 120; // Wait for 120 seconds
if (!isNull _vehicle) then { deleteVehicle _vehicle; };
};
}]
]
];
_taskDeliverVehicle call wolf_tasksystem_fnc_registerTaskType;
//MEDEVAC Pickup Task, almost completely similar to Squad Pickup
private _taskPickupMedevac = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskType], // Inherit base TaskType definitions
["taskType", "pickupMedevac"], // Unique task type name
["possibleLocations", [LZ_GAMMA, LZ_WHISKEY]], // MEDEVAC Locations
["getContinuationType", { "deliverMedevac" }], // Next task in chain
// Create a new task instance
["createTask", {
params ["_previousTask", "_targetLocation"];
private _taskInstance = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskInstance], // Inherit base TaskInstance definitions
["taskType", _self], // Store task type reference
["location", _targetLocation]
]
];
_taskInstance;
}],
// Task execution starts: create wounded soldiers, setup logic
["onStart", {
private _location = (_self get "location") get "position";
private _locationName = (_self get "location") get "name";
private _markerText = format["MEDEVAC: Pick up wounded at %1", _locationName];
// Create Task, only for Harpy group
[Harpy, _self get "taskID", ["Evacuate Wounded Soldiers", _markerText], _location, "AUTOASSIGNED", 1, true, "heal", true] call BIS_fnc_taskCreate;
// List of possible body parts for injuries
private _bodyParts = ["Head", "Body", "LeftArm", "RightArm", "LeftLeg", "RightLeg"];
// List of possible injury types
private _damageTypes = ["bullet", "grenade", "explosive", "stab", "punch", "falling", "ropeburn"];
// Spawn the wounded group (4 soldiers)
private _group = createGroup west;
for "_i" from 1 to 4 do {
private _unit = _group createUnit ["B_Soldier_F", _location, [], 0, "NONE"];
// Apply 3 random injuries per unit
for "_j" from 1 to 3 do {
private _randomBodyPart = selectRandom _bodyParts;
private _randomDamageType = selectRandom _damageTypes;
private _randomSeverity = random [0.2, 0.4, 0.7]; // Mild, medium, or severe injury
[_unit, _randomSeverity, _randomBodyPart, _randomDamageType, objNull, [], true] call ace_medical_fnc_addDamageToUnit;
};
};
_group setFormDir random 360;
_self set ["woundedGroup", _group];
// Purple Smoke Signal
private _smokeHandler = [_self] spawn {
params ["_task"];
private _group = _task get "woundedGroup";
waitUntil { { _x distance (leader _group) < 1500 } count HARPY_GROUP > 0 };
"SmokeShellPurple" createVehicle getPosATL (leader _group);
};
_self set ["smokeHandler", _smokeHandler];
// Boarding Logic
[_self] spawn {
params ["_task"];
private _group = _task get "woundedGroup";
// Wait for helicopter to be close
waitUntil { { _x distance (leader _group) < 50 } count HARPY_GROUP > 0 };
// Find closest helicopter
private _possibleVehicles = (HARPY_GROUP apply { objectParent _x }) select {!isNull _x};
_possibleVehicles = _possibleVehicles arrayIntersect _possibleVehicles;
_possibleVehicles = _possibleVehicles select { _x distance (leader _group) < 70 };
private _targetVehicle = _possibleVehicles select 0;
if (isNil "_targetVehicle") exitWith {}; // No helicopter found, abort
// Order units to board
{ _x assignAsCargo _targetVehicle; [_x] orderGetIn true } forEach units _group;
waitUntil { ({ isNull objectParent _x } count units _group) == 0 };
_task set ["isCompleted", true]; // Task completes
call wolf_tasksystem_fnc_updateActiveTasks;
};
}],
["completionCondition", {
_self getOrDefault ["isCompleted", false] // This is set when all soldiers board the helicopter
}],
["onComplete", {
[_self get "taskID", "SUCCEEDED", true] call BIS_fnc_taskSetState;
terminate (_self get "smokeHandler"); // Kill smoke signal
}]
]
];
_taskPickupMedevac call wolf_tasksystem_fnc_registerTaskType;
private _taskDeliverMedevac = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskType], // Inherit base TaskType definitions
["taskType", "deliverMedevac"], // Unique task type
["canBeInitial", false], // Must be a follow-up task
["possibleLocations", [FIELD_HOSPITAL]], // Drop-off location
// Create a new task instance
["createTask", {
params ["_previousTask", "_targetLocation"];
private _taskInstance = createHashMapObject [
[
["#base", wolf_tasksystem_decl_TaskInstance], // Inherit base TaskInstance definitions
["taskType", _self], // Store task type reference
["location", _targetLocation],
["previousTask", _previousTask],
["woundedGroup", _previousTask get "woundedGroup"] // Carry over the wounded group from pickup task
]
];
_taskInstance;
}],