-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAPalletAutoLoader.lua
2310 lines (1928 loc) · 96.8 KB
/
APalletAutoLoader.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
---Specialization for automatically load objects onto a vehicle by Achimobil
-- It is not allowed to copy my code complete or in Parts into other mods
-- If you have any issues please report them in my Discord on the channel for the mod.
-- https://github.com/Achimobil/FS22_aPalletAutoLoader
APalletAutoLoaderCoordinator = {}
APalletAutoLoaderCoordinator.availableAutoloader = {}
APalletAutoLoader = {}
APalletAutoLoader.debug = false;
APalletAutoLoader.defaultPickupTriggerCollisionMask = CollisionFlag.TRIGGER_DYNAMIC_OBJECT;
APalletAutoLoader.modDir = g_currentModDirectory;
APalletAutoLoader.objectTypes = {};
APalletAutoLoader.palletobjectTypeNames = {};
APalletAutoLoaderTipsides = {
LEFT = 1,
RIGHT = 2,
MIDDLE = 3,
BACK = 4
}
APalletAutoLoaderLoadingState = {
STOPPED = 1,
RUNNING = 2
}
function APalletAutoLoader.print(text, ...)
if APalletAutoLoader.debug then
print("APalletAutoLoader Debug: " .. string.format(text, ...));
end
end
---Checks if all prerequisite specializations are loaded
-- @param table specializations specializations
-- @return boolean hasPrerequisite true if all prerequisite specializations are loaded
function APalletAutoLoader.prerequisitesPresent(specializations)
return true
end
function APalletAutoLoader.initSpecialization()
print("init aPalletAutoLoader");
g_configurationManager:addConfigurationType("aPalletAutoLoader", g_i18n:getText("configuration_aPalletAutoLoader"), "aPalletAutoLoader", nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
local schema = Vehicle.xmlSchema
schema:setXMLSpecializationType("APalletAutoLoader")
local baseXmlPath = "vehicle.aPalletAutoLoader.APalletAutoLoaderConfigurations.APalletAutoLoaderConfiguration(?)"
schema:register(XMLValueType.NODE_INDEX, baseXmlPath .. ".trigger#node", "Trigger node")
schema:register(XMLValueType.NODE_INDEX, baseXmlPath .. ".pickupTriggers.pickupTrigger(?)#node", "Pickup trigger node")
schema:register(XMLValueType.STRING, baseXmlPath .. "#supportedObject", "Path to xml of supported object")
schema:register(XMLValueType.INT, baseXmlPath .. "#fillUnitIndex", "Fill unit index to check fill type")
schema:register(XMLValueType.INT, baseXmlPath .. "#maxObjects", "Max. number of objects to load", "Number of load places")
schema:register(XMLValueType.BOOL, baseXmlPath .. "#useBales", "Use for bales", false)
schema:register(XMLValueType.BOOL, baseXmlPath .. "#useTensionBelts", "Automatically mount tension belts", "False for mobile, otherwise true")
schema:register(XMLValueType.BOOL, baseXmlPath .. "#usePalletWeightReduction", "Reduce the weight of pallets on loading", true)
schema:register(XMLValueType.VECTOR_TRANS, baseXmlPath .. "#UnloadRightOffset", "Offset for Unload right")
schema:register(XMLValueType.VECTOR_TRANS, baseXmlPath .. "#UnloadLeftOffset", "Offset for Unload left")
schema:register(XMLValueType.VECTOR_TRANS, baseXmlPath .. "#UnloadMiddleOffset", "Offset for Unload middle")
schema:register(XMLValueType.VECTOR_TRANS, baseXmlPath .. "#UnloadBackOffset", "Offset for Unload back")
schema:register(XMLValueType.NODE_INDEX, baseXmlPath .. ".loadArea#baseNode", "Base node for loading")
schema:register(XMLValueType.VECTOR_TRANS, baseXmlPath .. ".loadArea#leftRightCornerOffset", "Offset for the left corner, loading will be done starting this point")
schema:register(XMLValueType.FLOAT, baseXmlPath .. ".loadArea#lenght", "length of the loadArea")
schema:register(XMLValueType.FLOAT, baseXmlPath .. ".loadArea#height", "height of the loadArea")
schema:register(XMLValueType.FLOAT, baseXmlPath .. ".loadArea#width", "width of the loadArea")
schema:register(XMLValueType.STRING, baseXmlPath .. ".autoLoadObjectSettings.autoLoadObjectSetting(?)#name", "name of the loading type to configure different than base setting")
schema:register(XMLValueType.STRING, baseXmlPath .. ".autoLoadObjectSettings.autoLoadObjectSetting(?)#maxObjects", "max number of objects loadable for this type, otherwise base maxObjects is used")
schema:register(XMLValueType.VECTOR_TRANS, baseXmlPath .. ".autoLoadObjectSettings.autoLoadObjectSetting(?)#leftRightCornerOffset", "Offset for the left corner, otherwise loadingArea value is used")
schema:register(XMLValueType.FLOAT, baseXmlPath .. ".autoLoadObjectSettings.autoLoadObjectSetting(?)#lenght", "length to use for this type, otherwise loadingArea value is used")
schema:register(XMLValueType.FLOAT, baseXmlPath .. ".autoLoadObjectSettings.autoLoadObjectSetting(?)#height", "height to use for this type, otherwise loadingArea value is used")
schema:register(XMLValueType.FLOAT, baseXmlPath .. ".autoLoadObjectSettings.autoLoadObjectSetting(?)#width", "width to use for this type, otherwise loadingArea value is used")
schema:setXMLSpecializationType()
local schemaSavegame = Vehicle.xmlSchemaSavegame
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).FS22_aPalletAutoLoader.aPalletAutoLoader#lastUsedPalletTypeIndex", "Last used pallet type")
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).FS22_aPalletAutoLoader.aPalletAutoLoader#lastUseTensionBelts", "Last used tension belts setting")
-- load object types from XML into tables and use them for easier reading
local xmlFileObjects = XMLFile.load("objectTypesXML", APalletAutoLoader.modDir .. "objectTypes.xml");
xmlFileObjects:iterate("objectTypes.objectType", function (_, key)
local typeName = xmlFileObjects:getString(key .. "#typeName");
Logging.info("Load from XML typeName: %s", typeName);
if APalletAutoLoader.objectTypes[typeName] ~= nil then
Logging.xmlError(xmlFileObjects, "object type '%s' already defined!", typeName);
else
local autoLoadObject = {};
autoLoadObject.checkInfos = {};
autoLoadObject.sizeX = MathUtil.round(xmlFileObjects:getFloat(key .. "#sizeX"), 2);
autoLoadObject.sizeY = MathUtil.round(xmlFileObjects:getFloat(key .. "#sizeY"), 2);
autoLoadObject.sizeZ = MathUtil.round(xmlFileObjects:getFloat(key .. "#sizeZ"), 2);
autoLoadObject.type = xmlFileObjects:getString(key .. "#type");
autoLoadObject.stackable = xmlFileObjects:getBool(key .. "#stackable");
autoLoadObject.requirements = xmlFileObjects:getString(key .. "#requirements"); -- multiple values with | possible. Possible values "useBales". When multiple then all needs to match to add type to loading list
autoLoadObject.requiredMods = xmlFileObjects:getString(key .. "#requiredMods"); -- only add this type when the named mod is loaded. Full name required and DLC name can be used also. Currently only one mod is usable. Will be expanded later for mutliple mods with | splitting if needed
autoLoadObject.l10nText = xmlFileObjects:getString(key .. "#l10nText"); -- key for l10n, when not the type should be used
autoLoadObject.l10nMod = xmlFileObjects:getString(key .. "#l10nMod"); -- mod to lod the l10n from, when not the AL mod is used
local collisionMaskName = xmlFileObjects:getString(key .. "#pickupTriggerCollisionMask");
if collisionMaskName ~= nil then
autoLoadObject.pickupTriggerCollisionMask = CollisionFlag[collisionMaskName];
end
xmlFileObjects:iterate(key .. ".checks.check", function (_, checkKey)
local checkInfo = {};
checkInfo.checkTarget = xmlFileObjects:getString(checkKey .. "#checkTarget");
checkInfo.checkMethod = xmlFileObjects:getString(checkKey .. "#checkMethod");
checkInfo.checkValue = xmlFileObjects:getString(checkKey .. "#checkValue");
checkInfo.checkValue2 = xmlFileObjects:getString(checkKey .. "#checkValue2");
checkInfo.checkResultOnMatch = xmlFileObjects:getBool(checkKey .. "#checkResultOnMatch");
table.insert(autoLoadObject.checkInfos, checkInfo);
end)
APalletAutoLoader.objectTypes[typeName] = autoLoadObject;
table.insert(APalletAutoLoader.palletobjectTypeNames, typeName);
end
end)
xmlFileObjects:delete(xmlFileObjects);
end
function APalletAutoLoader.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, "getIsValidObject", APalletAutoLoader.getIsValidObject)
SpecializationUtil.registerFunction(vehicleType, "getIsMountedObject", APalletAutoLoader.getIsMountedObject)
SpecializationUtil.registerFunction(vehicleType, "getIsAutoLoadingAllowed", APalletAutoLoader.getIsAutoLoadingAllowed)
SpecializationUtil.registerFunction(vehicleType, "getFirstValidLoadPlace", APalletAutoLoader.getFirstValidLoadPlace)
SpecializationUtil.registerFunction(vehicleType, "autoLoaderOverlapCallback", APalletAutoLoader.autoLoaderOverlapCallback)
SpecializationUtil.registerFunction(vehicleType, "autoLoaderTriggerCallback", APalletAutoLoader.autoLoaderTriggerCallback)
SpecializationUtil.registerFunction(vehicleType, "autoLoaderPickupTriggerCallback", APalletAutoLoader.autoLoaderPickupTriggerCallback)
SpecializationUtil.registerFunction(vehicleType, "onDeleteAPalletAutoLoaderObject", APalletAutoLoader.onDeleteAPalletAutoLoaderObject)
SpecializationUtil.registerFunction(vehicleType, "onDeleteObjectToLoad", APalletAutoLoader.onDeleteObjectToLoad)
SpecializationUtil.registerFunction(vehicleType, "loadObject", APalletAutoLoader.loadObject)
SpecializationUtil.registerFunction(vehicleType, "unloadAll", APalletAutoLoader.unloadAll)
SpecializationUtil.registerFunction(vehicleType, "loadAllInRange", APalletAutoLoader.loadAllInRange)
SpecializationUtil.registerFunction(vehicleType, "SetTipside", APalletAutoLoader.SetTipside)
SpecializationUtil.registerFunction(vehicleType, "SetAutoloadType", APalletAutoLoader.SetAutoloadType)
SpecializationUtil.registerFunction(vehicleType, "SetLoadingState", APalletAutoLoader.SetLoadingState)
SpecializationUtil.registerFunction(vehicleType, "StartLoading", APalletAutoLoader.StartLoading)
SpecializationUtil.registerFunction(vehicleType, "GetAutoloadTypes", APalletAutoLoader.GetAutoloadTypes)
SpecializationUtil.registerFunction(vehicleType, "SetTensionBeltsValue", APalletAutoLoader.SetTensionBeltsValue)
SpecializationUtil.registerFunction(vehicleType, "ChangeShowMarkers", APalletAutoLoader.ChangeShowMarkers)
SpecializationUtil.registerFunction(vehicleType, "PalHasBales", APalletAutoLoader.PalHasBales)
SpecializationUtil.registerFunction(vehicleType, "PalIsFull", APalletAutoLoader.PalIsFull)
SpecializationUtil.registerFunction(vehicleType, "PalGetBalesToIgnore", APalletAutoLoader.PalGetBalesToIgnore)
SpecializationUtil.registerFunction(vehicleType, "PalIsGrabbingBale", APalletAutoLoader.PalIsGrabbingBale)
SpecializationUtil.registerFunction(vehicleType, "AddSupportedObjects", APalletAutoLoader.AddSupportedObjects)
SpecializationUtil.registerFunction(vehicleType, "CreateAvailableTypeList", APalletAutoLoader.CreateAvailableTypeList)
SpecializationUtil.registerFunction(vehicleType, "SetPickupTriggerCollisionMask", APalletAutoLoader.SetPickupTriggerCollisionMask)
SpecializationUtil.registerFunction(vehicleType, "SetAutoloadTypeAutomatic", APalletAutoLoader.SetAutoloadTypeAutomatic)
SpecializationUtil.registerFunction(vehicleType, "RemoveObjectFromToLoadLists", APalletAutoLoader.RemoveObjectFromToLoadLists)
if vehicleType.functions["getFillUnitCapacity"] == nil then
SpecializationUtil.registerFunction(vehicleType, "getFillUnitCapacity", APalletAutoLoader.getFillUnitCapacity)
end
if vehicleType.functions["getFillUnitFillLevel"] == nil then
SpecializationUtil.registerFunction(vehicleType, "getFillUnitFillLevel", APalletAutoLoader.getFillUnitFillLevel)
end
if vehicleType.functions["getFillUnitFreeCapacity"] == nil then
SpecializationUtil.registerFunction(vehicleType, "getFillUnitFreeCapacity", APalletAutoLoader.getFillUnitFreeCapacity)
end
end
function APalletAutoLoader.registerOverwrittenFunctions(vehicleType)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "getDynamicMountTimeToMount", APalletAutoLoader.getDynamicMountTimeToMount)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "getUseTurnedOnSchema", APalletAutoLoader.getUseTurnedOnSchema)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "lockTensionBeltObject", APalletAutoLoader.lockTensionBeltObject)
if vehicleType.functions["getFillUnitCapacity"] ~= nil then
SpecializationUtil.registerOverwrittenFunction(vehicleType, "getFillUnitCapacity", APalletAutoLoader.getFillUnitCapacity)
end
if vehicleType.functions["getFillUnitFillLevel"] ~= nil then
SpecializationUtil.registerOverwrittenFunction(vehicleType, "getFillUnitFillLevel", APalletAutoLoader.getFillUnitFillLevel)
end
if vehicleType.functions["getFillUnitFreeCapacity"] ~= nil then
SpecializationUtil.registerOverwrittenFunction(vehicleType, "getFillUnitFreeCapacity", APalletAutoLoader.getFillUnitFreeCapacity)
end
end
function APalletAutoLoader.registerEventListeners(vehicleType)
SpecializationUtil.registerEventListener(vehicleType, "onLoad", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onDelete", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onReadUpdateStream", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onWriteUpdateStream", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onDraw", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onAIImplementStart", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onAIImplementEnd", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onAIFieldWorkerStart", APalletAutoLoader)
SpecializationUtil.registerEventListener(vehicleType, "onAIFieldWorkerEnd", APalletAutoLoader)
end
function APalletAutoLoader:onAIImplementStart()
-- Aufklappen, anschalten oder was sonst noch fehlt.
SetAutoloadStateEvent.sendEvent(self, APalletAutoLoaderLoadingState.RUNNING)
end
function APalletAutoLoader:onAIImplementEnd()
-- Zuklappen, ausschalten oder was sonst noch fehlt.
SetAutoloadStateEvent.sendEvent(self, APalletAutoLoaderLoadingState.STOPPED)
end
function APalletAutoLoader:onAIFieldWorkerStart()
-- Aufklappen, anschalten oder was sonst noch fehlt.
SetAutoloadStateEvent.sendEvent(self, APalletAutoLoaderLoadingState.RUNNING)
end
function APalletAutoLoader:onAIFieldWorkerEnd()
-- Zuklappen, ausschalten oder was sonst noch fehlt.
SetAutoloadStateEvent.sendEvent(self, APalletAutoLoaderLoadingState.STOPPED)
end
function APalletAutoLoader:onDraw(isActiveForInput, isActiveForInputIgnoreSelection)
local spec = self.spec_aPalletAutoLoader
if spec.autoLoadTypes ~= nil then
local maxItems = spec.autoLoadTypes[spec.currentautoLoadTypeIndex].maxItems;
if spec.isFullLoaded then maxItems = spec.numTriggeredObjects; end
local loadingText = spec.autoLoadTypes[spec.currentautoLoadTypeIndex].nameTranslated .. " (" .. spec.numTriggeredObjects .. " / " .. maxItems .. ")"
g_currentMission:addExtraPrintText(loadingText);
end
if not spec.showMarkers and not APalletAutoLoader.debug then return end
if spec.loadArea["baseNode"] ~= nil then
-- DebugUtil.drawDebugReferenceAxisFromNode(spec.loadArea["baseNode"]);
local leftRightCornerOffsetForObjectType = spec.loadArea["leftRightCornerOffset"];
local heightForObjectType = spec.loadArea["height"];
local lenghtForObjectType = spec.loadArea["lenght"];
local widthForObjectType = spec.loadArea["width"];
local name = spec.autoLoadTypes[spec.currentautoLoadTypeIndex].name;
if spec.autoLoadObjectSettings[name] ~= nil then
leftRightCornerOffsetForObjectType = spec.autoLoadObjectSettings[name].leftRightCornerOffset;
lenghtForObjectType = spec.autoLoadObjectSettings[name].lenght
heightForObjectType = spec.autoLoadObjectSettings[name].height
widthForObjectType = spec.autoLoadObjectSettings[name].width
end
-- draw line around loading area
local cornerX,cornerY,cornerZ = unpack(leftRightCornerOffsetForObjectType);
local node = spec.loadArea["baseNode"]
local minX = (-widthForObjectType*0.5)+(cornerX-(widthForObjectType*0.5));
local maxX = (widthForObjectType*0.5)+(cornerX-(widthForObjectType*0.5));
local maxZ = (lenghtForObjectType*0.5)+(cornerZ-(lenghtForObjectType*0.5));
local minZ = (-lenghtForObjectType*0.5)+(cornerZ-(lenghtForObjectType*0.5));
local yOffset = cornerY;
local r = 0;
local g = 0.8;
local b = 0.8;
-- loading area
local leftFrontX, leftFrontY, leftFrontZ = localToWorld(node, minX, yOffset, maxZ)
local rightFrontX, rightFrontY, rightFrontZ = localToWorld(node, maxX, yOffset, maxZ)
local leftBackX, leftBackY, leftBackZ = localToWorld(node, minX, yOffset, minZ)
local rightBackX, rightBackY, rightBackZ = localToWorld(node, maxX, yOffset, minZ)
drawDebugLine(leftFrontX, leftFrontY, leftFrontZ, r, g, b, rightFrontX, rightFrontY, rightFrontZ, r, g, b)
drawDebugLine(rightFrontX, rightFrontY, rightFrontZ, r, g, b, rightBackX, rightBackY, rightBackZ, r, g, b)
drawDebugLine(rightBackX, rightBackY, rightBackZ, r, g, b, leftBackX, leftBackY, leftBackZ, r, g, b)
drawDebugLine(leftBackX, leftBackY, leftBackZ, r, g, b, leftFrontX, leftFrontY, leftFrontZ, r, g, b)
-- unloading area
local offx, offY, offZ = unpack(spec.UnloadOffset[spec.currentTipside])
minX = minX + offx;
maxX = maxX + offx;
maxZ = maxZ + offZ;
minZ = minZ + offZ;
yOffset = yOffset + offY;
leftFrontX, leftFrontY, leftFrontZ = localToWorld(node, minX, yOffset, maxZ)
rightFrontX, rightFrontY, rightFrontZ = localToWorld(node, maxX, yOffset, maxZ)
leftBackX, leftBackY, leftBackZ = localToWorld(node, minX, yOffset, minZ)
rightBackX, rightBackY, rightBackZ = localToWorld(node, maxX, yOffset, minZ)
drawDebugLine(leftFrontX, leftFrontY, leftFrontZ, r, g, b, rightFrontX, rightFrontY, rightFrontZ, r, g, b)
drawDebugLine(rightFrontX, rightFrontY, rightFrontZ, r, g, b, rightBackX, rightBackY, rightBackZ, r, g, b)
drawDebugLine(rightBackX, rightBackY, rightBackZ, r, g, b, leftBackX, leftBackY, leftBackZ, r, g, b)
drawDebugLine(leftBackX, leftBackY, leftBackZ, r, g, b, leftFrontX, leftFrontY, leftFrontZ, r, g, b)
-- loadplaces
local autoLoadType = spec.autoLoadTypes[spec.currentautoLoadTypeIndex];
local loadPlaces = spec.autoLoadTypes[spec.currentautoLoadTypeIndex].places;
for i=1, #loadPlaces do
local loadPlace = loadPlaces[i]
-- square
if autoLoadType.type == "roundbale" then
local radius = autoLoadType.sizeX/2;
local vertical = false;
local offset = nil;
local color = {r,g,b};
DebugUtil.drawDebugCircleAtNode(loadPlace.node, radius, 12, color, vertical, offset)
elseif autoLoadType.type == "squarebale" then
-- switch sizeZ and sizeX here because it is used 90° turned
local sizeX = autoLoadType.sizeZ/2;
local sizeZ = autoLoadType.sizeX/2;
DebugUtil.drawDebugRectangle(loadPlace.node, -sizeX, sizeX, -sizeZ, sizeZ, 0, r, g, b)
else
local sizeX = autoLoadType.sizeX/2;
local sizeZ = autoLoadType.sizeZ/2;
DebugUtil.drawDebugRectangle(loadPlace.node, -sizeX, sizeX, -sizeZ, sizeZ, 0, r, g, b)
end
-- overlapBox malen
if APalletAutoLoader.debug then
-- center node
DebugUtil.drawDebugReferenceAxisFromNode(loadPlace.node);
local currentLoadHeigt = 0;
local x, y, z = localToWorld(loadPlace.node, 0, currentLoadHeigt, 0);
local rx, ry, rz = getWorldRotation(loadPlace.node)
if autoLoadType.type == "roundbale" then
local squareLength = (autoLoadType.sizeX / 2) * math.sqrt(2);
DebugUtil.drawOverlapBox(x, y + (autoLoadType.sizeY / 2), z, rx, ry, rz, squareLength / 2, autoLoadType.sizeY / 2, squareLength / 2, r, g, b)
elseif autoLoadType.type == "squarebale" then
-- switch sizeZ and sizeX here because it is used 90° turned
DebugUtil.drawOverlapBox(x, y + (autoLoadType.sizeY / 2), z, rx, ry, rz, autoLoadType.sizeZ / 2, autoLoadType.sizeY / 2, autoLoadType.sizeX / 2, r, g, b)
else
DebugUtil.drawOverlapBox(x, y + (autoLoadType.sizeY / 2), z, rx, ry, rz, autoLoadType.sizeX / 2, autoLoadType.sizeY / 2, autoLoadType.sizeZ / 2, r, g, b)
end
end
end
end
end
function APalletAutoLoader:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection)
if self.isClient then
local spec = self.spec_aPalletAutoLoader
if spec == nil then
return;
end
if spec.actionEvents == nil then
spec.actionEvents = {}
else
self:clearActionEventsTable(spec.actionEvents)
end
if isActiveForInput then
local _, actionEventId = self:addActionEvent(spec.actionEvents, InputAction.AL_LOAD_PALLET, self, APalletAutoLoader.actionEventToggleLoading, false, true, false, true, nil, nil, true, true)
g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_VERY_HIGH)
spec.toggleLoadingActionEventId = actionEventId;
local _, actionEventId2 = self:addActionEvent(spec.actionEvents, InputAction.AL_TOGGLE_LOADINGTYPE, self, APalletAutoLoader.actionEventToggleAutoLoadTypes, false, true, false, true, nil, nil, true, true)
g_inputBinding:setActionEventTextPriority(actionEventId2, GS_PRIO_VERY_HIGH)
spec.toggleAutoLoadTypesActionEventId = actionEventId2;
local _, actionEventId2Back = self:addActionEvent(spec.actionEvents, InputAction.AL_TOGGLE_LOADINGTYPEBACK, self, APalletAutoLoader.actionEventToggleAutoLoadTypesBack, false, true, false, true, nil, nil, true, true)
g_inputBinding:setActionEventTextPriority(actionEventId2Back, GS_PRIO_NORMAL)
spec.toggleAutoLoadTypesBackActionEventId = actionEventId2Back;
local _, actionEventId3 = self:addActionEvent(spec.actionEvents, InputAction.AL_TOGGLE_TIPSIDE, self, APalletAutoLoader.actionEventToggleTipside, false, true, false, true, nil, nil, true, true)
g_inputBinding:setActionEventTextPriority(actionEventId3, GS_PRIO_HIGH)
spec.toggleTipsideActionEventId = actionEventId3;
local _, actionEventId4 = self:addActionEvent(spec.actionEvents, InputAction.AL_UNLOAD, self, APalletAutoLoader.actionEventUnloadAll, false, true, false, true, nil, nil, true, true)
g_inputBinding:setActionEventTextPriority(actionEventId4, GS_PRIO_HIGH)
spec.unloadAllEventId = actionEventId4;
local _, actionEventId5 = self:addActionEvent(spec.actionEvents, InputAction.AL_TOGGLE_MARKERS, self, APalletAutoLoader.actionEventToggleMarkers, false, true, false, true, nil, nil, true, true),
g_inputBinding:setActionEventTextPriority(actionEventId5, GS_PRIO_HIGH);
spec.toggleMarkerEventId = actionEventId5;
local _, actionEventId6 = self:addActionEvent(spec.actionEvents, InputAction.AL_TOGGLE_AUTOMATIC_TENSIONBELTS, self, APalletAutoLoader.actionEventToggleAutomaticTensionBelts, false, true, false, true, nil, nil, true, true);
g_inputBinding:setActionEventTextPriority(actionEventId6, GS_PRIO_HIGH);
spec.toggleAutomaticTensionBeltsEventId = actionEventId6;
local _, actionEventIdMoveUpDown = self:addActionEvent(spec.actionEvents, InputAction.AL_UNLOADAREA_MOVE_UPDOWN, self, APalletAutoLoader.actionEventUnloadAreaMoveUpDown, false, true, true, true, nil);
g_inputBinding:setActionEventTextPriority(actionEventIdMoveUpDown, GS_PRIO_HIGH);
spec.actionEventIdMoveUpDown = actionEventIdMoveUpDown;
g_inputBinding:setActionEventText(actionEventIdMoveUpDown, g_i18n:getText("input_AL_UNLOADAREA_MOVE_UPDOWN"));
local _, actionEventIdMoveLeftRight = self:addActionEvent(spec.actionEvents, InputAction.AL_UNLOADAREA_MOVE_LEFTRIGHT, self, APalletAutoLoader.actionEventUnloadAreaMoveLeftRight, false, true, true, true, nil);
g_inputBinding:setActionEventTextPriority(actionEventIdMoveLeftRight, GS_PRIO_HIGH);
spec.actionEventIdMoveLeftRight = actionEventIdMoveLeftRight;
g_inputBinding:setActionEventText(actionEventIdMoveLeftRight, g_i18n:getText("input_AL_UNLOADAREA_MOVE_LEFTRIGHT"));
local _, actionEventIdMoveFrontBack = self:addActionEvent(spec.actionEvents, InputAction.AL_UNLOADAREA_MOVE_FRONTBACK, self, APalletAutoLoader.actionEventUnloadAreaMoveFrontBack, false, true, true, true, nil);
g_inputBinding:setActionEventTextPriority(actionEventIdMoveFrontBack, GS_PRIO_HIGH);
spec.actionEventIdMoveFrontBack = actionEventIdMoveFrontBack;
g_inputBinding:setActionEventText(actionEventIdMoveFrontBack, g_i18n:getText("input_AL_UNLOADAREA_MOVE_FRONTBACK"));
local _, automaticAutoLoadTypeActionEventId = self:addActionEvent(spec.actionEvents, InputAction.AL_AUTOMATIC_LOADINGTYPE, self, APalletAutoLoader.actionEventAutomaticLoadTypes, false, true, false, true, nil, nil, true, true)
g_inputBinding:setActionEventTextPriority(automaticAutoLoadTypeActionEventId, GS_PRIO_VERY_HIGH)
spec.automaticAutoLoadTypeActionEventId = automaticAutoLoadTypeActionEventId;
g_inputBinding:setActionEventText(automaticAutoLoadTypeActionEventId, g_i18n:getText("input_AL_AUTOMATIC_LOADINGTYPE"));
APalletAutoLoader.updateActionText(self);
end
end
end
function APalletAutoLoader.actionEventUnloadAreaMoveLeftRight(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader;
self:ChangeShowMarkers(true);
spec.UnloadOffset[spec.currentTipside][1] = spec.UnloadOffset[spec.currentTipside][1] + (inputValue/50);
end
function APalletAutoLoader.actionEventUnloadAreaMoveUpDown(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader;
self:ChangeShowMarkers(true);
spec.UnloadOffset[spec.currentTipside][2] = spec.UnloadOffset[spec.currentTipside][2] + (inputValue/50) ;
end
function APalletAutoLoader.actionEventUnloadAreaMoveFrontBack(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader;
self:ChangeShowMarkers(true);
spec.UnloadOffset[spec.currentTipside][3] = spec.UnloadOffset[spec.currentTipside][3] + (inputValue/50);
end
function APalletAutoLoader.updateActionText(self)
if self.isClient then
local spec = self.spec_aPalletAutoLoader
if not spec.available then
g_inputBinding:setActionEventActive(spec.toggleLoadingActionEventId, false)
g_inputBinding:setActionEventActive(spec.automaticAutoLoadTypeActionEventId, false)
g_inputBinding:setActionEventActive(spec.toggleAutoLoadTypesActionEventId, false)
g_inputBinding:setActionEventActive(spec.toggleAutoLoadTypesBackActionEventId, false)
g_inputBinding:setActionEventActive(spec.toggleTipsideActionEventId, false)
g_inputBinding:setActionEventActive(spec.unloadAllEventId, false)
g_inputBinding:setActionEventActive(spec.toggleMarkerEventId, false)
g_inputBinding:setActionEventActive(spec.toggleAutomaticTensionBeltsEventId, false)
g_inputBinding:setActionEventActive(spec.actionEventIdMoveUpDown, false)
g_inputBinding:setActionEventActive(spec.actionEventIdMoveLeftRight, false)
g_inputBinding:setActionEventActive(spec.actionEventIdMoveFrontBack, false)
return;
end
-- different texts for the toggle loading key
local text;
if spec.loadingState == APalletAutoLoaderLoadingState.STOPPED then
text = g_i18n:getText("aPalletAutoLoader_startLoading")
else
text = g_i18n:getText("aPalletAutoLoader_stopLoading")
end
if spec.objectsToLoadCount ~= 0 then text = text .. ": " .. spec.objectsToLoadCount end
g_inputBinding:setActionEventText(spec.toggleLoadingActionEventId, text)
-- this line to have the loading always active
g_inputBinding:setActionEventActive(spec.toggleLoadingActionEventId, true)
-- this line to have loading only active when there is something in range, in code for private versions which wants to not activate loading always
-- g_inputBinding:setActionEventActive(spec.toggleLoadingActionEventId, spec.objectsToLoadCount ~= 0 or spec.numTriggeredObjects ~= 0)
local loadingText = ""
if (spec.autoLoadTypes == nil or spec.autoLoadTypes[spec.currentautoLoadTypeIndex] == nil) then
loadingText = g_i18n:getText("aPalletAutoLoader_LoadingType") .. ": " .. "unknown"
else
loadingText = g_i18n:getText("aPalletAutoLoader_LoadingType") .. ": " .. spec.autoLoadTypes[spec.currentautoLoadTypeIndex].nameTranslated
end
g_inputBinding:setActionEventText(spec.toggleAutoLoadTypesActionEventId, loadingText)
g_inputBinding:setActionEventText(spec.toggleTipsideActionEventId, spec.tipsideText)
local tensionBeltText = g_i18n:getText("aPalletAutoLoader_TensionBeltsNotActive");
if spec.useTensionBelts then
tensionBeltText = g_i18n:getText("aPalletAutoLoader_TensionBeltsActive");
end
g_inputBinding:setActionEventText(spec.toggleAutomaticTensionBeltsEventId, tensionBeltText)
-- deactivate when somthing is already loaded or not
g_inputBinding:setActionEventActive(spec.toggleAutoLoadTypesActionEventId, spec.numTriggeredObjects == 0 and spec.loadingState == APalletAutoLoaderLoadingState.STOPPED)
g_inputBinding:setActionEventActive(spec.toggleAutoLoadTypesBackActionEventId, spec.numTriggeredObjects == 0 and spec.loadingState == APalletAutoLoaderLoadingState.STOPPED)
g_inputBinding:setActionEventActive(spec.automaticAutoLoadTypeActionEventId, spec.numTriggeredObjects == 0 and spec.loadingState == APalletAutoLoaderLoadingState.STOPPED and spec.objectsToLoadCount ~= 0)
g_inputBinding:setActionEventActive(spec.unloadAllEventId, spec.numTriggeredObjects ~= 0)
g_inputBinding:setActionEventActive(spec.actionEventIdMoveUpDown, spec.numTriggeredObjects ~= 0 and spec.showMarkers)
g_inputBinding:setActionEventActive(spec.actionEventIdMoveLeftRight, spec.numTriggeredObjects ~= 0 and spec.showMarkers)
g_inputBinding:setActionEventActive(spec.actionEventIdMoveFrontBack, spec.numTriggeredObjects ~= 0 and spec.showMarkers)
g_inputBinding:setActionEventActive(spec.toggleMarkerEventId, true)
g_inputBinding:setActionEventActive(spec.toggleAutomaticTensionBeltsEventId, not spec.showMarkers)
end
end
function APalletAutoLoader.actionEventToggleLoading(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader
if spec.loadingState == APalletAutoLoaderLoadingState.STOPPED then
SetAutoloadStateEvent.sendEvent(self, APalletAutoLoaderLoadingState.RUNNING)
else
SetAutoloadStateEvent.sendEvent(self, APalletAutoLoaderLoadingState.STOPPED)
end
end
function APalletAutoLoader:SetLoadingState(newLoadingState)
local spec = self.spec_aPalletAutoLoader
spec.loadingState = newLoadingState;
spec.usedPositions = {};
if self.isClient then
-- nur beim Client aufrufen, Wenn ein Server im Spiel ist kommt das über die Sync
APalletAutoLoader.updateActionText(self);
end
if self.isServer then
-- Starten des Ladetimers, wenn der neue Status aktiv ist
if spec.loadingState == APalletAutoLoaderLoadingState.RUNNING then
self:StartLoading();
else
-- release all joints
local releasedOneJoint = false;
for _,jointData in pairs(spec.objectsToJoint) do
removeJoint(jointData.jointIndex)
delete(jointData.jointTransform)
releasedOneJoint = true;
jointData.object.tensionMountObject = nil;
end
spec.objectsToJoint = {};
-- start tension belts time if needed
if releasedOneJoint == true and spec.useTensionBelts then
spec.beltsTimer:start(false);
self:setAllTensionBeltsActive(false, false)
end
end
end
end
function APalletAutoLoader:StartLoading()
local spec = self.spec_aPalletAutoLoader
if (spec.loadTimer:getIsRunning()) then return end;
spec.isFullLoaded = false;
spec.loadTimer:start(false);
end
function APalletAutoLoader:GetAutoloadTypes()
local spec = self.spec_aPalletAutoLoader;
return spec.autoLoadTypes;
end
function APalletAutoLoader.actionEventAutomaticLoadTypes(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader
SetAutoloadTypeAutomaticEvent.sendEvent(self)
end
--- Select automatic a fitting loading type for a object in range.
function APalletAutoLoader:SetAutoloadTypeAutomatic()
local spec = self.spec_aPalletAutoLoader
local newAutoLoadTypeIndex = nil;
for _, object in pairs(spec.objectsToLoad) do
for autoLoadTypeIndex, autoLoadType in pairs(spec.autoLoadTypes) do
local isValidLoadType = autoLoadType.CheckTypeMethod(object);
if isValidLoadType then
newAutoLoadTypeIndex = autoLoadTypeIndex;
goto newAutoLoadTypeIndexSet
end
end
end
for object,_ in pairs(spec.balesToLoad) do
for autoLoadTypeIndex, autoLoadType in pairs(spec.autoLoadTypes) do
local isValidLoadType = autoLoadType.CheckTypeMethod(object);
if isValidLoadType then
newAutoLoadTypeIndex = autoLoadTypeIndex;
goto newAutoLoadTypeIndexSet
end
end
end
:: newAutoLoadTypeIndexSet ::
if newAutoLoadTypeIndex ~= nil then
SetAutoloadTypeEvent.sendEvent(self, newAutoLoadTypeIndex)
end
end
function APalletAutoLoader.actionEventToggleAutoLoadTypes(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader
local newAutoLoadTypeIndex;
if spec.currentautoLoadTypeIndex >= #spec.autoLoadTypes then
newAutoLoadTypeIndex = 1;
else
newAutoLoadTypeIndex = spec.currentautoLoadTypeIndex + 1;
end
SetAutoloadTypeEvent.sendEvent(self, newAutoLoadTypeIndex)
end
function APalletAutoLoader.actionEventToggleAutoLoadTypesBack(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader
local newAutoLoadTypeIndex;
if spec.currentautoLoadTypeIndex == 1 then
newAutoLoadTypeIndex = #spec.autoLoadTypes;
else
newAutoLoadTypeIndex = spec.currentautoLoadTypeIndex - 1;
end
SetAutoloadTypeEvent.sendEvent(self, newAutoLoadTypeIndex)
end
function APalletAutoLoader:SetAutoloadType(newAutoLoadTypeIndex)
local spec = self.spec_aPalletAutoLoader
spec.currentautoLoadTypeIndex = newAutoLoadTypeIndex;
self:SetPickupTriggerCollisionMask()
if self.isClient then
-- nur beim Client aufrufen, Wenn ein Server im Spiel ist kommt das über die Sync
APalletAutoLoader.updateActionText(self);
end
end
function APalletAutoLoader.actionEventToggleTipside(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader;
if not spec.showMarkers then
self:ChangeShowMarkers(true);
else
local newTipside = APalletAutoLoaderTipsides.LEFT;
if spec.currentTipside == APalletAutoLoaderTipsides.LEFT then
newTipside = APalletAutoLoaderTipsides.RIGHT;
elseif spec.currentTipside == APalletAutoLoaderTipsides.RIGHT then
newTipside = APalletAutoLoaderTipsides.BACK;
end
self:ChangeShowMarkers(true);
SetTipsideEvent.sendEvent(self, newTipside);
end
end
function APalletAutoLoader:SetTipside(tipsideIndex)
local spec = self.spec_aPalletAutoLoader
spec.currentTipside = tipsideIndex;
spec.tipsideText = g_i18n:getText("aPalletAutoLoader_tipside") .. ": " .. g_i18n:getText("aPalletAutoLoader_" .. spec.currentTipside)
if self.isClient then
-- nur beim Client aufrufen, Wenn ein Server im Spiel ist kommt das über die Sync
APalletAutoLoader.updateActionText(self);
end
end
function APalletAutoLoader.actionEventToggleMarkers(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader
self:ChangeShowMarkers(not spec.showMarkers);
end
function APalletAutoLoader:ChangeShowMarkers(newShowMarkers)
local spec = self.spec_aPalletAutoLoader
spec.showMarkers = newShowMarkers;
if self.isClient then
-- nur beim Client aufrufen, wird auf Server ja nicht gezeigt
APalletAutoLoader.updateActionText(self);
end
end
function APalletAutoLoader.actionEventUnloadAll(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader;
self:ChangeShowMarkers(false);
if not self.isServer then
-- Entladebefehl in den stream schreiben mit entladeseite
spec.callUnloadAll = true;
self:raiseDirtyFlags(spec.dirtyFlag);
else
self:unloadAll(spec.UnloadOffset[spec.currentTipside]);
if (spec.UnloadOffsetOriginal ~= nil and spec.UnloadOffsetOriginal[spec.currentTipside] ~= nil) then
spec.UnloadOffset[spec.currentTipside] = {unpack(spec.UnloadOffsetOriginal[spec.currentTipside])};
end
APalletAutoLoader.updateActionText(self);
end
end
function APalletAutoLoader.actionEventToggleAutomaticTensionBelts(self, actionName, inputValue, callbackState, isAnalog)
local spec = self.spec_aPalletAutoLoader
SetAutomaticTensionBeltsEvent.sendEvent(self, not spec.useTensionBelts)
end
function APalletAutoLoader:SetTensionBeltsValue(newTensionBeltsValue)
local spec = self.spec_aPalletAutoLoader
spec.useTensionBelts = newTensionBeltsValue;
if self.isClient then
-- nur beim Client aufrufen, Wenn ein Server im Spiel ist kommt das über die Sync
APalletAutoLoader.updateActionText(self);
end
end
---Called on loading
-- @param table savegame savegame
function APalletAutoLoader:onLoad(savegame)
APalletAutoLoader.print("onLoad(%s)", savegame);
print("init aPalletAutoLoader");
local aPalletAutoLoaderConfigurationId = Utils.getNoNil(self.configurations["aPalletAutoLoader"], 1)
local baseXmlPath = string.format("vehicle.aPalletAutoLoader.APalletAutoLoaderConfigurations.APalletAutoLoaderConfiguration(%d)", aPalletAutoLoaderConfigurationId -1)
-- hier für server und client
self.spec_aPalletAutoLoader = {}
local spec = self.spec_aPalletAutoLoader
spec.callUnloadAll = false;
spec.objectsToLoadCount = 0;
spec.dirtyFlag = self:getNextDirtyFlag()
spec.numTriggeredObjects = 0
spec.isFullLoaded = false;
spec.currentTipside = APalletAutoLoaderTipsides.LEFT;
spec.tipsideText = g_i18n:getText("aPalletAutoLoader_tipside") .. ": " .. g_i18n:getText("aPalletAutoLoader_" .. spec.currentTipside)
spec.currentautoLoadTypeIndex = 1;
spec.available = false;
spec.showMarkers = false;
spec.loadingState = APalletAutoLoaderLoadingState.STOPPED;
spec.useTensionBelts = false;
spec.tensionBeltsDelay = 210;
spec.usePalletWeightReduction = true
spec.autoLoadObjectSettings = {}
if g_dedicatedServer ~= nil then
spec.tensionBeltsDelay = 1500;
end
-- load the loading area
spec.loadArea = {};
spec.loadArea["baseNode"] = self.xmlFile:getValue(baseXmlPath..".loadArea#baseNode", nil, self.components, self.i3dMappings);
spec.loadArea["leftRightCornerOffset"] = self.xmlFile:getValue(baseXmlPath .. ".loadArea#leftRightCornerOffset", "0 0 0", true);
spec.loadArea["lenght"] = self.xmlFile:getValue(baseXmlPath .. ".loadArea#lenght") or 5
spec.loadArea["height"] = self.xmlFile:getValue(baseXmlPath .. ".loadArea#height") or 2
spec.loadArea["width"] = self.xmlFile:getValue(baseXmlPath .. ".loadArea#width") or 2
spec.maxObjects = self.xmlFile:getValue(baseXmlPath .. "#maxObjects") or 50
spec.usePalletWeightReduction = self.xmlFile:getBool(baseXmlPath .. "#usePalletWeightReduction", spec.usePalletWeightReduction);
spec.UnloadOffset = {}
spec.UnloadOffsetOriginal = {}
spec.UnloadOffset[APalletAutoLoaderTipsides.RIGHT] = self.xmlFile:getValue(baseXmlPath .. "#UnloadRightOffset", "-" .. (spec.loadArea["width"]+1) .. " -0.5 0", true)
spec.UnloadOffsetOriginal[APalletAutoLoaderTipsides.RIGHT] = {unpack(spec.UnloadOffset[APalletAutoLoaderTipsides.RIGHT])}
spec.UnloadOffset[APalletAutoLoaderTipsides.LEFT] = self.xmlFile:getValue(baseXmlPath .. "#UnloadLeftOffset", (spec.loadArea["width"]+1) .. " -0.5 0", true)
spec.UnloadOffsetOriginal[APalletAutoLoaderTipsides.LEFT] = {unpack(spec.UnloadOffset[APalletAutoLoaderTipsides.LEFT])}
spec.UnloadOffset[APalletAutoLoaderTipsides.MIDDLE] = self.xmlFile:getValue(baseXmlPath .. "#UnloadMiddleOffset", "0 0 0", true)
spec.UnloadOffsetOriginal[APalletAutoLoaderTipsides.MIDDLE] = {unpack(spec.UnloadOffset[APalletAutoLoaderTipsides.MIDDLE])}
spec.UnloadOffset[APalletAutoLoaderTipsides.BACK] = self.xmlFile:getValue(baseXmlPath .. "#UnloadBackOffset", "0 -0.5 -" .. (spec.loadArea["lenght"]+1), true)
spec.UnloadOffsetOriginal[APalletAutoLoaderTipsides.BACK] = {unpack(spec.UnloadOffset[APalletAutoLoaderTipsides.BACK])}
if spec.loadArea["baseNode"] == nil then
APalletAutoLoader:removeUnusedEventListener(self, "onDelete", APalletAutoLoader)
APalletAutoLoader:removeUnusedEventListener(self, "onRegisterActionEvents", APalletAutoLoader)
APalletAutoLoader:removeUnusedEventListener(self, "onReadUpdateStream", APalletAutoLoader)
APalletAutoLoader:removeUnusedEventListener(self, "onWriteUpdateStream", APalletAutoLoader)
APalletAutoLoader:removeUnusedEventListener(self, "onDraw", APalletAutoLoader)
APalletAutoLoader:removeUnusedEventListener(self, "onAIImplementStart", APalletAutoLoader)
APalletAutoLoader:removeUnusedEventListener(self, "onAIImplementEnd", APalletAutoLoader)
APalletAutoLoader:removeUnusedEventListener(self, "onAIFieldWorkerStart", APalletAutoLoader)
APalletAutoLoader:removeUnusedEventListener(self, "onAIFieldWorkerEnd", APalletAutoLoader)
return;
end
local i = 0
while true do
local autoLoadObjectKey = string.format(baseXmlPath .. ".autoLoadObjectSettings.autoLoadObjectSetting(%d)", i)
if not self.xmlFile:hasProperty(autoLoadObjectKey) then
break
end
local autoLoadObjectSetting = {}
autoLoadObjectSetting.name = self.xmlFile:getValue(autoLoadObjectKey .. "#name", "x")
if autoLoadObjectSetting.name == "x" then
Logging.xmlWarning(self.xmlFile, "autoLoadObjectSetting has no name");
else
autoLoadObjectSetting.maxObjects = self.xmlFile:getValue(autoLoadObjectKey .. "#maxObjects", spec.maxObjects);
autoLoadObjectSetting.leftRightCornerOffset = self.xmlFile:getValue(autoLoadObjectKey .. "#leftRightCornerOffset", nil, true) or spec.loadArea["leftRightCornerOffset"];
autoLoadObjectSetting.lenght = self.xmlFile:getValue(autoLoadObjectKey .. "#lenght", spec.loadArea["lenght"]);
autoLoadObjectSetting.height = self.xmlFile:getValue(autoLoadObjectKey .. "#height", spec.loadArea["height"]);
autoLoadObjectSetting.width = self.xmlFile:getValue(autoLoadObjectKey .. "#width", spec.loadArea["width"]);
spec.autoLoadObjectSettings[autoLoadObjectSetting.name] = autoLoadObjectSetting;
end
i = i + 1
end
spec.available = true;
spec.useBales = self.xmlFile:getValue(baseXmlPath .. "#useBales", false)
local types = self:CreateAvailableTypeList();
-- create loadplaces automatically from load Area size
if spec.loadArea["baseNode"] ~= nil then
spec.autoLoadTypes = {};
spec.palletShopText = {};
spec.roundBaleShopText = {};
spec.squareBaleShopText = {};
for i,name in ipairs(types) do
APalletAutoLoader.print("process %s", name);
local autoLoadObject = {}
autoLoadObject.index = spec.loadArea["baseNode"]
autoLoadObject.name = name
APalletAutoLoader:AddSupportedObjects(autoLoadObject, name)
if autoLoadObject.nameTranslated == nil then
autoLoadObject.nameTranslated = g_i18n:getText("aPalletAutoLoader_" .. name)
end
if autoLoadObject.sizeX == nil then
Logging.error("'%s' missing in 'APalletAutoLoader:AddSupportedObjects()' result", name)
return;
end
-- load from settings if available, otherwise base data
local leftRightCornerOffsetForObjectType = spec.loadArea["leftRightCornerOffset"];
local heightForObjectType = MathUtil.round(spec.loadArea["height"], 2);
local lenghtForObjectType = MathUtil.round(spec.loadArea["lenght"], 2);
local widthForObjectType = MathUtil.round(spec.loadArea["width"], 2);
if spec.autoLoadObjectSettings[name] ~= nil then
leftRightCornerOffsetForObjectType = spec.autoLoadObjectSettings[name].leftRightCornerOffset;
lenghtForObjectType = MathUtil.round(spec.autoLoadObjectSettings[name].lenght, 2);
heightForObjectType = MathUtil.round(spec.autoLoadObjectSettings[name].height, 2);
widthForObjectType = MathUtil.round(spec.autoLoadObjectSettings[name].width, 2);
end
APalletAutoLoader.print("lenghtForObjectType: %s", lenghtForObjectType);
autoLoadObject.places = {}
local cornerX,cornerY,cornerZ = unpack(leftRightCornerOffsetForObjectType);
-- paletten nebeneinander bestimmen
-- vieviele passen ohne drehung?
local restFirstNoRotation = MathUtil.round((widthForObjectType - autoLoadObject.sizeX) % (autoLoadObject.sizeX + 0.05), 2);
local countNoRotation = MathUtil.round((widthForObjectType - autoLoadObject.sizeX - restFirstNoRotation) / (autoLoadObject.sizeX + 0.05) + 1, 2);
APalletAutoLoader.print("restFirstNoRotation: %s - countNoRotation: %s", restFirstNoRotation, countNoRotation);
-- vie viele passen mit drehung?
local restFirstRotation = MathUtil.round((widthForObjectType - autoLoadObject.sizeZ) % (autoLoadObject.sizeZ + 0.05), 2);
local countRotation = MathUtil.round((widthForObjectType - autoLoadObject.sizeZ - restFirstRotation) / (autoLoadObject.sizeZ + 0.05) + 1, 2);
APalletAutoLoader.print("restFirstRotation: %s - countRotation: %s", restFirstRotation, countRotation);
-- wie viele passen wenn eine mit drehung gemacht wird?
local restOneRotation = MathUtil.round((widthForObjectType - autoLoadObject.sizeX - autoLoadObject.sizeZ - 0.05) % (autoLoadObject.sizeX + 0.05), 2);
local countOneRotation = MathUtil.round((widthForObjectType - autoLoadObject.sizeX - restOneRotation - autoLoadObject.sizeZ - 0.05) / (autoLoadObject.sizeX + 0.05) + 2, 2);
APalletAutoLoader.print("restOneRotation: %s - countOneRotation: %s", restOneRotation, countOneRotation);
local backDistance = 0.05;
if autoLoadObject.type == "roundbale" then
-- rundballen ein bischen mehr platz geben wegen der runden kollision
backDistance = 0.07;
end
local loadingPattern = {}
if restFirstNoRotation <= restFirstRotation or autoLoadObject.type == "roundbale" then
APalletAutoLoader.print("load without rotation");
-- auladen ohne rotation, heißt also quer zur Ladefläche
-- rundballen generell hier, weil sind ja rund
if autoLoadObject.type == "roundbale" and countNoRotation == 1 then
APalletAutoLoader.print("roundbale with countNoRotation = 1 ");
-- wenn rundballen und noch genug platz, versetzt laden um mehr auf die fläche zu bekommen
-- hierbei aber nur, wenn die restfläche mindestens so viel ist, wie der halbe durchmesser zur einfachen Verteilung, komplexer kann später
-- position der zwei reihen
local rowX1 = (cornerX - (autoLoadObject.sizeX / 2))
local rowX2 = (cornerX - widthForObjectType + (autoLoadObject.sizeX / 2))
-- abweichende distanz berechnen aus dem abstand der beiden Reihen und dem durchmesser
-- a² + b² = c²
-- a = wurzel aus c² - b²
local optimalDistanceZ = math.sqrt(math.pow(autoLoadObject.sizeX + backDistance, 2) - math.pow((rowX1 - rowX2), 2)) * 2;
-- minimale distanz nur aus der größe und en abstand
local minimalDistanceZ = (autoLoadObject.sizeZ + backDistance);
-- die höhere der beiden distanzen muss benutzt werden
local distanceZ = math.max(optimalDistanceZ, minimalDistanceZ);
-- schleifen bis zur länge links und rechts ausgericht
-- linke seite
for colPos = (autoLoadObject.sizeZ / 2), lenghtForObjectType, distanceZ do
if (colPos + (autoLoadObject.sizeZ / 2)) <= lenghtForObjectType then
local loadingPatternItem = {}
loadingPatternItem.rotation = 0;
loadingPatternItem.posX = rowX1
loadingPatternItem.posZ = cornerZ - colPos
table.insert(loadingPattern, loadingPatternItem)
end
end
-- rechte seite
-- 2. reihe um die hälfte des abstandes nach hinten schieben
for colPos = (autoLoadObject.sizeZ / 2) + (distanceZ / 2), lenghtForObjectType, distanceZ do
if (colPos + (autoLoadObject.sizeZ / 2)) <= lenghtForObjectType then
local loadingPatternItem = {}
loadingPatternItem.rotation = 0;
loadingPatternItem.posX = rowX2
loadingPatternItem.posZ = cornerZ - colPos
table.insert(loadingPattern, loadingPatternItem)
end
end
else
APalletAutoLoader.print("not roundbale with countNoRotation = %s", countNoRotation);
for rowNumber = 0, (countNoRotation-1) do
APalletAutoLoader.print("rowNumber = %s", rowNumber);
-- schleife bis zur länge
for colPos = (autoLoadObject.sizeZ / 2), (lenghtForObjectType + backDistance), (autoLoadObject.sizeZ + backDistance) do
APalletAutoLoader.print("colPos = %s", colPos);
if (colPos + (autoLoadObject.sizeZ / 2)) <= lenghtForObjectType then
local loadingPatternItem = {}
loadingPatternItem.rotation = 0;
loadingPatternItem.posX = cornerX - (autoLoadObject.sizeX / 2) - (rowNumber * (autoLoadObject.sizeX + backDistance)) - (restFirstNoRotation / 2)
loadingPatternItem.posZ = cornerZ - colPos
table.insert(loadingPattern, loadingPatternItem)
end
end
end
end
elseif restOneRotation < restFirstRotation and countOneRotation >= 2 then
-- aufladen wobei die ersten quer und die letzt längs geladen wird.
-- erst mal die quer einfügen mit verschobenem Zentrum
local maxPosX = math.huge;
for rowNumber = 0, (countOneRotation-2) do
-- schleife bis zur länge
for colPos = (autoLoadObject.sizeZ / 2), (lenghtForObjectType + backDistance), (autoLoadObject.sizeZ + backDistance) do
if (colPos + (autoLoadObject.sizeZ / 2)) <= lenghtForObjectType then
local loadingPatternItem = {}
loadingPatternItem.rotation = 0;
loadingPatternItem.posX = cornerX - (autoLoadObject.sizeX / 2) - (rowNumber * (autoLoadObject.sizeX + backDistance)) - (restOneRotation / 2)
loadingPatternItem.posZ = cornerZ - colPos
table.insert(loadingPattern, loadingPatternItem)
if loadingPatternItem.posX < maxPosX then maxPosX = loadingPatternItem.posX end
end
end
end
-- jetzt die eine reihe längs auch als schleife bis zur länge
for colPos = (autoLoadObject.sizeX / 2), (lenghtForObjectType + backDistance), (autoLoadObject.sizeX + backDistance) do
if (colPos + (autoLoadObject.sizeX / 2)) <= lenghtForObjectType then
local loadingPatternItem = {}
loadingPatternItem.rotation = math.rad(90);
-- loadingPatternItem.posX = cornerX - (autoLoadObject.sizeX / 2) - ((countOneRotation-1) * (autoLoadObject.sizeX + backDistance)) - (restOneRotation / 2)
loadingPatternItem.posX = maxPosX - (autoLoadObject.sizeX / 2) - (autoLoadObject.sizeZ / 2) - backDistance;
loadingPatternItem.posZ = cornerZ - colPos
table.insert(loadingPattern, loadingPatternItem)
end
end
else
-- aufladen mit rotation, heißt also längs zur Ladefläche
local countCol = 0;
for rowNumber = 0, (countRotation-1) do
-- schleife bis zur länge
for colPos = (autoLoadObject.sizeX / 2), (lenghtForObjectType + backDistance), (autoLoadObject.sizeX + backDistance) do
if (colPos + (autoLoadObject.sizeX / 2)) <= lenghtForObjectType then
local loadingPatternItem = {}
loadingPatternItem.rotation = math.rad(90);
loadingPatternItem.posX = cornerX - (autoLoadObject.sizeZ / 2) - (rowNumber * (autoLoadObject.sizeZ + backDistance)) - (restFirstRotation / 2)
loadingPatternItem.posZ = cornerZ - colPos
table.insert(loadingPattern, loadingPatternItem)
if rowNumber == 0 then
countCol = countCol + 1
end
end
end
end
-- jetzt könnte aber noch quer was dahinter passen, gleiche logik wie bei quer laden, nur später anfangen
for rowNumber = 0, (countNoRotation-1) do
-- schleife bis zur länge
for colPos = (autoLoadObject.sizeZ / 2) + (countCol * (autoLoadObject.sizeX + backDistance)), (lenghtForObjectType + backDistance), (autoLoadObject.sizeZ + backDistance) do
if (colPos + (autoLoadObject.sizeZ / 2)) <= lenghtForObjectType then
local loadingPatternItem = {}
loadingPatternItem.rotation = 0;
loadingPatternItem.posX = cornerX - (autoLoadObject.sizeX / 2) - (rowNumber * (autoLoadObject.sizeX + backDistance)) - (restFirstNoRotation / 2)
loadingPatternItem.posZ = cornerZ - colPos
table.insert(loadingPattern, loadingPatternItem)
end
end
end
end
table.sort(loadingPattern,compLoadingPattern)
for _,loadingPatternItem in ipairs(loadingPattern) do
local place = {}
place.node = createTransformGroup("Loadplace")
link(autoLoadObject.index, place.node);
-- Round bales must be rotated with 15° so the collision edge is not pointing to the left and right border.