-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathUniversalAutoload.lua
5851 lines (5202 loc) · 223 KB
/
UniversalAutoload.lua
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
-- ============================================================= --
-- Universal Autoload MOD - SPECIALISATION
-- ============================================================= --
UniversalAutoload = {}
UniversalAutoload.name = g_currentModName
UniversalAutoload.path = g_currentModDirectory
UniversalAutoload.specName = ("spec_%s.universalAutoload"):format(g_currentModName)
UniversalAutoload.showDebug = false
UniversalAutoload.showLoading = false
UniversalAutoload.delayTime = 200
UniversalAutoload.logSpace = 0.25
UniversalAutoload.maxLayerCount = 20
UniversalAutoload.SPLITSHAPES_LOOKUP = {}
UniversalAutoload.ROTATED_BALE_FACTOR = 0.75
--0.85355339
local debugKeys = false
local debugConsole = false
local debugLoading = false
local debugPallets = false
local debugVehicles = false
local debugSpecial = false
-- EVENTS
source(g_currentModDirectory.."events/CycleContainerEvent.lua")
source(g_currentModDirectory.."events/CycleMaterialEvent.lua")
source(g_currentModDirectory.."events/PlayerTriggerEvent.lua")
source(g_currentModDirectory.."events/RaiseActiveEvent.lua")
source(g_currentModDirectory.."events/ResetLoadingEvent.lua")
source(g_currentModDirectory.."events/SetBaleCollectionModeEvent.lua")
source(g_currentModDirectory.."events/SetContainerTypeEvent.lua")
source(g_currentModDirectory.."events/SetFilterEvent.lua")
source(g_currentModDirectory.."events/SetHorizontalLoadingEvent.lua")
source(g_currentModDirectory.."events/SetLoadsideEvent.lua")
source(g_currentModDirectory.."events/SetMaterialTypeEvent.lua")
source(g_currentModDirectory.."events/SetTipsideEvent.lua")
source(g_currentModDirectory.."events/StartLoadingEvent.lua")
source(g_currentModDirectory.."events/StopLoadingEvent.lua")
source(g_currentModDirectory.."events/UnloadingEvent.lua")
source(g_currentModDirectory.."events/UpdateActionEvents.lua")
source(g_currentModDirectory.."events/WarningMessageEvent.lua")
-- REQUIRED SPECIALISATION FUNCTIONS
function UniversalAutoload.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(TensionBelts, specializations)
end
--
function UniversalAutoload.initSpecialization()
g_configurationManager:addConfigurationType("universalAutoload", g_i18n:getText("configuration_universalAutoload"), "universalAutoload", nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
UniversalAutoload.xmlSchema = XMLSchema.new("universalAutoload")
local globalKey = "universalAutoload"
UniversalAutoload.xmlSchema:register(XMLValueType.BOOL, globalKey.."#showDebug", "Show the full graphical debugging display for all vehicles in game", false)
UniversalAutoload.xmlSchema:register(XMLValueType.BOOL, globalKey.."#highPriority", "Apply high priority to all UAL key bindings in the F1 menu", true)
UniversalAutoload.xmlSchema:register(XMLValueType.BOOL, globalKey.."#manualLoadingOnly", "Prevent autoloading (automatic unloading is allowed)", false)
UniversalAutoload.xmlSchema:register(XMLValueType.BOOL, globalKey.."#disableManualLoading", "Prevent use of manual loading triggers", false)
UniversalAutoload.xmlSchema:register(XMLValueType.BOOL, globalKey.."#disableAutoStrap", "Disable the automatic application of tension belts", false)
UniversalAutoload.xmlSchema:register(XMLValueType.FLOAT, globalKey.."#pricePerLog", "The price charged for each auto-loaded log (default is zero)", 0)
UniversalAutoload.xmlSchema:register(XMLValueType.FLOAT, globalKey.."#pricePerBale", "The price charged for each auto-loaded bale (default is zero)", 0)
UniversalAutoload.xmlSchema:register(XMLValueType.FLOAT, globalKey.."#pricePerPallet", "The price charged for each auto-loaded pallet (default is zero)", 0)
UniversalAutoload.xmlSchema:register(XMLValueType.FLOAT, globalKey.."#minLogLength", "The global minimum length for logs that will be autoloaded (default is zero)", 0)
local objectTypesKey = "universalAutoload.objectTypes.objectType(?)"
UniversalAutoload.xmlSchema:register(XMLValueType.STRING, objectTypesKey.."#name", "Custom vehicle types for objects to be loaded by UAL", nil)
local allVehiclesKey = "universalAutoload.vehicleConfigurations"
UniversalAutoload.xmlSchema:register(XMLValueType.BOOL, allVehiclesKey.."#showDebug", "Show the full graphical debugging display for all vehicles in config", false)
local vehicleKey = "universalAutoload.vehicleConfigurations.vehicleConfiguration(?)"
local vehicleSchemas = {
[1] = { ["schema"] = UniversalAutoload.xmlSchema, ["key"] = vehicleKey },
[2] = { ["schema"] = Vehicle.xmlSchema, ["key"] = "vehicle."..vehicleKey }
}
for _, s in ipairs(vehicleSchemas) do
s.schema:register(XMLValueType.STRING, s.key.."#configFileName", "Vehicle config file xml full path - used to identify supported vehicles", nil)
s.schema:register(XMLValueType.STRING, s.key.."#selectedConfigs", "Selected Configuration Names", nil)
s.schema:register(XMLValueType.STRING, s.key.."#useConfigName", "Specific configuration to be used for selected configs", nil)
s.schema:register(XMLValueType.VECTOR_TRANS, s.key..".loadingArea(?)#offset", "Offset to the centre of the loading area", "0 0 0")
s.schema:register(XMLValueType.STRING, s.key..".loadingArea(?)#offsetRoot", "Vehicle i3d node that this area offset is relative to", nil)
s.schema:register(XMLValueType.FLOAT, s.key..".loadingArea(?)#width", "Width of the loading area", 0)
s.schema:register(XMLValueType.FLOAT, s.key..".loadingArea(?)#length", "Length of the loading area", 0)
s.schema:register(XMLValueType.FLOAT, s.key..".loadingArea(?)#height", "Height of the loading area", 0)
s.schema:register(XMLValueType.FLOAT, s.key..".loadingArea(?)#baleHeight", "Height of the loading area for BALES only", nil)
s.schema:register(XMLValueType.STRING, s.key..".loadingArea(?)#widthAxis", "Axis name to extend width of the loading area", nil)
s.schema:register(XMLValueType.STRING, s.key..".loadingArea(?)#lengthAxis", "Axis name to extend length of the loading area", nil)
s.schema:register(XMLValueType.STRING, s.key..".loadingArea(?)#heightAxis", "Axis name to extend height of the loading area", nil)
s.schema:register(XMLValueType.STRING, s.key..".loadingArea(?)#offsetFrontAxis", "Axis name to adjust the front position of the loading area", nil)
s.schema:register(XMLValueType.STRING, s.key..".loadingArea(?)#offsetRearAxis", "Axis name to adjust the rear position of the loading area", nil)
s.schema:register(XMLValueType.BOOL, s.key..".loadingArea(?)#reverseWidthAxis", "Reverses direction of width extension if true", false)
s.schema:register(XMLValueType.BOOL, s.key..".loadingArea(?)#reverseLengthAxis", "Reverses direction of length extension if true", false)
s.schema:register(XMLValueType.BOOL, s.key..".loadingArea(?)#reverseHeightAxis", "Reverses direction of height extension if true", false)
s.schema:register(XMLValueType.BOOL, s.key..".loadingArea(?)#noLoadingIfFolded", "Prevent loading when folded (for this area only)", false)
s.schema:register(XMLValueType.BOOL, s.key..".loadingArea(?)#noLoadingIfUnfolded", "Prevent loading when unfolded (for this area only)", false)
s.schema:register(XMLValueType.BOOL, s.key..".loadingArea(?)#noLoadingIfCovered", "Prevent loading when covered (for this area only)", false)
s.schema:register(XMLValueType.BOOL, s.key..".loadingArea(?)#noLoadingIfUncovered", "Prevent loading when uncovered (for this area only)", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#isBoxTrailer", "If trailer is enclosed with a rear door", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#isLogTrailer", "If trailer is a logging trailer - will load only logs, dropped from above", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#isBaleTrailer", "If trailer should use an automatic bale collection mode", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#isBaleProcessor", "If trailer should consume bales (e.g. TMR Mixer or Straw Blower)", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#isCurtainTrailer", "Automatically detect the available load side (if the trailer has curtain sides)", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#enableRearLoading", "Use the automatic rear loading trigger", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#enableSideLoading", "Use the automatic side loading triggers", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#noLoadingIfFolded", "Prevent loading when folded", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#noLoadingIfUnfolded", "Prevent loading when unfolded", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#noLoadingIfCovered", "Prevent loading when covered", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#noLoadingIfUncovered", "Prevent loading when uncovered", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#rearUnloadingOnly", "Use rear unloading zone only (not side zones)", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#frontUnloadingOnly", "Use front unloading zone only (not side zones)", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#horizontalLoading", "Start with horizontal loading enabled (can be toggled if key is bound)", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#disableAutoStrap", "Disable the automatic application of tension belts", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#disableHeightLimit", "Disable the density based stacking height limit", false)
s.schema:register(XMLValueType.BOOL, s.key..".options#zonesOverlap", "Flag to identify when the loading areas overlap each other", false)
s.schema:register(XMLValueType.STRING, s.key..".options#offsetRoot", "Vehicle i3d node that area offsets are relative to", nil)
s.schema:register(XMLValueType.FLOAT, s.key..".options#minLogLength", "The minimum length for logs that will be autoloaded (default is zero)", 0)
s.schema:register(XMLValueType.BOOL, s.key..".options#showDebug", "Show the full graphical debugging display for this vehicle", false)
end
local containerKey = "universalAutoload.containerConfigurations.containerConfiguration(?)"
local legacyContainerKey = "universalAutoload.containerTypeConfigurations.containerConfiguration(?)"
local containerSchemas = {
[1] = { ["schema"] = UniversalAutoload.xmlSchema, ["key"] = containerKey },
[2] = { ["schema"] = UniversalAutoload.xmlSchema, ["key"] = legacyContainerKey }
}
for _, s in ipairs(containerSchemas) do
s.schema:register(XMLValueType.STRING, s.key.."#containerType", "The loading type category to group under in the menu)", "ANY")
s.schema:register(XMLValueType.STRING, s.key.."#name", "Simplified Pallet Configuration Filename", "UNKNOWN")
s.schema:register(XMLValueType.FLOAT, s.key.."#sizeX", "Width of the pallet", 1.5)
s.schema:register(XMLValueType.FLOAT, s.key.."#sizeY", "Height of the pallet", 2.0)
s.schema:register(XMLValueType.FLOAT, s.key.."#sizeZ", "Length of the pallet", 1.5)
s.schema:register(XMLValueType.BOOL, s.key.."#isBale", "If the object is either a round bale or square bale", false)
s.schema:register(XMLValueType.BOOL, s.key.."#flipYZ", "Should always rotate 90 degrees to stack on end - e.g. for round bales", false)
s.schema:register(XMLValueType.BOOL, s.key.."#neverStack", "Should never load another pallet on top of this one when loading", false)
s.schema:register(XMLValueType.BOOL, s.key.."#neverRotate", "Should never rotate object when loading", false)
s.schema:register(XMLValueType.BOOL, s.key.."#alwaysRotate", "Should always rotate to face outwards for manual unloading", false)
s.schema:register(XMLValueType.FLOAT, s.key.."#frontOffset", "Offset from the front of trailer (only when loaded first)", 0)
end
local schemaSavegame = Vehicle.xmlSchemaSavegame
local specKey = "vehicles.vehicle(?).universalAutoload"
schemaSavegame:register(XMLValueType.STRING, specKey.."#tipside", "Last used tip side", "none")
schemaSavegame:register(XMLValueType.STRING, specKey.."#loadside", "Last used load side", "both")
schemaSavegame:register(XMLValueType.FLOAT, specKey.."#loadWidth", "Last used load width", 0)
schemaSavegame:register(XMLValueType.FLOAT, specKey.."#loadLength", "Last used load length", 0)
schemaSavegame:register(XMLValueType.FLOAT, specKey.."#loadHeight", "Last used load height", 0)
schemaSavegame:register(XMLValueType.FLOAT, specKey.."#actualWidth", "Last used expected load width", 0)
schemaSavegame:register(XMLValueType.FLOAT, specKey.."#actualLength", "Last used complete load length", 0)
schemaSavegame:register(XMLValueType.FLOAT, specKey.."#layerCount", "Number of layers that are currently loaded", 0)
schemaSavegame:register(XMLValueType.FLOAT, specKey.."#layerHeight", "Total height of the currently loaded layers", 0)
schemaSavegame:register(XMLValueType.FLOAT, specKey.."#nextLayerHeight", "Height for the next layer (highest point in previous layer)", 0)
--schemaSavegame:register(XMLValueType.INT, specKey.."#layerCount", "Number of layers that are currently loaded", 0)
schemaSavegame:register(XMLValueType.INT, specKey.."#loadAreaIndex", "Last used load area", 1)
schemaSavegame:register(XMLValueType.INT, specKey.."#materialIndex", "Last used material type", 1)
schemaSavegame:register(XMLValueType.INT, specKey.."#containerIndex", "Last used container type", 1)
schemaSavegame:register(XMLValueType.BOOL, specKey.."#loadingFilter", "TRUE=Load full pallets only; FALSE=Load any pallets", false)
schemaSavegame:register(XMLValueType.BOOL, specKey.."#useHorizontalLoading", "Last used horizontal loading state", false)
schemaSavegame:register(XMLValueType.BOOL, specKey.."#baleCollectionMode", "Enable manual toggling of the automatic bale collection mode", false)
end
--
function UniversalAutoload.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, "ualGetIsMoving", UniversalAutoload.ualGetIsMoving)
SpecializationUtil.registerFunction(vehicleType, "ualGetIsFilled", UniversalAutoload.ualGetIsFilled)
SpecializationUtil.registerFunction(vehicleType, "ualGetIsCovered", UniversalAutoload.ualGetIsCovered)
SpecializationUtil.registerFunction(vehicleType, "ualGetIsFolding", UniversalAutoload.ualGetIsFolding)
SpecializationUtil.registerFunction(vehicleType, "ualOnDeleteLoadedObject_Callback", UniversalAutoload.ualOnDeleteLoadedObject_Callback)
SpecializationUtil.registerFunction(vehicleType, "ualOnDeleteAvailableObject_Callback", UniversalAutoload.ualOnDeleteAvailableObject_Callback)
SpecializationUtil.registerFunction(vehicleType, "ualOnDeleteAutoLoadingObject_Callback", UniversalAutoload.ualOnDeleteAutoLoadingObject_Callback)
SpecializationUtil.registerFunction(vehicleType, "ualTestLocation_Callback", UniversalAutoload.ualTestLocation_Callback)
SpecializationUtil.registerFunction(vehicleType, "ualTestUnloadLocation_Callback", UniversalAutoload.ualTestUnloadLocation_Callback)
SpecializationUtil.registerFunction(vehicleType, "ualTestLocationOverlap_Callback", UniversalAutoload.ualTestLocationOverlap_Callback)
SpecializationUtil.registerFunction(vehicleType, "ualPlayerTrigger_Callback", UniversalAutoload.ualPlayerTrigger_Callback)
SpecializationUtil.registerFunction(vehicleType, "ualLoadingTrigger_Callback", UniversalAutoload.ualLoadingTrigger_Callback)
SpecializationUtil.registerFunction(vehicleType, "ualUnloadingTrigger_Callback", UniversalAutoload.ualUnloadingTrigger_Callback)
SpecializationUtil.registerFunction(vehicleType, "ualAutoLoadingTrigger_Callback", UniversalAutoload.ualAutoLoadingTrigger_Callback)
--- Courseplay functions
SpecializationUtil.registerFunction(vehicleType, "ualHasLoadedBales", UniversalAutoload.ualHasLoadedBales)
SpecializationUtil.registerFunction(vehicleType, "ualIsFull", UniversalAutoload.ualIsFull)
SpecializationUtil.registerFunction(vehicleType, "ualGetLoadedBales", UniversalAutoload.ualGetLoadedBales)
SpecializationUtil.registerFunction(vehicleType, "ualIsObjectLoadable", UniversalAutoload.ualIsObjectLoadable)
--- Autodrive functions
SpecializationUtil.registerFunction(vehicleType, "ualStartLoad", UniversalAutoload.ualStartLoad)
SpecializationUtil.registerFunction(vehicleType, "ualStopLoad", UniversalAutoload.ualStopLoad)
SpecializationUtil.registerFunction(vehicleType, "ualUnload", UniversalAutoload.ualUnload)
SpecializationUtil.registerFunction(vehicleType, "ualSetUnloadPosition", UniversalAutoload.ualSetUnloadPosition)
SpecializationUtil.registerFunction(vehicleType, "ualGetFillUnitCapacity", UniversalAutoload.ualGetFillUnitCapacity)
SpecializationUtil.registerFunction(vehicleType, "ualGetFillUnitFillLevel", UniversalAutoload.ualGetFillUnitFillLevel)
SpecializationUtil.registerFunction(vehicleType, "ualGetFillUnitFreeCapacity", UniversalAutoload.ualGetFillUnitFreeCapacity)
end
--
function UniversalAutoload.registerOverwrittenFunctions(vehicleType)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanStartFieldWork", UniversalAutoload.getCanStartFieldWork)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "getCanImplementBeUsedForAI", UniversalAutoload.getCanImplementBeUsedForAI)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDynamicMountTimeToMount", UniversalAutoload.getDynamicMountTimeToMount)
end
function UniversalAutoload:getCanStartFieldWork(superFunc)
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.baleCollectionMode then
if debugSpecial then print("getCanStartFieldWork...") end
--return true
end
return superFunc(self)
end
function UniversalAutoload:getCanImplementBeUsedForAI(superFunc)
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled then
if debugSpecial then print("*** getCanImplementBeUsedForAI ***") end
--DebugUtil.printTableRecursively(self.spec_aiImplement, "--", 0, 1)
--return true
end
return superFunc(self)
end
--
function UniversalAutoload.registerEventListeners(vehicleType)
SpecializationUtil.registerEventListener(vehicleType, "onLoad", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onReadStream", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onDelete", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onPreDelete", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onUpdate", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onActivate", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onDeactivate", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onFoldStateChanged", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onMovingToolChanged", UniversalAutoload)
--- Courseplay event listeners.
SpecializationUtil.registerEventListener(vehicleType, "onAIImplementStart", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onAIImplementEnd", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onAIFieldWorkerStart", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onAIFieldWorkerEnd", UniversalAutoload)
end
function UniversalAutoload.removeEventListeners(vehicleType)
-- print("REMOVE EVENT LISTENERS")
-- *** full credit to GtX for this function ***
local function removeUnusedEventListener(vehicle, name, specClass)
local eventListeners = vehicle.eventListeners[name]
if eventListeners ~= nil then
for i = #eventListeners, 1, -1 do
if specClass.className ~= nil and specClass.className == eventListeners[i].className then
table.remove(eventListeners, i)
end
end
end
end
-- (called during 'onLoad' so do not unregister that)
removeUnusedEventListener(vehicleType, "onPostLoad", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onRegisterActionEvents", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onDelete", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onPreDelete", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onUpdate", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onActivate", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onDeactivate", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onFoldStateChanged", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onMovingToolChanged", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onAIImplementStart", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onAIImplementEnd", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onAIFieldWorkerStart", UniversalAutoload)
removeUnusedEventListener(vehicleType, "onAIFieldWorkerEnd", UniversalAutoload)
end
-- HOOK PLAYER ON FOOT UPDATE OBJECTS/TRIGGERS
UniversalAutoload.lastClosestVehicle = nil
function UniversalAutoload:OverwrittenUpdateObjects(superFunc, ...)
superFunc(self, ...)
if self.mission.player.isControlled and not g_gui:getIsGuiVisible() then
-- print("Player Is Controlled")
local player = self.mission.player
local playerId = player.userId
local closestVehicle = nil
local closestVehicleDistance = 25 --math.huge
for _, vehicle in pairs(UniversalAutoload.VEHICLES) do
if vehicle ~= nil then
local SPEC = vehicle.spec_universalAutoload
if SPEC.playerInTrigger~=nil and SPEC.playerInTrigger[playerId] == true and
g_currentMission.nodeToObject[vehicle.rootNode]~=nil then
local distance = calcDistanceFrom(player.rootNode, vehicle.rootNode)
if distance < closestVehicleDistance then
closestVehicle = vehicle
closestVehicleDistance = distance
end
end
end
end
if UniversalAutoload.lastClosestVehicle ~= closestVehicle then
local lastVehicle = UniversalAutoload.lastClosestVehicle
if lastVehicle ~= nil then
UniversalAutoload.clearActionEvents(lastVehicle)
UniversalAutoload.forceRaiseActive(lastVehicle)
end
UniversalAutoload.lastClosestVehicle = closestVehicle
if closestVehicle ~= nil then
closestVehicle.spec_universalAutoload.updateKeys = true
end
end
if UniversalAutoload.lastClosestVehicle ~= nil then
UniversalAutoload.forceRaiseActive(UniversalAutoload.lastClosestVehicle)
end
if UniversalAutoload.lastClosestVehicle ~= nil then
UniversalAutoload.printHelpText(UniversalAutoload.lastClosestVehicle)
end
end
end
ActivatableObjectsSystem.updateObjects = Utils.overwrittenFunction(ActivatableObjectsSystem.updateObjects, UniversalAutoload.OverwrittenUpdateObjects)
-- ACTION EVENT FUNCTIONS
function UniversalAutoload:clearActionEvents()
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.actionEvents~=nil then
self:clearActionEventsTable(spec.actionEvents)
end
end
--
function UniversalAutoload:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection)
if self.isClient and g_dedicatedServer==nil then
local spec = self.spec_universalAutoload
UniversalAutoload.clearActionEvents(self)
if isActiveForInput then
-- print("onRegisterActionEvents: "..self:getFullName())
UniversalAutoload.updateActionEventKeys(self)
end
end
end
--
function UniversalAutoload:updateActionEventKeys()
if self.isClient and g_dedicatedServer==nil then
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.actionEvents ~= nil and next(spec.actionEvents) == nil then
if debugKeys then print("updateActionEventKeys: "..self:getFullName()) end
local actions = UniversalAutoload.ACTIONS
local ignoreCollisions = true
local topPriority = GS_PRIO_HIGH
local midPriority = GS_PRIO_NORMAL
local lowPriority = GS_PRIO_LOW
if UniversalAutoload.highPriority == true then
topPriority = GS_PRIO_VERY_HIGH
midPriority = GS_PRIO_HIGH
lowPriority = GS_PRIO_NORMAL
end
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.UNLOAD_ALL, self, UniversalAutoload.actionEventUnloadAll, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, topPriority)
spec.unloadAllActionEventId = actionEventId
if debugKeys then print(" UNLOAD_ALL: "..tostring(valid)) end
spec.updateToggleLoading = true
if not UniversalAutoload.manualLoadingOnly then
if spec.isBaleTrailer then
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_BALE_COLLECTION, self, UniversalAutoload.actionEventToggleBaleCollectionMode, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, topPriority)
spec.toggleBaleCollectionModeEventId = actionEventId
if debugKeys then print(" TOGGLE_BALE_COLLECTION: "..tostring(valid)) end
end
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_LOADING, self, UniversalAutoload.actionEventToggleLoading, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, topPriority)
spec.toggleLoadingActionEventId = actionEventId
if debugKeys then print(" TOGGLE_LOADING: "..tostring(valid)) end
if not spec.isLogTrailer then
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_FILTER, self, UniversalAutoload.actionEventToggleFilter, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
spec.toggleLoadingFilterActionEventId = actionEventId
if debugKeys then print(" TOGGLE_FILTER: "..tostring(valid)) end
spec.updateToggleFilter = true
end
end
if not spec.isLogTrailer then
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_HORIZONTAL, self, UniversalAutoload.actionEventToggleHorizontalLoading, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
spec.toggleHorizontalLoadingActionEventId = actionEventId
if debugKeys then print(" TOGGLE_HORIZONTAL: "..tostring(valid)) end
spec.updateHorizontalLoading = true
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.CYCLE_MATERIAL_FW, self, UniversalAutoload.actionEventCycleMaterial_FW, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
spec.cycleMaterialActionEventId = actionEventId
if debugKeys then print(" CYCLE_MATERIAL_FW: "..tostring(valid)) end
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.CYCLE_MATERIAL_BW, self, UniversalAutoload.actionEventCycleMaterial_BW, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, lowPriority)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
if debugKeys then print(" CYCLE_MATERIAL_BW: "..tostring(valid)) end
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.SELECT_ALL_MATERIALS, self, UniversalAutoload.actionEventSelectAllMaterials, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
if debugKeys then print(" SELECT_ALL_MATERIALS: "..tostring(valid)) end
spec.updateCycleMaterial = true
if UniversalAutoload.chatKeyConflict ~= true then
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.CYCLE_CONTAINER_FW, self, UniversalAutoload.actionEventCycleContainer_FW, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
spec.cycleContainerActionEventId = actionEventId
if debugKeys then print(" CYCLE_CONTAINER_FW: "..tostring(valid)) end
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.CYCLE_CONTAINER_BW, self, UniversalAutoload.actionEventCycleContainer_BW, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, lowPriority)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
if debugKeys then print(" CYCLE_CONTAINER_BW: "..tostring(valid)) end
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.SELECT_ALL_CONTAINERS, self, UniversalAutoload.actionEventSelectAllContainers, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
if debugKeys then print(" SELECT_ALL_CONTAINERS: "..tostring(valid)) end
spec.updateCycleContainer = true
end
end
if not spec.isCurtainTrailer and not spec.rearUnloadingOnly and not spec.frontUnloadingOnly then
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_TIPSIDE, self, UniversalAutoload.actionEventToggleTipside, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
spec.toggleTipsideActionEventId = actionEventId
if debugKeys then print(" TOGGLE_TIPSIDE: "..tostring(valid)) end
spec.updateToggleTipside = true
end
if g_currentMission.player.isControlled then
if not g_currentMission.missionDynamicInfo.isMultiplayer and self.spec_tensionBelts then
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_BELTS, self, UniversalAutoload.actionEventToggleBelts, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
spec.toggleBeltsActionEventId = actionEventId
if debugKeys then print(" TOGGLE_BELTS: "..tostring(valid)) end
spec.updateToggleBelts = true
end
if spec.isCurtainTrailer or spec.isBoxTrailer then
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_DOOR, self, UniversalAutoload.actionEventToggleDoor, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
spec.toggleDoorActionEventId = actionEventId
if debugKeys then print(" TOGGLE_DOOR: "..tostring(valid)) end
spec.updateToggleDoor = true
end
if spec.isCurtainTrailer then
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_CURTAIN, self, UniversalAutoload.actionEventToggleCurtain, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, midPriority)
spec.toggleCurtainActionEventId = actionEventId
if debugKeys then print(" TOGGLE_CURTAIN: "..tostring(valid)) end
spec.updateToggleCurtain = true
end
end
if self.isServer then
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_SHOW_LOADING, self, UniversalAutoload.actionEventToggleShowLoading, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, lowPriority)
-- spec.ToggleShowLoadingActionEventId = actionEventId
if debugKeys then print(" TOGGLE_SHOW_LOADING: "..tostring(valid)) end
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions.TOGGLE_SHOW_DEBUG, self, UniversalAutoload.actionEventToggleShowDebug, false, true, false, true, nil, nil, ignoreCollisions, true)
g_inputBinding:setActionEventTextPriority(actionEventId, lowPriority)
-- spec.ToggleShowLoadingActionEventId = actionEventId
if debugKeys then print(" TOGGLE_SHOW_DEBUG: "..tostring(valid)) end
end
if debugKeys then print("*** updateActionEventKeys ***") end
end
end
end
--
function UniversalAutoload:updateToggleBeltsActionEvent()
--if debugKeys then print("updateToggleBeltsActionEvent") end
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.toggleBeltsActionEventId ~= nil then
g_inputBinding:setActionEventActive(spec.toggleBeltsActionEventId, true)
local tensionBeltsText
if self.spec_tensionBelts.areBeltsFasten then
tensionBeltsText = g_i18n:getText("action_unfastenTensionBelts")
else
tensionBeltsText = g_i18n:getText("action_fastenTensionBelts")
end
g_inputBinding:setActionEventText(spec.toggleBeltsActionEventId, tensionBeltsText)
g_inputBinding:setActionEventTextVisibility(spec.toggleBeltsActionEventId, true)
end
end
--
function UniversalAutoload:updateToggleDoorActionEvent()
--if debugKeys then print("updateToggleDoorActionEvent") end
local spec = self.spec_universalAutoload
local foldable = self.spec_foldable
if g_currentMission.player.isControlled then
if spec~=nil and spec.isAutoloadEnabled and self.spec_foldable and (spec.isCurtainTrailer or spec.isBoxTrailer) then
local direction = self:getToggledFoldDirection()
local toggleDoorText = ""
if direction == foldable.turnOnFoldDirection then
toggleDoorText = foldable.negDirectionText
else
toggleDoorText = foldable.posDirectionText
end
g_inputBinding:setActionEventText(spec.toggleDoorActionEventId, toggleDoorText)
g_inputBinding:setActionEventTextVisibility(spec.toggleDoorActionEventId, true)
end
else
if spec~=nil and spec.isAutoloadEnabled and self.spec_foldable and self.isClient then
Foldable.updateActionEventFold(self)
end
end
end
--
function UniversalAutoload:updateToggleCurtainActionEvent()
--if debugKeys then print("updateToggleCurtainActionEvent") end
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and g_currentMission.player.isControlled then
if self.spec_trailer and spec.isCurtainTrailer then
local trailer = self.spec_trailer
local tipSide = trailer.tipSides[trailer.preferedTipSideIndex]
if tipSide ~= nil then
local toggleCurtainText = nil
local tipState = self:getTipState()
if tipState == Trailer.TIPSTATE_CLOSED or tipState == Trailer.TIPSTATE_CLOSING then
toggleCurtainText = tipSide.manualTipToggleActionTextPos
else
toggleCurtainText = tipSide.manualTipToggleActionTextNeg
end
g_inputBinding:setActionEventText(spec.toggleCurtainActionEventId, toggleCurtainText)
g_inputBinding:setActionEventTextVisibility(spec.toggleCurtainActionEventId, true)
end
end
end
end
--
function UniversalAutoload:updateCycleMaterialActionEvent()
--if debugKeys then print("updateCycleMaterialActionEvent") end
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.cycleMaterialActionEventId ~= nil then
-- Material Type: ALL / <MATERIAL>
if not spec.isLoading then
local materialTypeText = g_i18n:getText("universalAutoload_materialType")..": "..UniversalAutoload.getSelectedMaterialText(self)
g_inputBinding:setActionEventText(spec.cycleMaterialActionEventId, materialTypeText)
g_inputBinding:setActionEventTextVisibility(spec.cycleMaterialActionEventId, true)
end
end
end
--
function UniversalAutoload:updateCycleContainerActionEvent()
--if debugKeys then print("updateCycleContainerActionEvent") end
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.cycleContainerActionEventId ~= nil then
-- Container Type: ALL / <PALLET_TYPE>
if not spec.isLoading then
local containerTypeText = g_i18n:getText("universalAutoload_containerType")..": "..UniversalAutoload.getSelectedContainerText(self)
g_inputBinding:setActionEventText(spec.cycleContainerActionEventId, containerTypeText)
g_inputBinding:setActionEventTextVisibility(spec.cycleContainerActionEventId, true)
end
end
end
--
function UniversalAutoload:updateToggleFilterActionEvent()
--if debugKeys then print("updateToggleFilterActionEvent") end
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.toggleLoadingFilterActionEventId ~= nil then
-- Loading Filter: ANY / FULL ONLY
local loadingFilterText
if spec.currentLoadingFilter then
loadingFilterText = g_i18n:getText("universalAutoload_loadingFilter")..": "..g_i18n:getText("universalAutoload_fullOnly")
else
loadingFilterText = g_i18n:getText("universalAutoload_loadingFilter")..": "..g_i18n:getText("universalAutoload_loadAny")
end
g_inputBinding:setActionEventText(spec.toggleLoadingFilterActionEventId, loadingFilterText)
g_inputBinding:setActionEventTextVisibility(spec.toggleLoadingFilterActionEventId, true)
end
end
--
function UniversalAutoload:updateHorizontalLoadingActionEvent()
--if debugKeys then print("updateHorizontalLoadingActionEvent") end
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.toggleHorizontalLoadingActionEventId ~= nil then
-- Loading Filter: ANY / FULL ONLY
local horizontalLoadingText
if spec.useHorizontalLoading then
horizontalLoadingText = g_i18n:getText("universalAutoload_loadingMethod")..": "..g_i18n:getText("universalAutoload_layer")
else
horizontalLoadingText = g_i18n:getText("universalAutoload_loadingMethod")..": "..g_i18n:getText("universalAutoload_stack")
end
g_inputBinding:setActionEventText(spec.toggleHorizontalLoadingActionEventId, horizontalLoadingText)
g_inputBinding:setActionEventTextVisibility(spec.toggleHorizontalLoadingActionEventId, true)
end
end
--
function UniversalAutoload:updateToggleTipsideActionEvent()
--if debugKeys then print("updateToggleTipsideActionEvent") end
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.toggleTipsideActionEventId ~= nil then
-- Tipside: NONE/BOTH/LEFT/RIGHT/
if spec.currentTipside == "none" then
g_inputBinding:setActionEventActive(spec.toggleTipsideActionEventId, false)
else
local tipsideText = g_i18n:getText("universalAutoload_tipside")..": "..g_i18n:getText("universalAutoload_"..(spec.currentTipside or "none"))
g_inputBinding:setActionEventText(spec.toggleTipsideActionEventId, tipsideText)
g_inputBinding:setActionEventTextVisibility(spec.toggleTipsideActionEventId, true)
end
end
end
--
function UniversalAutoload:updateToggleLoadingActionEvent()
--if debugKeys then print("updateToggleLoadingActionEvent") end
local spec = self.spec_universalAutoload
if spec~=nil and spec.isAutoloadEnabled and spec.toggleBaleCollectionModeEventId ~= nil then
-- Activate/Deactivate the AUTO-BALE key binding
if spec.baleCollectionMode==true or spec.validUnloadCount==0 then
local baleCollectionModeText
if spec.baleCollectionMode then
baleCollectionModeText = g_i18n:getText("universalAutoload_baleMode")..": "..g_i18n:getText("universalAutoload_enabled")
else
baleCollectionModeText = g_i18n:getText("universalAutoload_baleMode")..": "..g_i18n:getText("universalAutoload_disabled")
end
g_inputBinding:setActionEventText(spec.toggleBaleCollectionModeEventId, baleCollectionModeText)
g_inputBinding:setActionEventTextVisibility(spec.toggleBaleCollectionModeEventId, true)
if debugKeys then print(" >> " .. baleCollectionModeText) end
else
g_inputBinding:setActionEventActive(spec.toggleBaleCollectionModeEventId, false)
end
end
if spec~=nil and spec.isAutoloadEnabled and spec.toggleLoadingActionEventId ~= nil then
-- Activate/Deactivate the LOAD key binding
if spec.isLoading and not self.baleCollectionMode==true then
local stopLoadingText = g_i18n:getText("universalAutoload_stopLoading")
g_inputBinding:setActionEventText(spec.toggleLoadingActionEventId, stopLoadingText)
if debugKeys then print(" >> " .. stopLoadingText) end
else
if UniversalAutoload.getIsLoadingKeyAllowed(self) then
local startLoadingText = g_i18n:getText("universalAutoload_startLoading")
if debugLoading then startLoadingText = startLoadingText.." ("..tostring(spec.validLoadCount)..")" end
g_inputBinding:setActionEventText(spec.toggleLoadingActionEventId, startLoadingText)
g_inputBinding:setActionEventActive(spec.toggleLoadingActionEventId, true)
g_inputBinding:setActionEventTextVisibility(spec.toggleLoadingActionEventId, true)
if debugKeys then print(" >> " .. startLoadingText) end
else
g_inputBinding:setActionEventActive(spec.toggleLoadingActionEventId, false)
end
end
end
if spec~=nil and spec.isAutoloadEnabled and spec.unloadAllActionEventId ~= nil then
-- Activate/Deactivate the UNLOAD key binding
if UniversalAutoload.getIsUnloadingKeyAllowed(self) then
local unloadText = g_i18n:getText("universalAutoload_unloadAll")
if debugLoading then unloadText = unloadText.." ("..tostring(spec.validUnloadCount)..")" end
g_inputBinding:setActionEventText(spec.unloadAllActionEventId, unloadText)
g_inputBinding:setActionEventActive(spec.unloadAllActionEventId, true)
g_inputBinding:setActionEventTextVisibility(spec.unloadAllActionEventId, true)
if debugKeys then print(" >> " .. unloadText) end
else
g_inputBinding:setActionEventActive(spec.unloadAllActionEventId, false)
end
end
end
-- ACTION EVENTS
function UniversalAutoload.actionEventToggleBelts(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleBelts: "..self:getFullName())
local spec = self.spec_universalAutoload
if self.spec_tensionBelts.areBeltsFasten then
self:setAllTensionBeltsActive(false)
else
self:setAllTensionBeltsActive(true)
end
spec.updateToggleBelts = true
end
--
function UniversalAutoload.actionEventToggleDoor(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleDoor: "..self:getFullName())
local spec = self.spec_universalAutoload
local foldable = self.spec_foldable
if #foldable.foldingParts > 0 then
local toggleDirection = self:getToggledFoldDirection()
if toggleDirection == foldable.turnOnFoldDirection then
self:setFoldState(toggleDirection, true)
else
self:setFoldState(toggleDirection, false)
end
end
spec.updateToggleDoor = true
end
--
function UniversalAutoload.actionEventToggleCurtain(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleCurtain: "..self:getFullName())
local spec = self.spec_universalAutoload
local tipState = self:getTipState()
if tipState == Trailer.TIPSTATE_CLOSED or tipState == Trailer.TIPSTATE_CLOSING then
self:startTipping(nil, false)
TrailerToggleManualTipEvent.sendEvent(self, true)
else
self:stopTipping()
TrailerToggleManualTipEvent.sendEvent(self, false)
end
spec.updateToggleCurtain = true
end
--
function UniversalAutoload.actionEventToggleShowDebug(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleShowDebug: "..self:getFullName())
local spec = self.spec_universalAutoload
if self.isServer then
UniversalAutoload.showDebug = not UniversalAutoload.showDebug
end
end
--
function UniversalAutoload.actionEventToggleShowLoading(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleShowLoading: "..self:getFullName())
local spec = self.spec_universalAutoload
if self.isServer then
UniversalAutoload.showLoading = not UniversalAutoload.showLoading
end
end
--
function UniversalAutoload.actionEventToggleBaleCollectionMode(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleBaleCollectionMode: "..self:getFullName())
local spec = self.spec_universalAutoload
UniversalAutoload.setBaleCollectionMode(self, not spec.baleCollectionMode)
end
--
function UniversalAutoload.actionEventCycleMaterial_FW(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventCycleMaterial_FW: "..self:getFullName())
UniversalAutoload.cycleMaterialTypeIndex(self, 1)
end
--
function UniversalAutoload.actionEventCycleMaterial_BW(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventCycleMaterial_BW: "..self:getFullName())
UniversalAutoload.cycleMaterialTypeIndex(self, -1)
end
--
function UniversalAutoload.actionEventSelectAllMaterials(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventSelectAllMaterials: "..self:getFullName())
UniversalAutoload.setMaterialTypeIndex(self, 1)
end
--
function UniversalAutoload.actionEventCycleContainer_FW(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventCycleContainer_FW: "..self:getFullName())
UniversalAutoload.cycleContainerTypeIndex(self, 1)
end
--
function UniversalAutoload.actionEventCycleContainer_BW(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventCycleContainer_BW: "..self:getFullName())
UniversalAutoload.cycleContainerTypeIndex(self, -1)
end
--
function UniversalAutoload.actionEventSelectAllContainers(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventSelectAllContainers: "..self:getFullName())
UniversalAutoload.setContainerTypeIndex(self, 1)
end
--
function UniversalAutoload.actionEventToggleFilter(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleFilter: "..self:getFullName())
local spec = self.spec_universalAutoload
local state = not spec.currentLoadingFilter
UniversalAutoload.setLoadingFilter(self, state)
end
--
function UniversalAutoload.actionEventToggleHorizontalLoading(self, actionName, inputValue, callbackState, isAnalog)
--print("actionEventToggleHorizontalLoading: "..self:getFullName())
local spec = self.spec_universalAutoload
local state = not spec.useHorizontalLoading
UniversalAutoload.setHorizontalLoading(self, state)
end
--
function UniversalAutoload.actionEventToggleTipside(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleTipside: "..self:getFullName())
local spec = self.spec_universalAutoload
local tipside
if spec.currentTipside == "left" then
tipside = "right"
else
tipside = "left"
end
UniversalAutoload.setCurrentTipside(self, tipside)
end
--
function UniversalAutoload.actionEventToggleLoading(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleLoading: "..self:getFullName())
local spec = self.spec_universalAutoload
if not spec.isLoading then
UniversalAutoload.startLoading(self)
else
UniversalAutoload.stopLoading(self)
end
end
--
function UniversalAutoload.actionEventUnloadAll(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventUnloadAll: "..self:getFullName())
UniversalAutoload.startUnloading(self)
end
-- EVENT FUNCTIONS
function UniversalAutoload:cycleMaterialTypeIndex(direction, noEventSend)
local spec = self.spec_universalAutoload
if self.isServer then
local materialIndex
if direction == 1 then
materialIndex = 999
for _, object in pairs(spec.availableObjects) do
local objectMaterialName = UniversalAutoload.getMaterialTypeName(object)
local objectMaterialIndex = UniversalAutoload.MATERIALS_INDEX[objectMaterialName] or 1
if objectMaterialIndex > spec.currentMaterialIndex and objectMaterialIndex < materialIndex then
materialIndex = objectMaterialIndex
end
end
for _, object in pairs(spec.loadedObjects) do
local objectMaterialName = UniversalAutoload.getMaterialTypeName(object)
local objectMaterialIndex = UniversalAutoload.MATERIALS_INDEX[objectMaterialName] or 1
if objectMaterialIndex > spec.currentMaterialIndex and objectMaterialIndex < materialIndex then
materialIndex = objectMaterialIndex
end
end
else
materialIndex = 0
local startingValue = (spec.currentMaterialIndex==1) and #UniversalAutoload.MATERIALS+1 or spec.currentMaterialIndex
for _, object in pairs(spec.availableObjects) do
local objectMaterialName = UniversalAutoload.getMaterialTypeName(object)
local objectMaterialIndex = UniversalAutoload.MATERIALS_INDEX[objectMaterialName] or 1
if objectMaterialIndex < startingValue and objectMaterialIndex > materialIndex then
materialIndex = objectMaterialIndex
end
end
for _, object in pairs(spec.loadedObjects) do
local objectMaterialName = UniversalAutoload.getMaterialTypeName(object)
local objectMaterialIndex = UniversalAutoload.MATERIALS_INDEX[objectMaterialName] or 1
if objectMaterialIndex < startingValue and objectMaterialIndex > materialIndex then
materialIndex = objectMaterialIndex
end
end
end
if materialIndex == nil or materialIndex == 0 or materialIndex == 999 then
materialIndex = 1
end
UniversalAutoload.setMaterialTypeIndex(self, materialIndex)
if materialIndex==1 and spec.totalAvailableCount==0 and spec.totalUnloadCount==0 then
-- NO_OBJECTS_FOUND
UniversalAutoload.showWarningMessage(self, 2)
end
end
UniversalAutoloadCycleMaterialEvent.sendEvent(self, direction, noEventSend)
end
--
function UniversalAutoload:setMaterialTypeIndex(typeIndex, noEventSend)
-- print("setMaterialTypeIndex: "..self:getFullName().." "..tostring(typeIndex))
local spec = self.spec_universalAutoload
spec.currentMaterialIndex = math.min(math.max(typeIndex, 1), table.getn(UniversalAutoload.MATERIALS))
UniversalAutoloadSetMaterialTypeEvent.sendEvent(self, typeIndex, noEventSend)
spec.updateCycleMaterial = true
if self.isServer then
UniversalAutoload.countActivePallets(self)
end
end
--
function UniversalAutoload:cycleContainerTypeIndex(direction, noEventSend)
local spec = self.spec_universalAutoload
if self.isServer then
local containerIndex
if direction == 1 then
containerIndex = 999
for _, object in pairs(spec.availableObjects) do
local objectContainerName = UniversalAutoload.getContainerTypeName(object)
local objectContainerIndex = UniversalAutoload.CONTAINERS_INDEX[objectContainerName] or 1
if objectContainerIndex > spec.currentContainerIndex and objectContainerIndex < containerIndex then
containerIndex = objectContainerIndex
end
end
for _, object in pairs(spec.loadedObjects) do
local objectContainerName = UniversalAutoload.getContainerTypeName(object)
local objectContainerIndex = UniversalAutoload.CONTAINERS_INDEX[objectContainerName] or 1
if objectContainerIndex > spec.currentContainerIndex and objectContainerIndex < containerIndex then
containerIndex = objectContainerIndex
end
end
else
containerIndex = 0
local startingValue = (spec.currentContainerIndex==1) and #UniversalAutoload.CONTAINERS+1 or spec.currentContainerIndex
for _, object in pairs(spec.availableObjects) do
local objectContainerName = UniversalAutoload.getContainerTypeName(object)
local objectContainerIndex = UniversalAutoload.CONTAINERS_INDEX[objectContainerName] or 1
if objectContainerIndex < startingValue and objectContainerIndex > containerIndex then
containerIndex = objectContainerIndex
end
end
for _, object in pairs(spec.loadedObjects) do
local objectContainerName = UniversalAutoload.getContainerTypeName(object)
local objectContainerIndex = UniversalAutoload.CONTAINERS_INDEX[objectContainerName] or 1
if objectContainerIndex < startingValue and objectContainerIndex > containerIndex then
containerIndex = objectContainerIndex
end
end
end
if containerIndex == nil or containerIndex == 0 or containerIndex == 999 then
containerIndex = 1
end
UniversalAutoload.setContainerTypeIndex(self, containerIndex)
if containerIndex==1 and spec.totalAvailableCount==0 and spec.totalUnloadCount==0 then
-- NO_OBJECTS_FOUND
UniversalAutoload.showWarningMessage(self, 2)
end
end
UniversalAutoloadCycleContainerEvent.sendEvent(self, direction, noEventSend)
end
--
function UniversalAutoload:setContainerTypeIndex(typeIndex, noEventSend)
-- print("setContainerTypeIndex: "..self:getFullName().." "..tostring(typeIndex))
local spec = self.spec_universalAutoload
spec.currentContainerIndex = math.min(math.max(typeIndex, 1), table.getn(UniversalAutoload.CONTAINERS))
UniversalAutoloadSetContainerTypeEvent.sendEvent(self, typeIndex, noEventSend)
spec.updateCycleContainer = true
if self.isServer then
UniversalAutoload.countActivePallets(self)
end
end
--
function UniversalAutoload:setLoadingFilter(state, noEventSend)
-- print("setLoadingFilter: "..self:getFullName().." "..tostring(state))
local spec = self.spec_universalAutoload
spec.currentLoadingFilter = state
UniversalAutoloadSetFilterEvent.sendEvent(self, state, noEventSend)
spec.updateToggleFilter = true
if self.isServer then
UniversalAutoload.countActivePallets(self)
end
end
--
function UniversalAutoload:setHorizontalLoading(state, noEventSend)
-- print("setHorizontalLoading: "..self:getFullName().." "..tostring(state))
local spec = self.spec_universalAutoload
spec.useHorizontalLoading = state
UniversalAutoloadSetHorizontalLoadingEvent.sendEvent(self, state, noEventSend)
spec.updateHorizontalLoading = true
end
--
function UniversalAutoload:setCurrentTipside(tipside, noEventSend)
-- print("setTipside: "..self:getFullName().." - "..tostring(tipside))
local spec = self.spec_universalAutoload
spec.currentTipside = tipside
UniversalAutoloadSetTipsideEvent.sendEvent(self, tipside, noEventSend)
spec.updateToggleTipside = true
end