-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathUniversalAutoloadInstaller.lua
1564 lines (1357 loc) · 61.9 KB
/
UniversalAutoloadInstaller.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- ============================================================= --
-- Universal Autoload MOD - MANAGER
-- ============================================================= --
-- manager
UniversalAutoloadManager = {}
addModEventListener(UniversalAutoloadManager)
-- specialisation
g_specializationManager:addSpecialization('universalAutoload', 'UniversalAutoload', Utils.getFilename('UniversalAutoload.lua', g_currentModDirectory), "")
TypeManager.validateTypes = Utils.appendedFunction(TypeManager.validateTypes, function(self)
if self.typeName == "vehicle" then
for vehicleName, vehicleType in pairs(g_vehicleTypeManager.types) do
-- Anything with tension belts could potentially require autoload
if SpecializationUtil.hasSpecialization(TensionBelts, vehicleType.specializations) then
g_vehicleTypeManager:addSpecialization(vehicleName, UniversalAutoload.name .. '.universalAutoload')
-- print(" UAL INSTALLED: "..vehicleName)
end
end
end
end)
-- Create a new store pack to group all UAL supported vehicles
-- @Loki Cannot do this in the modDesc using 'storePacks.storePack' as Giants forgot to localise l10n
g_storeManager:addModStorePack("UNIVERSALAUTOLOAD", g_i18n:getText("configuration_universalAutoload", g_currentModName), "icons/storePack_ual.dds", g_currentModDirectory)
-- variables
UniversalAutoload.userSettingsFile = "modSettings/UniversalAutoload.xml"
UniversalAutoload.SHOP_ICON = UniversalAutoload.path .. "icons/shop_icon.dds"
-- tables
UniversalAutoload.ACTIONS = {
["TOGGLE_LOADING"] = "UNIVERSALAUTOLOAD_TOGGLE_LOADING",
["UNLOAD_ALL"] = "UNIVERSALAUTOLOAD_UNLOAD_ALL",
["TOGGLE_TIPSIDE"] = "UNIVERSALAUTOLOAD_TOGGLE_TIPSIDE",
["TOGGLE_FILTER"] = "UNIVERSALAUTOLOAD_TOGGLE_FILTER",
["TOGGLE_HORIZONTAL"] = "UNIVERSALAUTOLOAD_TOGGLE_HORIZONTAL",
["CYCLE_MATERIAL_FW"] = "UNIVERSALAUTOLOAD_CYCLE_MATERIAL_FW",
["CYCLE_MATERIAL_BW"] = "UNIVERSALAUTOLOAD_CYCLE_MATERIAL_BW",
["SELECT_ALL_MATERIALS"] = "UNIVERSALAUTOLOAD_SELECT_ALL_MATERIALS",
["CYCLE_CONTAINER_FW"] = "UNIVERSALAUTOLOAD_CYCLE_CONTAINER_FW",
["CYCLE_CONTAINER_BW"] = "UNIVERSALAUTOLOAD_CYCLE_CONTAINER_BW",
["SELECT_ALL_CONTAINERS"] = "UNIVERSALAUTOLOAD_SELECT_ALL_CONTAINERS",
["TOGGLE_BELTS"] = "UNIVERSALAUTOLOAD_TOGGLE_BELTS",
["TOGGLE_DOOR"] = "UNIVERSALAUTOLOAD_TOGGLE_DOOR",
["TOGGLE_CURTAIN"] = "UNIVERSALAUTOLOAD_TOGGLE_CURTAIN",
["TOGGLE_SHOW_DEBUG"] = "UNIVERSALAUTOLOAD_TOGGLE_SHOW_DEBUG",
["TOGGLE_SHOW_LOADING"] = "UNIVERSALAUTOLOAD_TOGGLE_SHOW_LOADING",
["TOGGLE_BALE_COLLECTION"] = "UNIVERSALAUTOLOAD_TOGGLE_BALE_COLLECTION"
}
UniversalAutoload.WARNINGS = {
[1] = "warning_UNIVERSALAUTOLOAD_CLEAR_UNLOADING_AREA",
[2] = "warning_UNIVERSALAUTOLOAD_NO_OBJECTS_FOUND",
[3] = "warning_UNIVERSALAUTOLOAD_UNABLE_TO_LOAD_OBJECT",
[4] = "warning_UNIVERSALAUTOLOAD_NO_LOADING_UNLESS_STATIONARY"
}
UniversalAutoload.CONTAINERS = {
[1] = "ALL",
[2] = "EURO_PALLET",
[3] = "BIGBAG_PALLET",
[4] = "LIQUID_TANK",
[5] = "BIGBAG",
[6] = "BALE",
[7] = "LOGS"
}
UniversalAutoload.VALID_OBJECTS = {
[1] = "pallet",
[2] = "bigBag",
[3] = "treeSaplingPallet",
[4] = "pdlc_pumpsAndHosesPack.hosePallet",
[5] = "pdlc_forestryPack.woodContainer",
[6] = "pdlc_premiumExpansion.vegetablePallet"
}
UniversalAutoload.INVALID_OBJECTS = {
}
-- DEFINE DEFAULTS FOR CONTAINER TYPES
UniversalAutoload.ALL = { sizeX = 1.250, sizeY = 0.850, sizeZ = 0.850 }
UniversalAutoload.EURO_PALLET = { sizeX = 1.250, sizeY = 0.790, sizeZ = 0.850 }
UniversalAutoload.BIGBAG_PALLET = { sizeX = 1.525, sizeY = 1.075, sizeZ = 1.200 }
UniversalAutoload.LIQUID_TANK = { sizeX = 1.433, sizeY = 1.500, sizeZ = 1.415 }
UniversalAutoload.BIGBAG = { sizeX = 1.050, sizeY = 1.666, sizeZ = 0.866, neverStack=true }
UniversalAutoload.BALE = { isBale=true }
UniversalAutoload.VEHICLES = {}
UniversalAutoload.UNKNOWN_TYPES = {}
-- IMPORT VEHICLE CONFIGURATIONS
UniversalAutoload.VEHICLE_CONFIGURATIONS = {}
function UniversalAutoloadManager.ImportUserConfigurations(userSettingsFile, overwriteExisting)
if g_currentMission.isMultiplayer then
print("Custom configurations are not supported in multiplayer")
return
end
local N,M = 0,0
if fileExists(userSettingsFile) then
UniversalAutoloadManager.ImportGlobalSettings(userSettingsFile, overwriteExisting)
print("IMPORT user vehicle configurations")
N = N + UniversalAutoloadManager.ImportVehicleConfigurations(userSettingsFile, overwriteExisting)
print("IMPORT user container configurations")
M = M + UniversalAutoloadManager.ImportContainerTypeConfigurations(userSettingsFile, overwriteExisting)
else
print("CREATING user settings file")
local defaultSettingsFile = Utils.getFilename("config/UniversalAutoload.xml", UniversalAutoload.path)
copyFile(defaultSettingsFile, userSettingsFile, false)
UniversalAutoload.showDebug = false
UniversalAutoload.highPriority = true
UniversalAutoload.disableAutoStrap = false
UniversalAutoload.manualLoadingOnly = false
UniversalAutoload.disableManualLoading = false
UniversalAutoload.pricePerLog = 0
UniversalAutoload.pricePerBale = 0
UniversalAutoload.pricePerPallet = 0
UniversalAutoload.minLogLength = 0
end
return N,M
end
--
function UniversalAutoload.ImportUserConfigurations(userSettingsFile, overwriteExisting)
print("*** OLD VERSION OF UNIVERSAL AUTOLOAD MODHUB ADD-ON DETECTED - please update to latest version ***")
return UniversalAutoloadManager.ImportUserConfigurations(userSettingsFile, overwriteExisting)
end
--
function UniversalAutoloadManager.ImportGlobalSettings(xmlFilename, overwriteExisting)
if g_currentMission:getIsServer() then
local xmlFile = XMLFile.load("configXml", xmlFilename, UniversalAutoload.xmlSchema)
if xmlFile ~= 0 and xmlFile ~= nil then
if overwriteExisting or not UniversalAutoload.globalSettingsLoaded then
print("IMPORT Universal Autoload global settings")
UniversalAutoload.globalSettingsLoaded = true
UniversalAutoload.showDebug = xmlFile:getValue("universalAutoload#showDebug", false)
UniversalAutoload.highPriority = xmlFile:getValue("universalAutoload#highPriority", true)
UniversalAutoload.disableAutoStrap = xmlFile:getValue("universalAutoload#disableAutoStrap", false)
UniversalAutoload.manualLoadingOnly = xmlFile:getValue("universalAutoload#manualLoadingOnly", false)
UniversalAutoload.disableManualLoading = xmlFile:getValue("universalAutoload#disableManualLoading", false)
UniversalAutoload.pricePerLog = xmlFile:getValue("universalAutoload#pricePerLog", 0)
UniversalAutoload.pricePerBale = xmlFile:getValue("universalAutoload#pricePerBale", 0)
UniversalAutoload.pricePerPallet = xmlFile:getValue("universalAutoload#pricePerPallet", 0)
UniversalAutoload.minLogLength = xmlFile:getValue("universalAutoload#minLogLength", 0)
print(" >> Show Debug Display: " .. tostring(UniversalAutoload.showDebug))
print(" >> Menu High Priority: " .. tostring(UniversalAutoload.highPriority))
print(" >> Manual Loading Only: " .. tostring(UniversalAutoload.manualLoadingOnly))
print(" >> Disable Manual Loading: " .. tostring(UniversalAutoload.disableManualLoading))
print(" >> Automatic Tension Belts: " .. tostring(not UniversalAutoload.disableAutoStrap))
print(" >> Price Per Log: " .. tostring(UniversalAutoload.pricePerLog))
print(" >> Price Per Bale: " .. tostring(UniversalAutoload.pricePerBale))
print(" >> Price Per Pallet: " .. tostring(UniversalAutoload.pricePerPallet))
print(" >> Minimum Log Length: " .. tostring(UniversalAutoload.minLogLength))
end
local objectTypesKey = "universalAutoload.objectTypes"
if xmlFile:hasProperty(objectTypesKey) then
print("ADDING EXTRA object types")
local i = 0
while true do
local objectTypeKey = string.format(objectTypesKey .. ".objectType(%d)", i)
if not xmlFile:hasProperty(objectTypeKey) then
break
end
local objectType = xmlFile:getValue(objectTypeKey.."#name")
objectType = objectType:gsub(":", ".")
local customEnvironment, _ = objectType:match( "^(.-)%.(.+)$" )
if customEnvironment==nil or g_modIsLoaded[customEnvironment] then
if not tableContainsValue(UniversalAutoload.VALID_OBJECTS, objectType) then
table.insert(UniversalAutoload.VALID_OBJECTS, objectType)
print(" >> " .. tostring(objectType))
end
end
i = i + 1
end
end
xmlFile:delete()
else
print("Universal Autoload - could not open global settings file")
end
else
print("Universal Autoload - global settings are only loaded for the server")
end
end
--
function UniversalAutoloadManager.ImportVehicleConfigurations(xmlFilename, overwriteExisting)
local i = 0
local xmlFile = XMLFile.load("configXml", xmlFilename, UniversalAutoload.xmlSchema)
if xmlFile ~= 0 then
local debugAll = xmlFile:getValue("universalAutoload.vehicleConfigurations#showDebug", false)
while true do
local configKey = string.format("universalAutoload.vehicleConfigurations.vehicleConfiguration(%d)", i)
if not xmlFile:hasProperty(configKey) then
break
end
local configFileName = xmlFile:getValue(configKey.."#configFileName")
local validXmlFilename = UniversalAutoload.getValidXmlName(configFileName)
if validXmlFilename ~= nil then
if UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName] == nil then
UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName] = {}
-- Update the store pack with available vehicle
-- StoreManager.addPackItem' allows duplicates when using 'gsStoreItemsReload' so not used
table.addElement(g_storeManager:getPackItems("UNIVERSALAUTOLOAD"), validXmlFilename)
end
local configGroup = UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName]
local selectedConfigs = xmlFile:getValue(configKey.."#selectedConfigs", "ALL")
local useConfigName = xmlFile:getValue(configKey.."#useConfigName", nil)
if configGroup[selectedConfigs] == nil or overwriteExisting then
configGroup[selectedConfigs] = {}
configGroup[selectedConfigs].loadingArea = {}
local config = configGroup[selectedConfigs]
config.useConfigName = useConfigName
config.xmlFilename = validXmlFilename
local j = 0
local hasBaleHeight = false
while true do
local loadAreaKey = string.format("%s.loadingArea(%d)", configKey, j)
if not xmlFile:hasProperty(loadAreaKey) then
break
end
config.loadingArea[j+1] = {}
config.loadingArea[j+1].width = xmlFile:getValue(loadAreaKey.."#width", nil)
config.loadingArea[j+1].length = xmlFile:getValue(loadAreaKey.."#length", nil)
config.loadingArea[j+1].height = xmlFile:getValue(loadAreaKey.."#height", nil)
config.loadingArea[j+1].baleHeight = xmlFile:getValue(loadAreaKey.."#baleHeight", nil)
config.loadingArea[j+1].widthAxis = xmlFile:getValue(loadAreaKey.."#widthAxis", nil)
config.loadingArea[j+1].lengthAxis = xmlFile:getValue(loadAreaKey.."#lengthAxis", nil)
config.loadingArea[j+1].heightAxis = xmlFile:getValue(loadAreaKey.."#heightAxis", nil)
config.loadingArea[j+1].offsetFrontAxis = xmlFile:getValue(loadAreaKey.."#offsetFrontAxis", nil)
config.loadingArea[j+1].offsetRearAxis = xmlFile:getValue(loadAreaKey.."#offsetRearAxis", nil)
config.loadingArea[j+1].reverseWidthAxis = xmlFile:getValue(loadAreaKey.."#reverseWidthAxis", false)
config.loadingArea[j+1].reverseLengthAxis = xmlFile:getValue(loadAreaKey.."#reverseLengthAxis", false)
config.loadingArea[j+1].reverseHeightAxis = xmlFile:getValue(loadAreaKey.."#reverseHeightAxis", false)
config.loadingArea[j+1].offset = xmlFile:getValue(loadAreaKey.."#offset", "0 0 0", true)
config.loadingArea[j+1].offsetRoot = xmlFile:getValue(loadAreaKey.."#offsetRoot", nil)
config.loadingArea[j+1].noLoadingIfFolded = xmlFile:getValue(loadAreaKey.."#noLoadingIfFolded", false)
config.loadingArea[j+1].noLoadingIfUnfolded = xmlFile:getValue(loadAreaKey.."#noLoadingIfUnfolded", false)
config.loadingArea[j+1].noLoadingIfCovered = xmlFile:getValue(loadAreaKey.."#noLoadingIfCovered", false)
config.loadingArea[j+1].noLoadingIfUncovered = xmlFile:getValue(loadAreaKey.."#noLoadingIfUncovered", false)
hasBaleHeight = hasBaleHeight or type(config.loadingArea[j+1].baleHeight) == 'number'
j = j + 1
end
local isBaleTrailer = xmlFile:getValue(configKey..".options#isBaleTrailer", nil)
local isBaleProcessor = xmlFile:getValue(configKey..".options#isBaleProcessor", nil)
local horizontalLoading = xmlFile:getValue(configKey..".options#horizontalLoading", nil)
config.horizontalLoading = horizontalLoading or isBaleTrailer or isBaleProcessor or false
config.isBaleTrailer = isBaleTrailer or hasBaleHeight
config.isBaleProcessor = isBaleProcessor
config.isBoxTrailer = xmlFile:getValue(configKey..".options#isBoxTrailer", false)
config.isLogTrailer = xmlFile:getValue(configKey..".options#isLogTrailer", false)
config.isCurtainTrailer = xmlFile:getValue(configKey..".options#isCurtainTrailer", false)
config.enableRearLoading = xmlFile:getValue(configKey..".options#enableRearLoading", false)
config.enableSideLoading = xmlFile:getValue(configKey..".options#enableSideLoading", false)
config.noLoadingIfFolded = xmlFile:getValue(configKey..".options#noLoadingIfFolded", false)
config.noLoadingIfUnfolded = xmlFile:getValue(configKey..".options#noLoadingIfUnfolded", false)
config.noLoadingIfCovered = xmlFile:getValue(configKey..".options#noLoadingIfCovered", false)
config.noLoadingIfUncovered = xmlFile:getValue(configKey..".options#noLoadingIfUncovered", false)
config.rearUnloadingOnly = xmlFile:getValue(configKey..".options#rearUnloadingOnly", false)
config.frontUnloadingOnly = xmlFile:getValue(configKey..".options#frontUnloadingOnly", false)
config.disableAutoStrap = xmlFile:getValue(configKey..".options#disableAutoStrap", false)
config.disableHeightLimit = xmlFile:getValue(configKey..".options#disableHeightLimit", false)
config.zonesOverlap = xmlFile:getValue(configKey..".options#zonesOverlap", false)
config.offsetRoot = xmlFile:getValue(configKey..".options#offsetRoot", nil)
config.minLogLength = xmlFile:getValue(configKey..".options#minLogLength", UniversalAutoload.minLogLength)
config.showDebug = xmlFile:getValue(configKey..".options#showDebug", debugAll)
if not config.showDebug then
print(" >> "..configFileName.." ("..selectedConfigs..")")
else
print(" >> "..configFileName.." ("..selectedConfigs..") DEBUG")
end
else
if UniversalAutoload.showDebug then print(" ALREADY EXISTS: "..configFileName.." ("..selectedConfigs..")") end
end
else
if UniversalAutoload.showDebug then print(" NOT FOUND: " .. configFileName) end
end
i = i + 1
end
xmlFile:delete()
end
return i
end
--
function UniversalAutoload.ImportVehicleConfigurations(xmlFilename, overwriteExisting)
print("*** OLD VERSION OF UNIVERSAL AUTOLOAD MODHUB ADD-ON DETECTED - please update to latest version ***")
return UniversalAutoloadManager.ImportVehicleConfigurations(xmlFilename, overwriteExisting)
end
-- IMPORT CONTAINER TYPE DEFINITIONS
UniversalAutoload.LOADING_TYPE_CONFIGURATIONS = {}
UniversalAutoload.LOADING_TYPE_CONFIG_BY_PATH = {}
function UniversalAutoloadManager.ImportContainerTypeConfigurations(xmlFilename, overwriteExisting)
local i = 0
local xmlFile = XMLFile.load("configXml", xmlFilename, UniversalAutoload.xmlSchema)
if xmlFile ~= 0 then
local containerRootKey = "universalAutoload.containerConfigurations"
local legacyContainerRootKey = "universalAutoload.containerTypeConfigurations"
if not xmlFile:hasProperty(containerRootKey) and xmlFile:hasProperty(legacyContainerRootKey) then
print("*** OLD VERSION OF CONFIG FILE DETECTED - please use <containerConfigurations> ***")
containerRootKey = legacyContainerRootKey
end
while true do
local configKey = string.format(containerRootKey..".containerConfiguration(%d)", i)
if not xmlFile:hasProperty(configKey) then
break
end
local containerType = xmlFile:getValue(configKey.."#containerType", "ALL")
if tableContainsValue(UniversalAutoload.CONTAINERS, containerType) then
local default = UniversalAutoload[containerType] or {}
local name = xmlFile:getValue(configKey.."#name")
local customEnvironment, i3d_name = name:match( "^(.-):(.+)$" )
if i3d_name and i3d_name:find("/") and i3d_name:find(".i3d") then
local shortName = UniversalAutoload.getObjectNameFromI3d(i3d_name)
UniversalAutoload.LOADING_TYPE_CONFIG_BY_PATH[shortName] = UniversalAutoload.LOADING_TYPE_CONFIG_BY_PATH[shortName] or {}
table.insert(UniversalAutoload.LOADING_TYPE_CONFIG_BY_PATH[shortName], i3d_name)
end
if customEnvironment==nil or g_modIsLoaded[customEnvironment] then
local config = UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[name]
if config == nil or overwriteExisting then
UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[name] = {}
newType = UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[name]
newType.name = name
newType.type = containerType
newType.containerIndex = UniversalAutoload.CONTAINERS_INDEX[containerType] or 1
newType.sizeX = xmlFile:getValue(configKey.."#sizeX", default.sizeX or 1.5)
newType.sizeY = xmlFile:getValue(configKey.."#sizeY", default.sizeY or 1.5)
newType.sizeZ = xmlFile:getValue(configKey.."#sizeZ", default.sizeZ or 1.5)
newType.isBale = xmlFile:getValue(configKey.."#isBale", default.isBale or false)
newType.flipYZ = xmlFile:getValue(configKey.."#flipYZ", default.flipYZ or false)
newType.neverStack = xmlFile:getValue(configKey.."#neverStack", default.neverStack or false)
newType.neverRotate = xmlFile:getValue(configKey.."#neverRotate", default.neverRotate or false)
newType.alwaysRotate = xmlFile:getValue(configKey.."#alwaysRotate", default.alwaysRotate or false)
newType.frontOffset = xmlFile:getValue(configKey.."#frontOffset", default.frontOffset or 0)
print(string.format(" >> %s %s [%.3f, %.3f, %.3f]", newType.type, newType.name, newType.sizeX, newType.sizeY, newType.sizeZ ))
end
end
else
if UniversalAutoload.showDebug then print(" UNKNOWN CONTAINER TYPE: "..tostring(containerType)) end
end
i = i + 1
end
xmlFile:delete()
end
return i
end
--
function UniversalAutoload.ImportContainerTypeConfigurations(xmlFilename, overwriteExisting)
print("*** OLD VERSION OF UNIVERSAL AUTOLOAD MODHUB ADD-ON DETECTED - please update to latest version ***")
return UniversalAutoloadManager.ImportContainerTypeConfigurations(xmlFilename, overwriteExisting)
end
--
function UniversalAutoloadManager.importContainerTypeFromXml(xmlFilename, customEnvironment)
if xmlFilename ~= nil and not (string.find(xmlFilename, "multiPurchase") or string.find(xmlFilename, "multipleItemPurchase") ) then
-- print( " >> " .. xmlFilename )
local foundExisting = false
if customEnvironment ~= nil then
foundExisting = UniversalAutoloadManager.importUnknownSpecFromExisting(xmlFilename, customEnvironment)
end
if not foundExisting then
local loadedVehicleXML = false
local xmlFile = XMLFile.load("configXml", xmlFilename, Vehicle.xmlSchema)
if xmlFile~=nil and xmlFile:hasProperty("vehicle.base") then
loadedVehicleXML = true
UniversalAutoloadManager.importPalletTypeFromXml(xmlFile, customEnvironment)
end
xmlFile:delete()
if not loadedVehicleXML then
xmlFile = XMLFile.load("baleConfigXml", xmlFilename, BaleManager.baleXMLSchema)
if xmlFile~=nil and xmlFile:hasProperty("bale") then
UniversalAutoloadManager.importBaleTypeFromXml(xmlFile, customEnvironment)
end
xmlFile:delete()
end
end
end
end
--
function UniversalAutoloadManager.importObjectTypeTypeFromXml(xmlInput, customEnvironment)
local xmlFile = xmlInput
if type(xmlInput) == 'string' then
xmlFile = XMLFile.load("configXml", xmlInput, Vehicle.xmlSchema)
end
if xmlFile~=nil then
local vehicleType = xmlFile:getValue("vehicle#type")
if vehicleType~=nil and customEnvironment~=nil then
local objectType = customEnvironment.."."..vehicleType
if not tableContainsValue(UniversalAutoload.VALID_OBJECTS, objectType) then
table.insert(UniversalAutoload.VALID_OBJECTS, objectType)
end
end
if type(xmlInput) == 'string' then
xmlFile:delete()
end
end
end
--
function UniversalAutoloadManager.importUnknownSpecFromExisting(xmlFilename, customEnvironment)
local objectName = UniversalAutoload.getObjectNameFromXml(xmlFilename)
local customName = customEnvironment..":"..objectName
if UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[customName] ~= nil then
-- print("FOUND CUSTOM CONFIG FOR " .. customName)
return true
end
if UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[objectName] ~= nil then
-- print("USING BASE CONFIG FOR " .. customName)
UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[customName] = {}
newType = UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[customName]
oldType = UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[objectName]
newType.name = customName
newType.type = oldType.type
newType.containerIndex = oldType.containerIndex
newType.sizeX = oldType.sizeX
newType.sizeY = oldType.sizeY
newType.sizeZ = oldType.sizeZ
newType.isBale = oldType.isBale
newType.flipYZ = oldType.flipYZ
newType.neverStack = oldType.neverStack
newType.neverRotate = oldType.neverRotate
newType.alwaysRotate = oldType.alwaysRotate
newType.frontOffset = oldType.frontOffset
if oldType.isBale then
newType.width = oldType.width
newType.length = oldType.length
end
print(string.format(" >> %s [%.3f, %.3f, %.3f] - %s", newType.name, newType.sizeX, newType.sizeY, newType.sizeZ, newType.type ))
UniversalAutoloadManager.importObjectTypeTypeFromXml(xmlFilename, customEnvironment)
return true
end
end
--
function UniversalAutoloadManager.importPalletTypeFromXml(xmlFile, customEnvironment)
local i3d_path = xmlFile:getValue("vehicle.base.filename")
if i3d_path == nil then
print(" MISSING 'vehicle.base.filename' in " .. tostring(xmlFile.filename))
return
end
local i3d_name = UniversalAutoload.getObjectNameFromI3d(i3d_path)
if i3d_name ~= nil then
local name
if customEnvironment == nil then
name = i3d_name
else
name = customEnvironment..":"..i3d_name
end
if UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[name] == nil then
local category = xmlFile:getValue("vehicle.storeData.category", "NONE")
local width = xmlFile:getValue("vehicle.base.size#width", 1.5)
local height = xmlFile:getValue("vehicle.base.size#height", 1.5)
local length = xmlFile:getValue("vehicle.base.size#length", 1.5)
local containerType
if string.find(i3d_name, "liquidTank") or string.find(i3d_name, "IBC") then containerType = "LIQUID_TANK"
elseif string.find(i3d_name, "bigBag") or string.find(i3d_name, "BigBag") then containerType = "BIGBAG"
elseif string.find(i3d_name, "pallet") or string.find(i3d_name, "Pallet") then containerType = "EURO_PALLET"
elseif category == "pallets" then containerType = "EURO_PALLET"
elseif category == "bigbags" then containerType = "BIGBAG"
elseif category == "bigbagPallets" then containerType = "BIGBAG_PALLET"
else
containerType = "ALL"
if UniversalAutoload.showDebug then print(" USING DEFAULT CONTAINER TYPE: "..name.." - "..category) end
end
UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[name] = {}
newType = UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[name]
newType.name = name
newType.type = containerType or "ALL"
newType.containerIndex = UniversalAutoload.CONTAINERS_INDEX[containerType] or 1
newType.sizeX = width
newType.sizeY = height
newType.sizeZ = length
newType.isBale = false
newType.flipYZ = false
newType.neverStack = (containerType == "BIGBAG") or false
newType.neverRotate = false
newType.alwaysRotate = false
newType.frontOffset = 0
newType.width = math.min(newType.sizeX, newType.sizeZ)
newType.length = math.max(newType.sizeX, newType.sizeZ)
print(string.format(" >> %s [%.3f, %.3f, %.3f] - %s", newType.name,
newType.sizeX, newType.sizeY, newType.sizeZ, containerType ))
UniversalAutoloadManager.importObjectTypeTypeFromXml(xmlFile, customEnvironment)
return true
end
end
end
--
function UniversalAutoloadManager.importBaleTypeFromXml(xmlFile, customEnvironment)
local i3d_path = xmlFile:getValue("bale.filename")
if i3d_path == nil then
print("importBaleTypeFromXml: i3d_path == NIL")
print(tostring(xmlFile.filename))
return
end
local i3d_name = UniversalAutoload.getObjectNameFromI3d(i3d_path)
if i3d_name ~= nil then
local name
if customEnvironment == nil then
name = i3d_name
else
name = customEnvironment..":"..i3d_name
end
if UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[name] == nil then
local containerType = "BALE"
local width = xmlFile:getValue("bale.size#width", 1.5)
local height = xmlFile:getValue("bale.size#height", 1.5)
local length = xmlFile:getValue("bale.size#length", 2.4)
local diameter = xmlFile:getValue("bale.size#diameter", 1.8)
local isRoundbale = xmlFile:getValue("bale.size#isRoundbale", "false")
UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[name] = {}
newType = UniversalAutoload.LOADING_TYPE_CONFIGURATIONS[name]
newType.name = name
newType.type = containerType
newType.containerIndex = UniversalAutoload.CONTAINERS_INDEX[containerType] or 1
if isRoundbale then
newType.sizeX = diameter
newType.sizeY = width
newType.sizeZ = diameter
else
newType.sizeX = width
newType.sizeY = height
newType.sizeZ = length
end
newType.isBale = true
newType.flipYZ = isRoundbale
newType.neverStack = false
newType.neverRotate = false
newType.alwaysRotate = false
newType.frontOffset = 0
newType.width = math.min(newType.sizeX, newType.sizeZ)
newType.length = math.max(newType.sizeX, newType.sizeZ)
print(string.format(" >> %s [%.3f, %.3f, %.3f] - %s", newType.name,
newType.sizeX, newType.sizeY, newType.sizeZ, containerType ))
return true
end
end
end
-- DETECT CONFLICTS/ISSUES
function UniversalAutoloadManager.detectOldConfigVersion()
local userSettingsFile = Utils.getFilename(UniversalAutoload.userSettingsFile, getUserProfileAppPath())
if fileExists(userSettingsFile) then
local xmlFile = XMLFile.load("configXml", userSettingsFile, UniversalAutoload.xmlSchema)
if xmlFile ~= 0 then
local oldConfigKey = "universalAutoload.containerTypeConfigurations"
if xmlFile:hasProperty(oldConfigKey) then
print("*********************************************************************")
print("** UNIVERSAL AUTOLOAD - LOCAL MOD SETTINGS FILE IS OUT OF DATE **")
print("*********************************************************************")
print("** Please delete old 'UniversalAutoload.xml' file in modSettings **")
print("** OR update container config key to: 'containerConfigurations' **")
print("*********************************************************************")
end
xmlFile:delete()
end
end
end
--
function UniversalAutoloadManager.detectKeybindingConflicts()
--DETECT 'T' KEYS CONFLICT
if g_currentMission.missionDynamicInfo.isMultiplayer and not g_dedicatedServer then
local chatKey = ""
local containerKey = "KEY_t"
local xmlFile = loadXMLFile('TempXML', g_gui.inputManager.settingsPath)
local actionBindingCounter = 0
if xmlFile ~= 0 then
while true do
local key = string.format('inputBinding.actionBinding(%d)', actionBindingCounter)
local actionString = getXMLString(xmlFile, key .. '#action')
if actionString == nil then
break
end
if actionString == 'CHAT' then
local i = 0
while true do
local bindingKey = key .. string.format('.binding(%d)',i)
local bindingInput = getXMLString(xmlFile, bindingKey .. '#input')
if bindingInput == "KEY_t" then
print(" Using 'KEY_t' for 'CHAT'")
chatKey = bindingInput
elseif bindingInput == nil then
break
end
i = i + 1
end
end
if actionString == 'UNIVERSALAUTOLOAD_CYCLE_CONTAINER_FW' then
local i = 0
while true do
local bindingKey = key .. string.format('.binding(%d)',i)
local bindingInput = getXMLString(xmlFile, bindingKey .. '#input')
if bindingInput ~= nil then
print(" Using '"..bindingInput.."' for 'CYCLE_CONTAINER'")
containerKey = bindingInput
elseif bindingInput == nil then
break
end
i = i + 1
end
end
actionBindingCounter = actionBindingCounter + 1
end
end
delete(xmlFile)
if chatKey == containerKey then
print("**CHAT KEY CONFLICT DETECTED** - Disabling CYCLE_CONTAINER for Multiplayer")
print("(Please reassign 'CHAT' or 'CYCLE_CONTAINER' to a different key and RESTART the game)")
UniversalAutoload.chatKeyConflict = true
end
end
end
-- CONSOLE FUNCTIONS
function UniversalAutoloadManager:consoleResetVehicles()
if g_gui.currentGuiName == "ShopMenu" or g_gui.currentGuiName == "ShopConfigScreen" then
return "Reset vehicles is not supported while in shop!"
end
UniversalAutoloadManager.resetList = {}
UniversalAutoloadManager.resetCount = 1
g_currentMission.isReloadingVehicles = true
for _, vehicle in pairs(UniversalAutoload.VEHICLES) do
table.insert(UniversalAutoloadManager.resetList, vehicle)
end
UniversalAutoload.VEHICLES = {}
print(string.format("Resetting %d vehicles now..", #UniversalAutoloadManager.resetList))
UniversalAutoloadManager.resetNextVehicle()
end
--
function UniversalAutoloadManager:consoleImportUserConfigurations()
local oldVehicleConfigurations = deepCopy(UniversalAutoload.VEHICLE_CONFIGURATIONS)
local oldContainerConfigurations = deepCopy(UniversalAutoload.LOADING_TYPE_CONFIGURATIONS)
local userSettingsFile = Utils.getFilename(UniversalAutoload.userSettingsFile, getUserProfileAppPath())
local vehicleCount, objectCount = UniversalAutoloadManager.ImportUserConfigurations(userSettingsFile, true)
g_currentMission.isReloadingVehicles = true
if vehicleCount > 0 then
vehicleCount = 0
local doResetVehicle = false
for key, configGroup in pairs(UniversalAutoload.VEHICLE_CONFIGURATIONS) do
local foundFirstMatch = false
for index, config in pairs(configGroup) do
if oldVehicleConfigurations[key] and oldVehicleConfigurations[key][index]
and not deepCompare(oldVehicleConfigurations[key][index], config) then
-- FIRST LOOK IF THIS IS THE CURRENT CONTROLLED VECHILE
for _, vehicle in pairs(UniversalAutoload.VEHICLES) do
-- print(vehicle.configFileName .. " - " .. tostring(vehicle.spec_universalAutoload.boughtConfig) .. " / " .. index)
if string.find(vehicle.configFileName, key) and vehicle.spec_universalAutoload.boughtConfig == index then
local rootVehicle = vehicle:getRootVehicle()
if rootVehicle == g_currentMission.controlledVehicle then
foundFirstMatch = true
print("APPLYING UPDATED SETTINGS: " .. vehicle:getFullName())
if not UniversalAutoloadManager.resetVehicle(vehicle) then
print("THIS IS CURRENT CONTROLLED VEHICLE: " .. vehicle:getFullName())
doResetVehicle = true
end
end
end
end
-- THEN CHECK ALL THE OTHERS - but we can only reset one at a time
for _, vehicle in pairs(UniversalAutoload.VEHICLES) do
if string.find(vehicle.configFileName, key) and vehicle.spec_universalAutoload.boughtConfig == index then
if not foundFirstMatch then
foundFirstMatch = true
vehicleCount = vehicleCount + 1
print("APPLYING UPDATED SETTINGS: " .. vehicle:getFullName())
if not UniversalAutoloadManager.resetVehicle(vehicle) then
doResetVehicle = true
end
else
print("ONLY ONE OF EACH VEHICLE CONFIGURATION CAN BE RESET USING THIS COMMAND")
end
end
end
end
end
end
if doResetVehicle then
g_currentMission:consoleCommandReloadVehicle()
else
g_currentMission.isReloadingVehicles = false
end
end
if objectCount > 0 then
objectCount = 0
for key, value in pairs(UniversalAutoload.LOADING_TYPE_CONFIGURATIONS) do
if not deepCompare(oldContainerConfigurations[key], value) then
objectCount = objectCount + 1
end
end
end
if vehicleCount > 0 and objectCount == 0 then
return string.format("UPDATED: %d vehicle configurations", vehicleCount)
end
if objectCount > 0 and vehicleCount == 0 then
return string.format("UPDATED: %d container configurations", objectCount)
end
return string.format("UPDATED: %d vehicle configurations, %d container configurations", vehicleCount, objectCount)
end
--
function UniversalAutoloadManager:consoleAddPallets(palletType)
local pallets = {}
for _, fillType in pairs(g_fillTypeManager:getFillTypes()) do
local xmlName = fillType.palletFilename
if xmlName ~= nil and not xmlName:find("fillablePallet") then
pallets[fillType.name] = xmlName
end
end
if palletType then
palletType = string.upper(palletType or "")
local xmlFilename = pallets[palletType]
if xmlFilename == nil then
return "Error: Invalid pallet type. Valid types are " .. table.concatKeys(pallets, ", ")
end
pallets = {}
pallets[palletType] = xmlFilename
end
if g_currentMission.controlledVehicle ~= nil then
local vehicles = UniversalAutoloadManager.getAttachedVehicles(g_currentMission.controlledVehicle)
local count = 0
if next(vehicles) ~= nil then
for vehicle, hasAutoload in pairs(vehicles) do
if hasAutoload and vehicle:getIsActiveForInput() then
if UniversalAutoload.createPallets(vehicle, pallets) then
count = count + 1
end
end
end
end
if count>0 then return "Begin adding pallets now.." end
end
return "Please enter a vehicle with a UAL trailer attached to use this command"
end
--
function UniversalAutoloadManager:consoleAddLogs(arg1, arg2)
local length = nil
local treeTypeName = "PINE"
if tonumber(arg1) then
length = tonumber(arg1)
treeTypeName = arg2
elseif tonumber(arg2) then
length = tonumber(arg2)
treeTypeName = arg1
elseif arg1 ~= nil then
treeTypeName = arg1
end
local availableLogTypes
if not g_modIsLoaded["pdlc_forestryPack"] then
availableLogTypes = {
OAK = 3.5,
ELM = 3.5,
PINE = 30,
BIRCH = 5,
MAPLE = 2,
POPLAR = 18,
SPRUCE = 34,
WILLOW = 2.5,
CYPRESS = 2.5,
HICKORY = 4.2,
STONEPINE = 8,
}
else
availableLogTypes = {
OAK = 3.5,
ELM = 3.5,
PINE = 30,
BIRCH = 5,
MAPLE = 2,
POPLAR = 18,
SPRUCE = 34,
WILLOW = 2.5,
CYPRESS = 2.5,
HICKORY = 4.2,
DEADWOOD = 20,
STONEPINE = 8,
GIANTSEQUOIA = 7,
PONDEROSAPINE = 32,
LODGEPOLEPINE = 32
}
end
treeTypeName = string.upper(treeTypeName or "")
if availableLogTypes[treeTypeName]==nil then
return "Error: Invalid lumber type. Valid types are " .. table.concatKeys(availableLogTypes, ", ")
end
local maxLength = availableLogTypes[treeTypeName]
if treeTypeName == 'ELM' then treeTypeName = 'AMERICANELM' end
if treeTypeName == 'HICKORY' then treeTypeName = 'SHAGBARKHICKORY' end
if length == nil then length = maxLength end
if length > maxLength then
print("using maximum length " .. maxLength .. "m")
length = maxLength
end
if g_currentMission.controlledVehicle ~= nil then
local vehicles = UniversalAutoloadManager.getAttachedVehicles(g_currentMission.controlledVehicle)
local count = 0
if next(vehicles) ~= nil then
for vehicle, hasAutoload in pairs(vehicles) do
if hasAutoload and vehicle:getIsActiveForInput() then
local maxSingleLength = UniversalAutoload.getMaxSingleLength(vehicle)
if length > maxSingleLength then
length = maxSingleLength - 0.1
print("resizing to fit trailer " .. length .. "m")
end
if UniversalAutoload.createLogs(vehicle, treeTypeName, length) then
count = count + 1
end
end
end
end
if count>0 then return "Begin adding logs now.." end
end
return "Please enter a vehicle with a UAL trailer attached to use this command"
end
--
function UniversalAutoloadManager:consoleAddBales(fillTypeName, isRoundbale, width, height, length, wrapState, modName)
local usage = "ualAddBales fillTypeName isRoundBale [width] [height/diameter] [length] [wrapState] [modName]"
fillTypeName = Utils.getNoNil(fillTypeName, "STRAW")
isRoundbale = Utils.stringToBoolean(isRoundbale)
width = width ~= nil and tonumber(width) or nil
height = height ~= nil and tonumber(height) or nil
length = length ~= nil and tonumber(length) or nil
if wrapState ~= nil and tonumber(wrapState) == nil then
Logging.error("Invalid wrapState '%s'. Number expected", wrapState, usage)
return
end
wrapState = tonumber(wrapState or 0)
local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName(fillTypeName)
if fillTypeIndex == nil then
Logging.error("Invalid fillTypeName '%s' (e.g. STRAW). Use %s", fillTypeName, usage)
return
end
local xmlFilename, _ = g_baleManager:getBaleXMLFilename(fillTypeIndex, isRoundbale, width, height, length, height, modName)
if xmlFilename == nil then
Logging.error("Could not find bale for given size attributes! (%s)", usage)
g_baleManager:consoleCommandListBales()
return
end
bale = {}
bale.xmlFile = xmlFilename
bale.fillTypeIndex = fillTypeIndex
bale.wrapState = wrapState
if g_currentMission.controlledVehicle ~= nil then
local vehicles = UniversalAutoloadManager.getAttachedVehicles(g_currentMission.controlledVehicle)
local count = 0
if next(vehicles) ~= nil then
for vehicle, hasAutoload in pairs(vehicles) do
if hasAutoload and vehicle:getIsActiveForInput() then
if UniversalAutoload.createBales(vehicle, bale) then
count = count + 1
end
end
end
end
if count>0 then return "Begin adding bales now.." end
end
return "Please enter a vehicle with a UAL trailer attached to use this command"
end
--
function UniversalAutoloadManager:consoleAddRoundBales_125(fillTypeName)
return UniversalAutoloadManager:consoleAddBales(fillTypeName or "DRYGRASS_WINDROW", "true", "1.2", "1.25")
end
--
function UniversalAutoloadManager:consoleAddRoundBales_150(fillTypeName)
return UniversalAutoloadManager:consoleAddBales(fillTypeName or "DRYGRASS_WINDROW", "true", "1.2", "1.5")
end
--
function UniversalAutoloadManager:consoleAddRoundBales_180(fillTypeName)
return UniversalAutoloadManager:consoleAddBales(fillTypeName or "DRYGRASS_WINDROW", "true", "1.2", "1.8")
end
--
function UniversalAutoloadManager:consoleAddSquareBales_180(fillTypeName)
return UniversalAutoloadManager:consoleAddBales(fillTypeName or "STRAW", "false", "1.2", "0.9", "1.8")
end
--
function UniversalAutoloadManager:consoleAddSquareBales_220(fillTypeName)
return UniversalAutoloadManager:consoleAddBales(fillTypeName or "STRAW", "false", "1.2", "0.9", "2.2")
end
--
function UniversalAutoloadManager:consoleAddSquareBales_240(fillTypeName)
return UniversalAutoloadManager:consoleAddBales(fillTypeName or "STRAW", "false", "1.2", "0.9", "2.4")
end
--
function UniversalAutoloadManager:consoleClearLoadedObjects()