forked from loki79uk/FS25_UniversalAutoload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniversalAutoload.lua
More file actions
6044 lines (5360 loc) · 217 KB
/
UniversalAutoload.lua
File metadata and controls
6044 lines (5360 loc) · 217 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
-- ============================================================= --
-- Universal Autoload MOD - SPECIALISATION
-- ============================================================= --
UniversalAutoload = {}
UniversalAutoload.name = g_currentModName
UniversalAutoload.path = g_currentModDirectory
UniversalAutoload.specName = ("spec_%s.universalAutoload"):format(g_currentModName)
UniversalAutoload.globalKey = "universalAutoload"
UniversalAutoload.savegameStateKey = ".currentState"
UniversalAutoload.savegameConfigKey = ".configuration"
UniversalAutoload.postLoadKey = "." .. g_currentModName .. ".universalAutoload.currentState"
UniversalAutoload.savegameStateSchemaKey = "vehicles.vehicle(?)." .. g_currentModName .. ".universalAutoload.currentState"
UniversalAutoload.savegameConfigSchemaKey = "vehicles.vehicle(?)." .. g_currentModName .. ".universalAutoload.configuration"
UniversalAutoload.vehicleKey = "universalAutoload.vehicleConfigurations.vehicle(%d)"
UniversalAutoload.vehicleConfigKey = UniversalAutoload.vehicleKey .. ".configuration(%d)"
UniversalAutoload.vehicleSchemaKey = "universalAutoload.vehicleConfigurations.vehicle(?)"
UniversalAutoload.containerKey = "universalAutoload.containerConfigurations.container(%d)"
UniversalAutoload.containerSchemaKey = "universalAutoload.containerConfigurations.container(?)"
UniversalAutoload.SPLITSHAPES_LOOKUP = {}
UniversalAutoload.OBJECTS_LOOKUP = {}
UniversalAutoload.ALL = "ALL"
UniversalAutoload.DELTA = 0.005
UniversalAutoload.SPACING = 0.0
UniversalAutoload.BIGBAG_SPACING = 0.1
UniversalAutoload.MAX_STACK = 5
UniversalAutoload.LOG_SPACE = 0.25
UniversalAutoload.DELAY_TIME = 150
UniversalAutoload.MP_DELAY = 1000
UniversalAutoload.LOG_DELAY = 1000
UniversalAutoload.TRIGGER_DELTA = 0.1
UniversalAutoload.MAX_LAYER_COUNT = 10
UniversalAutoload.ROTATED_BALE_FACTOR = 0.80
-- 0.85355339
UniversalAutoload.showLoading = false
local debugKeys = false
local debugSchema = false
local debugConsole = false
local debugLoading = false
local debugPallets = false
local debugVehicles = false
local debugSpecial = false
-- local disablePhysicsAfterLoading = true
UniversalAutoload.MASK = {}
UniversalAutoload.MASK.object = CollisionFlag.VEHICLE + CollisionFlag.DYNAMIC_OBJECT + CollisionFlag.TREE
UniversalAutoload.MASK.everything = UniversalAutoload.MASK.object + CollisionFlag.STATIC_OBJECT + CollisionFlag.PLAYER
UniversalAutoload.MAX_NUM_ELEMENTS = InputHelpDisplay.MAX_NUM_ELEMENTS
UniversalAutoload.MAX_NUM_ELEMENTS_HIGH_PRIORITY = InputHelpDisplay.MAX_NUM_ELEMENTS_HIGH_PRIORITY
-- 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/SetCollectionModeEvent.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")
source(g_currentModDirectory.."events/UpdateDefaultSettingsEvent.lua")
-- REQUIRED SPECIALISATION FUNCTIONS
function UniversalAutoload.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(TensionBelts, specializations)
end
--
function UniversalAutoload.initSpecialization()
local globalKey = UniversalAutoload.globalKey
g_vehicleConfigurationManager:addConfigurationType("universalAutoload", g_i18n:getText("configuration_universalAutoload"), globalKey, "autoload", nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
local function registerConfig(schema, rootKey, tbl, parentKey)
parentKey = parentKey or ""
for _, v in pairs(tbl) do
if type(v) == "table" then
local currentKey = parentKey .. (v.key or "")
if v.valueType then
schema:register(XMLValueType[v.valueType], rootKey .. currentKey, v.description or "", v.default)
if debugSchema then print(" " .. rootKey .. currentKey) end
end
if v.data then
registerConfig(schema, rootKey, v.data, currentKey)
end
end
end
end
UniversalAutoload.xmlSchema = XMLSchema.new(globalKey)
print("*** REGISTER XML SCHEMAS ***")
if debugSchema then print("GLOBAL_DEFAULTS:") end
registerConfig(UniversalAutoload.xmlSchema, UniversalAutoload.globalKey, UniversalAutoload.GLOBAL_DEFAULTS)
if debugSchema then print("VEHICLE_DEFAULTS:") end
registerConfig(UniversalAutoload.xmlSchema, UniversalAutoload.vehicleSchemaKey, UniversalAutoload.VEHICLE_DEFAULTS)
if debugSchema then print("SAVEGAME_STATE_DEFAULTS:") end
registerConfig(Vehicle.xmlSchemaSavegame, UniversalAutoload.savegameStateSchemaKey, UniversalAutoload.SAVEGAME_STATE_DEFAULTS)
if debugSchema then print("SAVEGAME_CONFIG_DEFAULTS:") end
registerConfig(Vehicle.xmlSchemaSavegame, UniversalAutoload.savegameConfigSchemaKey, UniversalAutoload.CONFIG_DEFAULTS)
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, "ualOnDeleteVehicle_Callback", UniversalAutoload.ualOnDeleteVehicle_Callback)
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, "getFullName", UniversalAutoload.ualGetFullName)
-- 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 and spec.isAutoloadAvailable and not spec.autoloadDisabled and spec.autoCollectionMode 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 and spec.isAutoloadAvailable and not spec.autoloadDisabled then
-- if debugSpecial then print("*** getCanImplementBeUsedForAI ***") end
-- --DebugUtil.printTableRecursively(self.spec_aiImplement, "--", 0, 1)
-- --return true
-- end
-- return superFunc(self)
-- end
--
function UniversalAutoload:getDynamicMountTimeToMount(superFunc)
local spec = self.spec_universalAutoload
if spec==nil or not spec.isAutoloadAvailable or spec.autoloadDisabled then
return superFunc(self)
end
return UniversalAutoload.getIsLoadingVehicleAllowed(self) and -1 or math.huge
end
--
function UniversalAutoload:ualGetFullName(superFunc)
local spec = self.spec_universalAutoload
if spec==nil or not spec.isAutoloadAvailable or not UniversalAutoload.showDebug then
return superFunc(self)
end
return superFunc(self).." - UAL #"..tostring(self.rootNode)
end
function UniversalAutoload.registerEventListeners(vehicleType)
print(" Register vehicle type: " .. vehicleType.name)
SpecializationUtil.registerEventListener(vehicleType, "onLoad", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onUpdate", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onUpdateTick", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onUpdateEnd", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onDraw", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onReadStream", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onWriteStream", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onDelete", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onPreDelete", UniversalAutoload)
SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", 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")
SpecializationUtil.removeEventListener(vehicleType, "onLoad", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onPostLoad", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onUpdate", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onUpdateTick", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onUpdateEnd", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onDraw", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onDelete", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onPreDelete", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onRegisterActionEvents", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onActivate", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onDeactivate", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onFoldStateChanged", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onMovingToolChanged", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onAIImplementStart", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onAIImplementEnd", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onAIFieldWorkerStart", UniversalAutoload)
SpecializationUtil.removeEventListener(vehicleType, "onAIFieldWorkerEnd", UniversalAutoload)
end
-- ACTION EVENT FUNCTIONS
function UniversalAutoload:clearActionEvents()
local spec = self.spec_universalAutoload
if spec and spec.isAutoloadAvailable and spec.actionEvents 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 and spec.isAutoloadAvailable and not spec.autoloadDisabled and spec.actionEvents and next(spec.actionEvents) == nil then
if debugKeys then print("updateActionEventKeys: "..self:getFullName()) end
local actions = UniversalAutoload.ACTIONS
local ignoreCollisions = true
local reportAnyDeviceCollision = true
local triggerUp = false
local triggerDown = true
local triggerAlways = false
local startActive = true
local topPriority, midPriority, lowPriority
if UniversalAutoload.highPriority == true then
topPriority = GS_PRIO_VERY_HIGH
midPriority = GS_PRIO_HIGH
lowPriority = GS_PRIO_NORMAL
InputHelpDisplay.MAX_NUM_ELEMENTS = UniversalAutoload.MAX_NUM_ELEMENTS_HIGH_PRIORITY
else
topPriority = GS_PRIO_HIGH
midPriority = GS_PRIO_NORMAL
lowPriority = GS_PRIO_LOW
InputHelpDisplay.MAX_NUM_ELEMENTS = UniversalAutoload.MAX_NUM_ELEMENTS
end
local function registerActionEvent(id, event, callback, priority, visible)
local valid, actionEventId = self:addActionEvent(spec.actionEvents, actions[id], self, UniversalAutoload[callback],
triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName, ignoreCollisions, reportAnyDeviceCollision)
if debugKeys then print(" " .. id .. ": "..tostring(valid)) end
if valid == false then -- and self:getIsSelected()
local _, _, otherEvents = g_inputBinding:registerActionEvent(actions[id], self, UniversalAutoload[callback],
triggerUp, triggerDown, triggerAlways, startActive, callbackState, true, reportAnyDeviceCollision)
if otherEvents ~= nil then
local removedConflictingEvent = nil
for _, otherEvent in ipairs(otherEvents) do
if otherEvent.actionName == 'CRABSTEERING_ALLWHEEL' then
if otherEvent.parentEventsTable ~= nil then
g_inputBinding:removeActionEvent(otherEvent.id)
otherEvent.parentEventsTable[otherEvent.id] = nil
removedConflictingEvent = otherEvent.actionName
end
end
end
if removedConflictingEvent then
local valid, newActionEventId = self:addActionEvent(spec.actionEvents, actions[id], self, UniversalAutoload[callback],
triggerUp, triggerDown, triggerAlways, startActive, callbackState, customIconName, ignoreCollisions, reportAnyDeviceCollision)
if valid then
actionEventId = newActionEventId
else
actionEventId = nil
end
spec.alreadyPrintedConflictingAction = spec.alreadyPrintedConflictingAction or {}
if not spec.alreadyPrintedConflictingAction[removedConflictingEvent] then
spec.alreadyPrintedConflictingAction[removedConflictingEvent] = true
print("UAL - key binding for " .. id .. " failed to register")
if valid then
print("removed conflicting action: " .. removedConflictingEvent)
else
print("COULD NOT REMOVE conflicting action: " .. removedConflictingEvent)
end
print("*** Please re-bind one of these actions to prevent this message ***")
end
end
end
end
if actionEventId then
-- print("setting " .. tostring(actionEventId))
spec[event] = actionEventId
g_inputBinding:setActionEventTextPriority(actionEventId, priority)
if visible ~= nil then
g_inputBinding:setActionEventTextVisibility(actionEventId, visible)
end
end
end
registerActionEvent('GLOBAL_MENU', 'globalMenuActionEventId', 'actionEventGlobalMenu', lowPriority)
globalMenuText = "UAL " .. g_i18n:getText("ui_global_settings_ual")
g_inputBinding:setActionEventText(spec.globalMenuActionEventId, globalMenuText)
spec.updateToggleLoading = true
registerActionEvent('UNLOAD_ALL', 'unloadAllActionEventId', 'actionEventUnloadAll', topPriority, true)
registerActionEvent('TOGGLE_LOADING', 'toggleLoadingActionEventId', 'actionEventToggleLoading', topPriority)
registerActionEvent('TOGGLE_COLLECTION', 'toggleCollectionModeEventId', 'actionEventToggleCollectionMode', topPriority)
if not spec.isLogTrailer then
registerActionEvent('TOGGLE_FILTER', 'toggleLoadingFilterActionEventId', 'actionEventToggleFilter', midPriority)
spec.updateToggleFilter = true
end
if not spec.isLogTrailer then
registerActionEvent('TOGGLE_HORIZONTAL', 'toggleHorizontalLoadingActionEventId', 'actionEventToggleHorizontalLoading', midPriority)
spec.updateHorizontalLoading = true
registerActionEvent('CYCLE_MATERIAL_FW', 'cycleMaterialActionEventId', 'actionEventCycleMaterial_FW', midPriority)
registerActionEvent('CYCLE_MATERIAL_BW', 'cycleMaterialBwActionEventId', 'actionEventCycleMaterial_BW', lowPriority, false)
registerActionEvent('SELECT_ALL_MATERIALS', 'selectAllMaterialsEventId', 'actionEventSelectAllMaterials', lowPriority, false)
spec.updateCycleMaterial = true
if UniversalAutoload.chatKeyConflict ~= true then
registerActionEvent('CYCLE_CONTAINER_FW', 'cycleContainerActionEventId', 'actionEventCycleContainer_FW', midPriority)
registerActionEvent('CYCLE_CONTAINER_BW', 'cycleContainerBwActionEventId', 'actionEventCycleContainer_BW', lowPriority, false)
registerActionEvent('SELECT_ALL_CONTAINERS', 'selectAllContainersActionEventId', 'actionEventSelectAllContainers', lowPriority, false)
spec.updateCycleContainer = true
end
end
if not spec.isCurtainTrailer and not spec.rearUnloadingOnly and not spec.frontUnloadingOnly then
registerActionEvent('TOGGLE_TIPSIDE', 'toggleTipsideActionEventId', 'actionEventToggleTipside', midPriority)
spec.updateToggleTipside = true
end
-- if g_localPlayer.isControlled then
-- if not g_currentMission.missionDynamicInfo.isMultiplayer and self.spec_tensionBelts then
-- registerActionEvent('TOGGLE_BELTS', 'toggleBeltsActionEventId', 'actionEventToggleBelts', midPriority)
-- spec.updateToggleBelts = true
-- end
-- if spec.isCurtainTrailer or spec.isBoxTrailer then
-- registerActionEvent('TOGGLE_DOOR', 'toggleDoorActionEventId', 'actionEventToggleDoor', midPriority)
-- spec.updateToggleDoor = true
-- end
-- if spec.isCurtainTrailer then
-- registerActionEvent('TOGGLE_CURTAIN', 'toggleCurtainActionEventId', 'actionEventToggleCurtain', midPriority)
-- spec.updateToggleCurtain = true
-- end
-- end
registerActionEvent('TOGGLE_SHOW_DEBUG', 'toggleShowDebugActionEventId', 'actionEventToggleShowDebug', lowPriority)
registerActionEvent('TOGGLE_SHOW_LOADING', 'toggleShowLoadingActionEventId', 'actionEventToggleShowLoading', lowPriority)
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 and spec.isAutoloadAvailable and spec.toggleBeltsActionEventId then
g_inputBinding:setActionEventActive(spec.toggleBeltsActionEventId, true)
local tensionBeltsText
if self.spec_tensionBelts.areAllBeltsFastened 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_localPlayer.isControlled then
if spec and spec.isAutoloadAvailable 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 and spec.isAutoloadAvailable 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 and spec.isAutoloadAvailable and g_localPlayer.isControlled then
if self.spec_trailer and spec.isCurtainTrailer then
local trailer = self.spec_trailer
local tipSide = trailer.tipSides[trailer.preferedTipSideIndex]
if tipSide 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 and spec.isAutoloadAvailable and spec.cycleMaterialActionEventId 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 and spec.isAutoloadAvailable and spec.cycleContainerActionEventId 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 and spec.isAutoloadAvailable and spec.toggleLoadingFilterActionEventId 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 and spec.isAutoloadAvailable and spec.toggleHorizontalLoadingActionEventId 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 and spec.isAutoloadAvailable and spec.toggleTipsideActionEventId 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 and spec.isAutoloadAvailable and spec.toggleCollectionModeEventId then
-- Activate/Deactivate the AUTO-BALE key binding
if spec.autoCollectionMode or spec.validUnloadCount==0 then
local autoCollectionModeText = g_i18n:getText("universalAutoload_collectionMode")
if spec.autoCollectionMode then
if spec.baleCollectionActive == true then
autoCollectionModeText = g_i18n:getText("universalAutoload_baleMode")
elseif spec.baleCollectionActive == false then
if spec.isLogTrailer then
autoCollectionModeText = g_i18n:getText("universalAutoload_logMode")
else
autoCollectionModeText = g_i18n:getText("universalAutoload_palletMode")
end
end
autoCollectionModeText = autoCollectionModeText..": "..g_i18n:getText("universalAutoload_enabled")
else
autoCollectionModeText = autoCollectionModeText..": "..g_i18n:getText("universalAutoload_disabled")
end
g_inputBinding:setActionEventText(spec.toggleCollectionModeEventId, autoCollectionModeText)
g_inputBinding:setActionEventActive(spec.toggleCollectionModeEventId, true)
g_inputBinding:setActionEventTextVisibility(spec.toggleCollectionModeEventId, true)
if debugKeys then print(" >> " .. autoCollectionModeText) end
else
g_inputBinding:setActionEventActive(spec.toggleCollectionModeEventId, false)
end
end
if spec and spec.isAutoloadAvailable and spec.toggleLoadingActionEventId then
-- Activate/Deactivate the LOAD key binding
if spec.isLoading and not spec.autoCollectionMode 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) == true 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 and spec.isAutoloadAvailable and spec.unloadAllActionEventId then
-- Activate/Deactivate the UNLOAD key binding
if UniversalAutoload.getIsUnloadingKeyAllowed(self) == true 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.areAllBeltsFastened 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.isClient then
UniversalAutoload.showDebug = not UniversalAutoload.showDebug
UniversalAutoload.showLoading = UniversalAutoload.showDebug
end
end
--
function UniversalAutoload.actionEventToggleShowLoading(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleShowLoading: "..self:getFullName())
local spec = self.spec_universalAutoload
if self.isClient then
UniversalAutoload.showLoading = not UniversalAutoload.showLoading
if UniversalAutoload.showLoading == false then
UniversalAutoload.showDebug = false
end
end
end
--
function UniversalAutoload.actionEventToggleCollectionMode(self, actionName, inputValue, callbackState, isAnalog)
-- print("actionEventToggleCollectionMode: "..self:getFullName())
local spec = self.spec_universalAutoload
UniversalAutoload.setAutoCollectionMode(self, not spec.autoCollectionMode)
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("CALLBACK actionEventToggleLoading: "..self:getFullName())
local spec = self.spec_universalAutoload
if not spec.isLoading then
print("START Loading: "..self:getFullName() .. " (" .. tostring(spec.totalUnloadCount) .. ")")
UniversalAutoload.startLoading(self)
else
print("STOP Loading: "..self:getFullName() .. " (" .. tostring(spec.totalUnloadCount) .. ")")
UniversalAutoload.stopLoading(self)
end
end
--
function UniversalAutoload.actionEventUnloadAll(self, actionName, inputValue, callbackState, isAnalog)
-- print("CALLBACK actionEventUnloadAll: "..self:getFullName())
local spec = self.spec_universalAutoload
print("UNLOAD ALL: "..self:getFullName() .. " (" .. tostring(spec.totalUnloadCount) .. ")")
UniversalAutoload.startUnloading(self)
end
--
function UniversalAutoload.actionEventGlobalMenu(self, actionName, inputValue, callbackState, isAnalog)
-- print("CALLBACK actionEventGlobalMenu: "..self:getFullName())
local spec = self.spec_universalAutoload
print("GLOBAL MENU: " .. self:getFullName())
UniversalAutoloadManager.globalSettingsMenu:setNewVehicle(self)
UniversalAutoloadManager:onOpenGlobalSettingsEvent('UNIVERSALAUTOLOAD_GLOBAL_CONFIG', 1)
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 or {}) 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 or {}) 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 or {}) 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 or {}) 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, "NO_OBJECTS_FOUND")
end
end
UniversalAutoload.CycleMaterialEvent.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))
UniversalAutoload.SetMaterialTypeEvent.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 or {}) do
local objectContainerName = UniversalAutoload.getContainerTypeName(object)
local objectContainerIndex = UniversalAutoload.CONTAINERS_LOOKUP[objectContainerName] or 1
if objectContainerIndex > spec.currentContainerIndex and objectContainerIndex < containerIndex then
containerIndex = objectContainerIndex
end
end
for object, _ in pairs(spec.loadedObjects or {}) do
local objectContainerName = UniversalAutoload.getContainerTypeName(object)
local objectContainerIndex = UniversalAutoload.CONTAINERS_LOOKUP[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 or {}) do
local objectContainerName = UniversalAutoload.getContainerTypeName(object)
local objectContainerIndex = UniversalAutoload.CONTAINERS_LOOKUP[objectContainerName] or 1
if objectContainerIndex < startingValue and objectContainerIndex > containerIndex then
containerIndex = objectContainerIndex
end
end
for object, _ in pairs(spec.loadedObjects or {}) do
local objectContainerName = UniversalAutoload.getContainerTypeName(object)
local objectContainerIndex = UniversalAutoload.CONTAINERS_LOOKUP[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, "NO_OBJECTS_FOUND")
end
end
UniversalAutoload.CycleContainerEvent.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))
UniversalAutoload.SetContainerTypeEvent.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
UniversalAutoload.SetFilterEvent.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
UniversalAutoload.SetHorizontalLoadingEvent.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
UniversalAutoload.SetTipsideEvent.sendEvent(self, tipside, noEventSend)
spec.updateToggleTipside = true
end
--
function UniversalAutoload:setCurrentLoadside(loadside, noEventSend)
-- print("setLoadside: "..self:getFullName().." - "..tostring(loadside))
local spec = self.spec_universalAutoload
spec.currentLoadside = loadside
UniversalAutoload.SetLoadsideEvent.sendEvent(self, loadside, noEventSend)
if self.isServer then
UniversalAutoload.countActivePallets(self)
UniversalAutoload.updateActionEventText(self)
end
end
--
function UniversalAutoload:setAutoCollectionMode(autoCollectionMode, noEventSend)
-- print("setAutoCollectionMode: "..self:getFullName().." - "..tostring(autoCollectionMode))
local spec = self.spec_universalAutoload
if spec==nil or not spec.isAutoloadAvailable or spec.autoloadDisabled then
if debugVehicles then print(self:getFullName() .. ": UAL DISABLED - setAutoCollectionMode") end
return
end
if self.isServer and spec.autoCollectionMode ~= autoCollectionMode then
if autoCollectionMode then
if not spec.trailerIsFull then
local balesAvailable = spec.availableBaleCount and spec.availableBaleCount > 0
local palletsAvailable = spec.totalAvailableCount and spec.totalAvailableCount > 0
if balesAvailable and not spec.isLogTrailer then
if debugSpecial then print("autoCollectionMode: startLoading (bales)") end
spec.baleCollectionActive = true
elseif palletsAvailable then
if debugSpecial then print("autoCollectionMode: startLoading (pallets/logs)") end
spec.baleCollectionActive = false
else
if debugSpecial then print("autoCollectionMode: startLoading (unknown)") end
spec.baleCollectionActive = nil
end
UniversalAutoload.startLoading(self)
end
else
if debugSpecial then print("autoCollectionMode: stopLoading") end
UniversalAutoload.stopLoading(self)
if spec.baleCollectionActive then
spec.baleCollectionModeDeactivated = true
end
spec.baleCollectionActive = nil
end
end
spec.autoCollectionMode = autoCollectionMode
UniversalAutoload.SetCollectionModeEvent.sendEvent(self, autoCollectionMode, noEventSend)
spec.updateToggleLoading = true
end