-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVehicle.lua
More file actions
4658 lines (3548 loc) · 183 KB
/
Vehicle.lua
File metadata and controls
4658 lines (3548 loc) · 183 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---This class handles all basic functionality of a vehicle
-- - loading of i3d
-- - syncing of components
-- - handling of specializations
local Vehicle_mt = Class(Vehicle, Object)
---Register interaction flag
-- @param string name name of flag
function Vehicle.registerInteractionFlag(name)
local key = "INTERACTION_FLAG_"..string.upper(name)
if Vehicle[key] == nil then
Vehicle.NUM_INTERACTION_FLAGS = Vehicle.NUM_INTERACTION_FLAGS + 1
Vehicle[key] = Vehicle.NUM_INTERACTION_FLAGS
end
return Vehicle[key]
end
---
function Vehicle.registerEvents(vehicleType)
SpecializationUtil.registerEvent(vehicleType, "onPreLoad")
SpecializationUtil.registerEvent(vehicleType, "onLoad")
SpecializationUtil.registerEvent(vehicleType, "onPostLoad")
SpecializationUtil.registerEvent(vehicleType, "onPreInitComponentPlacement")
SpecializationUtil.registerEvent(vehicleType, "onPreLoadFinished")
SpecializationUtil.registerEvent(vehicleType, "onLoadFinished")
SpecializationUtil.registerEvent(vehicleType, "onLoadEnd")
SpecializationUtil.registerEvent(vehicleType, "onRegistered")
SpecializationUtil.registerEvent(vehicleType, "onDirtyMaskCleared")
SpecializationUtil.registerEvent(vehicleType, "onPreDelete")
SpecializationUtil.registerEvent(vehicleType, "onDelete")
SpecializationUtil.registerEvent(vehicleType, "onSave")
SpecializationUtil.registerEvent(vehicleType, "onReadStream")
SpecializationUtil.registerEvent(vehicleType, "onWriteStream")
SpecializationUtil.registerEvent(vehicleType, "onReadUpdateStream")
SpecializationUtil.registerEvent(vehicleType, "onWriteUpdateStream")
SpecializationUtil.registerEvent(vehicleType, "onReadPositionUpdateStream")
SpecializationUtil.registerEvent(vehicleType, "onWritePositionUpdateStream")
SpecializationUtil.registerEvent(vehicleType, "onHandToolTaken")
SpecializationUtil.registerEvent(vehicleType, "onHandToolPlaced")
SpecializationUtil.registerEvent(vehicleType, "onPreUpdate")
SpecializationUtil.registerEvent(vehicleType, "onUpdate")
SpecializationUtil.registerEvent(vehicleType, "onUpdateInterpolation")
SpecializationUtil.registerEvent(vehicleType, "onUpdateDebug")
SpecializationUtil.registerEvent(vehicleType, "onPostUpdate")
SpecializationUtil.registerEvent(vehicleType, "onUpdateTick")
SpecializationUtil.registerEvent(vehicleType, "onPostUpdateTick")
SpecializationUtil.registerEvent(vehicleType, "onUpdateEnd")
SpecializationUtil.registerEvent(vehicleType, "onDraw")
SpecializationUtil.registerEvent(vehicleType, "onDrawUIInfo")
SpecializationUtil.registerEvent(vehicleType, "onActivate")
SpecializationUtil.registerEvent(vehicleType, "onDeactivate")
SpecializationUtil.registerEvent(vehicleType, "onStateChange")
SpecializationUtil.registerEvent(vehicleType, "onPreRegisterActionEvents")
SpecializationUtil.registerEvent(vehicleType, "onRegisterActionEvents")
SpecializationUtil.registerEvent(vehicleType, "onRootVehicleChanged")
SpecializationUtil.registerEvent(vehicleType, "onSelect")
SpecializationUtil.registerEvent(vehicleType, "onUnselect")
SpecializationUtil.registerEvent(vehicleType, "onSetBroken")
SpecializationUtil.registerEvent(vehicleType, "onSaleItemSet")
end
---
function Vehicle.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, "register", Vehicle.register)
SpecializationUtil.registerFunction(vehicleType, "setOwnerFarmId", Vehicle.setOwnerFarmId)
SpecializationUtil.registerFunction(vehicleType, "loadSubSharedI3DFile", Vehicle.loadSubSharedI3DFile)
SpecializationUtil.registerFunction(vehicleType, "drawUIInfo", Vehicle.drawUIInfo)
SpecializationUtil.registerFunction(vehicleType, "raiseActive", Vehicle.raiseActive)
SpecializationUtil.registerFunction(vehicleType, "setLoadingState", Vehicle.setLoadingState)
SpecializationUtil.registerFunction(vehicleType, "setLoadingStep", Vehicle.setLoadingStep)
SpecializationUtil.registerFunction(vehicleType, "addToPhysics", Vehicle.addToPhysics)
SpecializationUtil.registerFunction(vehicleType, "removeFromPhysics", Vehicle.removeFromPhysics)
SpecializationUtil.registerFunction(vehicleType, "setVisibility", Vehicle.setVisibility)
SpecializationUtil.registerFunction(vehicleType, "setRelativePosition", Vehicle.setRelativePosition)
SpecializationUtil.registerFunction(vehicleType, "setAbsolutePosition", Vehicle.setAbsolutePosition)
SpecializationUtil.registerFunction(vehicleType, "getLimitedVehicleYPosition", Vehicle.getLimitedVehicleYPosition)
SpecializationUtil.registerFunction(vehicleType, "setWorldPosition", Vehicle.setWorldPosition)
SpecializationUtil.registerFunction(vehicleType, "setWorldPositionQuaternion", Vehicle.setWorldPositionQuaternion)
SpecializationUtil.registerFunction(vehicleType, "setDefaultComponentPosition", Vehicle.setDefaultComponentPosition)
SpecializationUtil.registerFunction(vehicleType, "getIsNodeActive", Vehicle.getIsNodeActive)
SpecializationUtil.registerFunction(vehicleType, "updateVehicleSpeed", Vehicle.updateVehicleSpeed)
SpecializationUtil.registerFunction(vehicleType, "getUpdatePriority", Vehicle.getUpdatePriority)
SpecializationUtil.registerFunction(vehicleType, "getPrice", Vehicle.getPrice)
SpecializationUtil.registerFunction(vehicleType, "getSellPrice", Vehicle.getSellPrice)
SpecializationUtil.registerFunction(vehicleType, "getDailyUpkeep", Vehicle.getDailyUpkeep)
SpecializationUtil.registerFunction(vehicleType, "getIsOnField", Vehicle.getIsOnField)
SpecializationUtil.registerFunction(vehicleType, "getParentComponent", Vehicle.getParentComponent)
SpecializationUtil.registerFunction(vehicleType, "getLastSpeed", Vehicle.getLastSpeed)
SpecializationUtil.registerFunction(vehicleType, "getDeactivateOnLeave", Vehicle.getDeactivateOnLeave)
SpecializationUtil.registerFunction(vehicleType, "getOwnerConnection", Vehicle.getOwnerConnection)
SpecializationUtil.registerFunction(vehicleType, "getIsVehicleNode", Vehicle.getIsVehicleNode)
SpecializationUtil.registerFunction(vehicleType, "getIsOperating", Vehicle.getIsOperating)
SpecializationUtil.registerFunction(vehicleType, "getIsActive", Vehicle.getIsActive)
SpecializationUtil.registerFunction(vehicleType, "getIsActiveForInput", Vehicle.getIsActiveForInput)
SpecializationUtil.registerFunction(vehicleType, "getIsActiveForSound", Vehicle.getIsActiveForSound)
SpecializationUtil.registerFunction(vehicleType, "getIsLowered", Vehicle.getIsLowered)
SpecializationUtil.registerFunction(vehicleType, "updateWaterInfo", Vehicle.updateWaterInfo)
SpecializationUtil.registerFunction(vehicleType, "onWaterRaycastCallback", Vehicle.onWaterRaycastCallback)
SpecializationUtil.registerFunction(vehicleType, "setBroken", Vehicle.setBroken)
SpecializationUtil.registerFunction(vehicleType, "getVehicleDamage", Vehicle.getVehicleDamage)
SpecializationUtil.registerFunction(vehicleType, "getRepairPrice", Vehicle.getRepairPrice)
SpecializationUtil.registerFunction(vehicleType, "getRepaintPrice", Vehicle.getRepaintPrice)
SpecializationUtil.registerFunction(vehicleType, "setMassDirty", Vehicle.setMassDirty)
SpecializationUtil.registerFunction(vehicleType, "updateMass", Vehicle.updateMass)
SpecializationUtil.registerFunction(vehicleType, "getMaxComponentMassReached", Vehicle.getMaxComponentMassReached)
SpecializationUtil.registerFunction(vehicleType, "getAdditionalComponentMass", Vehicle.getAdditionalComponentMass)
SpecializationUtil.registerFunction(vehicleType, "getTotalMass", Vehicle.getTotalMass)
SpecializationUtil.registerFunction(vehicleType, "getComponentMass", Vehicle.getComponentMass)
SpecializationUtil.registerFunction(vehicleType, "getDefaultMass", Vehicle.getDefaultMass)
SpecializationUtil.registerFunction(vehicleType, "getOverallCenterOfMass", Vehicle.getOverallCenterOfMass)
SpecializationUtil.registerFunction(vehicleType, "getVehicleWorldXRot", Vehicle.getVehicleWorldXRot)
SpecializationUtil.registerFunction(vehicleType, "getVehicleWorldDirection", Vehicle.getVehicleWorldDirection)
SpecializationUtil.registerFunction(vehicleType, "getFillLevelInformation", Vehicle.getFillLevelInformation)
SpecializationUtil.registerFunction(vehicleType, "activate", Vehicle.activate)
SpecializationUtil.registerFunction(vehicleType, "deactivate", Vehicle.deactivate)
SpecializationUtil.registerFunction(vehicleType, "setComponentJointFrame", Vehicle.setComponentJointFrame)
SpecializationUtil.registerFunction(vehicleType, "setComponentJointRotLimit", Vehicle.setComponentJointRotLimit)
SpecializationUtil.registerFunction(vehicleType, "setComponentJointTransLimit", Vehicle.setComponentJointTransLimit)
SpecializationUtil.registerFunction(vehicleType, "loadComponentFromXML", Vehicle.loadComponentFromXML)
SpecializationUtil.registerFunction(vehicleType, "loadComponentJointFromXML", Vehicle.loadComponentJointFromXML)
SpecializationUtil.registerFunction(vehicleType, "createComponentJoint", Vehicle.createComponentJoint)
SpecializationUtil.registerFunction(vehicleType, "loadSchemaOverlay", Vehicle.loadSchemaOverlay)
SpecializationUtil.registerFunction(vehicleType, "getAdditionalSchemaText", Vehicle.getAdditionalSchemaText)
SpecializationUtil.registerFunction(vehicleType, "getUseTurnedOnSchema", Vehicle.getUseTurnedOnSchema)
SpecializationUtil.registerFunction(vehicleType, "dayChanged", Vehicle.dayChanged)
SpecializationUtil.registerFunction(vehicleType, "periodChanged", Vehicle.periodChanged)
SpecializationUtil.registerFunction(vehicleType, "raiseStateChange", Vehicle.raiseStateChange)
SpecializationUtil.registerFunction(vehicleType, "doCheckSpeedLimit", Vehicle.doCheckSpeedLimit)
SpecializationUtil.registerFunction(vehicleType, "interact", Vehicle.interact)
SpecializationUtil.registerFunction(vehicleType, "getInteractionHelp", Vehicle.getInteractionHelp)
SpecializationUtil.registerFunction(vehicleType, "getIsInteractive", Vehicle.getIsInteractive)
SpecializationUtil.registerFunction(vehicleType, "getDistanceToNode", Vehicle.getDistanceToNode)
SpecializationUtil.registerFunction(vehicleType, "getIsAIActive", Vehicle.getIsAIActive)
SpecializationUtil.registerFunction(vehicleType, "getIsPowered", Vehicle.getIsPowered)
SpecializationUtil.registerFunction(vehicleType, "getRequiresPower", Vehicle.getRequiresPower)
SpecializationUtil.registerFunction(vehicleType, "getIsInShowroom", Vehicle.getIsInShowroom)
SpecializationUtil.registerFunction(vehicleType, "addVehicleToAIImplementList", Vehicle.addVehicleToAIImplementList)
SpecializationUtil.registerFunction(vehicleType, "setOperatingTime", Vehicle.setOperatingTime)
SpecializationUtil.registerFunction(vehicleType, "requestActionEventUpdate", Vehicle.requestActionEventUpdate)
SpecializationUtil.registerFunction(vehicleType, "removeActionEvents", Vehicle.removeActionEvents)
SpecializationUtil.registerFunction(vehicleType, "updateActionEvents", Vehicle.updateActionEvents)
SpecializationUtil.registerFunction(vehicleType, "registerActionEvents", Vehicle.registerActionEvents)
SpecializationUtil.registerFunction(vehicleType, "addActionEvent", Vehicle.addActionEvent)
SpecializationUtil.registerFunction(vehicleType, "updateSelectableObjects", Vehicle.updateSelectableObjects)
SpecializationUtil.registerFunction(vehicleType, "registerSelectableObjects", Vehicle.registerSelectableObjects)
SpecializationUtil.registerFunction(vehicleType, "addSubselection", Vehicle.addSubselection)
SpecializationUtil.registerFunction(vehicleType, "getRootVehicle", Vehicle.getRootVehicle)
SpecializationUtil.registerFunction(vehicleType, "findRootVehicle", Vehicle.findRootVehicle)
SpecializationUtil.registerFunction(vehicleType, "getChildVehicles", Vehicle.getChildVehicles)
SpecializationUtil.registerFunction(vehicleType, "addChildVehicles", Vehicle.addChildVehicles)
SpecializationUtil.registerFunction(vehicleType, "updateVehicleChain", Vehicle.updateVehicleChain)
SpecializationUtil.registerFunction(vehicleType, "getCanBeSelected", Vehicle.getCanBeSelected)
SpecializationUtil.registerFunction(vehicleType, "getBlockSelection", Vehicle.getBlockSelection)
SpecializationUtil.registerFunction(vehicleType, "getCanToggleSelectable", Vehicle.getCanToggleSelectable)
SpecializationUtil.registerFunction(vehicleType, "unselectVehicle", Vehicle.unselectVehicle)
SpecializationUtil.registerFunction(vehicleType, "selectVehicle", Vehicle.selectVehicle)
SpecializationUtil.registerFunction(vehicleType, "getIsSelected", Vehicle.getIsSelected)
SpecializationUtil.registerFunction(vehicleType, "getSelectedObject", Vehicle.getSelectedObject)
SpecializationUtil.registerFunction(vehicleType, "getSelectedVehicle", Vehicle.getSelectedVehicle)
SpecializationUtil.registerFunction(vehicleType, "setSelectedVehicle", Vehicle.setSelectedVehicle)
SpecializationUtil.registerFunction(vehicleType, "setSelectedObject", Vehicle.setSelectedObject)
SpecializationUtil.registerFunction(vehicleType, "getIsReadyForAutomatedTrainTravel", Vehicle.getIsReadyForAutomatedTrainTravel)
SpecializationUtil.registerFunction(vehicleType, "getIsAutomaticShiftingAllowed", Vehicle.getIsAutomaticShiftingAllowed)
SpecializationUtil.registerFunction(vehicleType, "getSpeedLimit", Vehicle.getSpeedLimit)
SpecializationUtil.registerFunction(vehicleType, "getRawSpeedLimit", Vehicle.getRawSpeedLimit)
SpecializationUtil.registerFunction(vehicleType, "getActiveFarm", Vehicle.getActiveFarm)
SpecializationUtil.registerFunction(vehicleType, "onVehicleWakeUpCallback", Vehicle.onVehicleWakeUpCallback)
SpecializationUtil.registerFunction(vehicleType, "getCanBeMounted", Vehicle.getCanBeMounted)
SpecializationUtil.registerFunction(vehicleType, "getName", Vehicle.getName)
SpecializationUtil.registerFunction(vehicleType, "getFullName", Vehicle.getFullName)
SpecializationUtil.registerFunction(vehicleType, "getBrand", Vehicle.getBrand)
SpecializationUtil.registerFunction(vehicleType, "getImageFilename", Vehicle.getImageFilename)
SpecializationUtil.registerFunction(vehicleType, "getCanBePickedUp", Vehicle.getCanBePickedUp)
SpecializationUtil.registerFunction(vehicleType, "getCanBeReset", Vehicle.getCanBeReset)
SpecializationUtil.registerFunction(vehicleType, "getCanBeSold", Vehicle.getCanBeSold)
SpecializationUtil.registerFunction(vehicleType, "getReloadXML", Vehicle.getReloadXML)
SpecializationUtil.registerFunction(vehicleType, "getIsInUse", Vehicle.getIsInUse)
SpecializationUtil.registerFunction(vehicleType, "getPropertyState", Vehicle.getPropertyState)
SpecializationUtil.registerFunction(vehicleType, "getAreControlledActionsAllowed", Vehicle.getAreControlledActionsAllowed)
SpecializationUtil.registerFunction(vehicleType, "getAreControlledActionsAvailable", Vehicle.getAreControlledActionsAvailable)
SpecializationUtil.registerFunction(vehicleType, "getAreControlledActionsAccessible", Vehicle.getAreControlledActionsAccessible)
SpecializationUtil.registerFunction(vehicleType, "getControlledActionIcons", Vehicle.getControlledActionIcons)
SpecializationUtil.registerFunction(vehicleType, "playControlledActions", Vehicle.playControlledActions)
SpecializationUtil.registerFunction(vehicleType, "getActionControllerDirection", Vehicle.getActionControllerDirection)
SpecializationUtil.registerFunction(vehicleType, "createMapHotspot", Vehicle.createMapHotspot)
SpecializationUtil.registerFunction(vehicleType, "getMapHotspot", Vehicle.getMapHotspot)
SpecializationUtil.registerFunction(vehicleType, "updateMapHotspot", Vehicle.updateMapHotspot)
SpecializationUtil.registerFunction(vehicleType, "getIsMapHotspotVisible", Vehicle.getIsMapHotspotVisible)
SpecializationUtil.registerFunction(vehicleType, "getMapHotspotRotation", Vehicle.getMapHotspotRotation)
SpecializationUtil.registerFunction(vehicleType, "getMapHotspotPosition", Vehicle.getMapHotspotPosition)
SpecializationUtil.registerFunction(vehicleType, "getShowInVehiclesOverview", Vehicle.getShowInVehiclesOverview)
SpecializationUtil.registerFunction(vehicleType, "showInfo", Vehicle.showInfo)
SpecializationUtil.registerFunction(vehicleType, "loadObjectChangeValuesFromXML", Vehicle.loadObjectChangeValuesFromXML)
SpecializationUtil.registerFunction(vehicleType, "setObjectChangeValues", Vehicle.setObjectChangeValues)
SpecializationUtil.registerFunction(vehicleType, "getIsSynchronized", Vehicle.getIsSynchronized)
end
---
function Vehicle.init()
g_vehicleConfigurationManager:addConfigurationType("baseColor", g_i18n:getText("configuration_baseColor"), nil, VehicleConfigurationItemColor)
g_vehicleConfigurationManager:addConfigurationType("vehicleType", g_i18n:getText("configuration_design"), nil, VehicleConfigurationItemVehicleType)
g_vehicleConfigurationManager:addConfigurationType("component", g_i18n:getText("configuration_design"), "base", VehicleConfigurationItem)
g_vehicleConfigurationManager:addConfigurationType("design", g_i18n:getText("configuration_design"), nil, VehicleConfigurationItem)
g_vehicleConfigurationManager:addConfigurationType("designColor", g_i18n:getText("configuration_designColor"), nil, VehicleConfigurationItemColor)
for i=2, 16 do
g_vehicleConfigurationManager:addConfigurationType(string.format("design%d", i), g_i18n:getText("configuration_design"), nil, VehicleConfigurationItem)
g_vehicleConfigurationManager:addConfigurationType(string.format("designColor%d", i), g_i18n:getText("configuration_designColor"), nil, VehicleConfigurationItemColor)
end
g_storeManager:addSpecType("age", "shopListAttributeIconLifeTime", nil, Vehicle.getSpecValueAge, StoreSpecies.VEHICLE)
g_storeManager:addSpecType("operatingTime", "shopListAttributeIconOperatingHours", nil, Vehicle.getSpecValueOperatingTime, StoreSpecies.VEHICLE)
g_storeManager:addSpecType("dailyUpkeep", "shopListAttributeIconMaintenanceCosts", nil, Vehicle.getSpecValueDailyUpkeep, StoreSpecies.VEHICLE)
g_storeManager:addSpecType("workingWidth", "shopListAttributeIconWorkingWidth", Vehicle.loadSpecValueWorkingWidth, Vehicle.getSpecValueWorkingWidth, StoreSpecies.VEHICLE)
g_storeManager:addSpecType("workingWidthConfig", "shopListAttributeIconWorkingWidth", Vehicle.loadSpecValueWorkingWidthConfig, Vehicle.getSpecValueWorkingWidthConfig, StoreSpecies.VEHICLE)
g_storeManager:addSpecType("speedLimit", "shopListAttributeIconWorkSpeed", Vehicle.loadSpecValueSpeedLimit, Vehicle.getSpecValueSpeedLimit, StoreSpecies.VEHICLE)
g_storeManager:addSpecType("weight", "shopListAttributeIconWeight", Vehicle.loadSpecValueWeight, Vehicle.getSpecValueWeight, StoreSpecies.VEHICLE, nil, Vehicle.getSpecConfigValuesWeight)
g_storeManager:addSpecType("additionalWeight", "shopListAttributeIconAdditionalWeight", Vehicle.loadSpecValueAdditionalWeight, Vehicle.getSpecValueAdditionalWeight, StoreSpecies.VEHICLE)
g_storeManager:addSpecType("combinations", nil, Vehicle.loadSpecValueCombinations, Vehicle.getSpecValueCombinations, StoreSpecies.VEHICLE)
g_storeManager:addSpecType("slots", "shopListAttributeIconSlots", nil, Vehicle.getSpecValueSlots, StoreSpecies.VEHICLE)
Vehicle.xmlSchema = XMLSchema.new("vehicle")
g_storeManager:addSpeciesXMLSchema(StoreSpecies.VEHICLE, Vehicle.xmlSchema)
g_vehicleTypeManager:setXMLSchema(Vehicle.xmlSchema)
Vehicle.xmlSchemaSounds = XMLSchema.new("vehicle_sounds")
Vehicle.xmlSchemaSounds:setRootNodeName("sounds")
Vehicle.xmlSchema:addSubSchema(Vehicle.xmlSchemaSounds, "sounds")
Vehicle.xmlSchemaSavegame = XMLSchema.new("savegame_vehicles")
Vehicle.registers()
end
---
function Vehicle.postInit()
local schema = Vehicle.xmlSchema
local schemaSavegame = Vehicle.xmlSchemaSavegame
local configurations = g_vehicleConfigurationManager:getConfigurations()
for _, configuration in pairs(configurations) do
g_asyncTaskManager:addSubtask(function()
if configuration.itemClass.registerXMLPaths ~= nil then
configuration.itemClass.registerXMLPaths(schema, configuration.configurationsKey, configuration.configurationKey .. "(?)")
end
schema:register(XMLValueType.FLOAT, configuration.configurationKey .. "(?)#workingWidth", "Work width to display in shop while config is active")
schema:register(XMLValueType.L10N_STRING, configuration.configurationKey .. "(?)#typeDesc", "Type description text to display in shop while config is active")
if configuration.itemClass.registerSavegameXMLPaths ~= nil then
configuration.itemClass.registerSavegameXMLPaths(schemaSavegame, "vehicles.vehicle(?).configuration(?)")
-- for backward compatibility
configuration.itemClass.registerSavegameXMLPaths(schemaSavegame, "vehicles.vehicle(?).boughtConfiguration(?)")
end
end)
end
end
---
function Vehicle.registers()
local schema = Vehicle.xmlSchema
local schemaSavegame = Vehicle.xmlSchemaSavegame
schema:register(XMLValueType.STRING, "vehicle#type", "Vehicle type")
schema:registerAutoCompletionDataSource("vehicle#type", "$dataS/vehicleTypes.xml", "vehicleTypes.type#name")
schema:register(XMLValueType.STRING, "vehicle.annotation", "Annotation", nil, true)
StoreManager.registerStoreDataXMLPaths(schema, "vehicle")
schema:register(XMLValueType.STRING, "vehicle.storeData.specs.workingWidth", "Working width to display in shop")
schema:register(XMLValueType.STRING, "vehicle.storeData.specs.combination(?)#xmlFilename", "Combination to display in shop")
schema:registerAutoCompletionDataSource("vehicle.storeData.specs.combination(?)#xmlFilename", "dataS/storeItems.xml", "storeItems.storeItem#xmlFilename")
schema:register(XMLValueType.STRING, "vehicle.storeData.specs.combination(?)#filterCategory", "Filter in this category")
schema:registerAutoCompletionDataSource("vehicle.storeData.specs.combination(?)#filterCategory", "$dataS/storeCategories.xml", "categories.category#name")
schema:register(XMLValueType.STRING, "vehicle.storeData.specs.combination(?)#filterSpec", "Filter for this spec type")
schema:register(XMLValueType.FLOAT, "vehicle.storeData.specs.combination(?)#filterSpecMin", "Filter spec type in this range (min.)")
schema:register(XMLValueType.FLOAT, "vehicle.storeData.specs.combination(?)#filterSpecMax", "Filter spec type in this range (max.)")
schema:register(XMLValueType.BOOL, "vehicle.storeData.specs.weight#ignore", "Hide vehicle weight in shop", false)
schema:register(XMLValueType.FLOAT, "vehicle.storeData.specs.weight#minValue", "Min. weight to display in shop")
schema:register(XMLValueType.FLOAT, "vehicle.storeData.specs.weight#maxValue", "Max. weight to display in shop")
schema:register(XMLValueType.STRING, "vehicle.storeData.specs.weight.config(?)#name", "Name of configuration")
schema:register(XMLValueType.INT, "vehicle.storeData.specs.weight.config(?)#index", "Index of selected configuration")
schema:register(XMLValueType.FLOAT, "vehicle.storeData.specs.weight.config(?)#value", "Weight value which can be reached with this configuration")
schema:register(XMLValueType.STRING, "vehicle.base.filename", "Path to i3d filename", nil)
schema:register(XMLValueType.L10N_STRING, "vehicle.base.typeDesc", "Type description", nil)
schema:register(XMLValueType.BOOL, "vehicle.base.synchronizePosition", "Vehicle position synchronized", true)
schema:register(XMLValueType.BOOL, "vehicle.base.supportsPickUp", "Vehicle can be picked up by hand", false)
schema:register(XMLValueType.BOOL, "vehicle.base.canBeReset", "Vehicle can be reset to shop", true)
schema:register(XMLValueType.BOOL, "vehicle.base.showInVehicleMenu", "Vehicle shows in vehicle menu", true)
schema:register(XMLValueType.BOOL, "vehicle.base.supportsRadio", "Vehicle supported radio", true)
schema:register(XMLValueType.BOOL, "vehicle.base.input#allowed", "Vehicle allows key input", true)
schema:register(XMLValueType.BOOL, "vehicle.base.selection#allowed", "Vehicle selection is allowed", true)
schema:register(XMLValueType.FLOAT, "vehicle.base.tailwaterDepth#warning", "Tailwater depth warning is shown from this water depth", "25% of vehicle height")
schema:register(XMLValueType.FLOAT, "vehicle.base.tailwaterDepth#threshold", "Vehicle is broken after this water depth", "75% of vehicle height")
schema:register(XMLValueType.STRING, "vehicle.base.mapHotspot#type", "Map hotspot type", nil, nil, table.toList(VehicleHotspot.TYPE))
schema:register(XMLValueType.BOOL, "vehicle.base.mapHotspot#available", "Map hotspot is available", true)
schema:register(XMLValueType.FLOAT, "vehicle.base.speedLimit#value", "Speed limit")
schema:register(XMLValueType.FLOAT, "vehicle.base.size#width", "Occupied width of the vehicle when loaded", nil, true)
schema:register(XMLValueType.FLOAT, "vehicle.base.size#length", "Occupied length of the vehicle when loaded", nil, true)
schema:register(XMLValueType.FLOAT, "vehicle.base.size#height", "Occupied height of the vehicle when loaded")
schema:register(XMLValueType.FLOAT, "vehicle.base.size#widthOffset", "Width offset")
schema:register(XMLValueType.FLOAT, "vehicle.base.size#lengthOffset", "Width offset")
schema:register(XMLValueType.FLOAT, "vehicle.base.size#heightOffset", "Height offset")
schema:register(XMLValueType.ANGLE, "vehicle.base.size#yRotation", "Y Rotation offset in i3d (Needs to be set to the vehicle's rotation in the i3d file and is e.g. used to check ai working direction)", 0)
schema:register(XMLValueType.NODE_INDEX, "vehicle.base.steeringAxle#node", "Steering axle node used to calculate the steering angle of attachments")
schema:register(XMLValueType.STRING, "vehicle.base.sounds#filename", "Path to external sound files")
schema:register(XMLValueType.FLOAT, "vehicle.base.sounds#volumeFactor", "This factor will be applied to all sounds of this vehicle")
I3DUtil.registerI3dMappingXMLPaths(schema, "vehicle")
Vehicle.registerComponentXMLPaths(schema, "vehicle.base.components")
Vehicle.registerComponentXMLPaths(schema, "vehicle.base.componentConfigurations.componentConfiguration(?)")
ObjectChangeUtil.registerObjectChangesXMLPaths(schema, "vehicle.base")
schema:register(XMLValueType.VECTOR_2, "vehicle.base.schemaOverlay#attacherJointPosition", "Position of attacher joint")
schema:register(XMLValueType.VECTOR_2, "vehicle.base.schemaOverlay#basePosition", "Position of vehicle")
schema:register(XMLValueType.STRING, "vehicle.base.schemaOverlay#name", "Name of schema overlay")
schema:registerAutoCompletionDataSource("vehicle.base.schemaOverlay#name", "$dataS/vehicleSchemaOverlays.xml", "vehicleSchemaOverlays.overlay#name")
schema:register(XMLValueType.FLOAT, "vehicle.base.schemaOverlay#invisibleBorderRight", "Size of invisible border on the right")
schema:register(XMLValueType.FLOAT, "vehicle.base.schemaOverlay#invisibleBorderLeft", "Size of invisible border on the left")
schema:register(XMLValueType.STRING, "vehicle.vehicleTypeConfigurations.vehicleTypeConfiguration(?)#vehicleType", "Vehicle type for configuration")
schema:register(XMLValueType.BOOL, "vehicle.designConfigurations#preLoad", "Defines if the design configurations are applied before the execution of load or after. Can help if the configurations manipulate the wheel positions for example.", false)
StoreItemUtil.registerConfigurationSetXMLPaths(schema, "vehicle")
schemaSavegame:register(XMLValueType.BOOL, "vehicles#loadAnyFarmInSingleplayer", "Load any farm in singleplayer", false)
schemaSavegame:register(XMLValueType.STRING, "vehicles.vehicle(?)#filename", "XML filename")
schemaSavegame:register(XMLValueType.STRING, "vehicles.vehicle(?)#modName", "Vehicle mod name")
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)#isBroken", "If the vehicle is broken", false)
schemaSavegame:register(XMLValueType.BOOL, "vehicles.vehicle(?)#defaultFarmProperty", "Property of default farm", false)
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?)#id", "Vehicle id")
schemaSavegame:register(XMLValueType.STRING, "vehicles.vehicle(?)#tourId", "Tour id")
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?)#farmId", "Farm id")
schemaSavegame:register(XMLValueType.STRING, "vehicles.vehicle(?)#uniqueId", "Vehicle's unique id")
schemaSavegame:register(XMLValueType.FLOAT, "vehicles.vehicle(?)#age", "Age in number of months")
schemaSavegame:register(XMLValueType.FLOAT, "vehicles.vehicle(?)#price", "Price")
VehiclePropertyState.registerXMLPath(schemaSavegame, "vehicles.vehicle(?)#propertyState", "Property state", nil, false)
schemaSavegame:register(XMLValueType.FLOAT, "vehicles.vehicle(?)#operatingTime", "Operating time")
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?)#selectedObjectIndex", "Selected object index")
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?)#subSelectedObjectIndex", "Sub selected object index")
schemaSavegame:register(XMLValueType.INT, "vehicles.vehicle(?).component(?)#index", "Component index")
schemaSavegame:register(XMLValueType.VECTOR_TRANS, "vehicles.vehicle(?).component(?)#position", "Component position")
schemaSavegame:register(XMLValueType.VECTOR_ROT, "vehicles.vehicle(?).component(?)#rotation", "Component rotation")
VehicleActionController.registerXMLPaths(schemaSavegame, "vehicles.vehicle(?).actionController")
schemaSavegame:register(XMLValueType.INT, "vehicles.attachments(?)#rootVehicleId", "Id of root vehicle")
end
---
function Vehicle.registerComponentXMLPaths(schema, basePath)
schema:register(XMLValueType.INT, basePath .. "#numComponents", "Number of components loaded from i3d", "number of components the i3d contains")
schema:register(XMLValueType.FLOAT, basePath .. "#maxMass", "Max. overall mass the vehicle can have", "unlimited")
schema:register(XMLValueType.NODE_INDEX, basePath .. "#directionReferenceNode", "Direction node to calculate the current driving direction and speed")
schema:register(XMLValueType.INT, basePath .. ".component(?)#index", "Index of the component node in the i3d hierarchy")
schema:register(XMLValueType.FLOAT, basePath .. ".component(?)#mass", "Mass of component [kg]", "Mass of component in i3d")
schema:register(XMLValueType.VECTOR_TRANS, basePath .. ".component(?)#centerOfMass", "Center of mass in local space (x y z)", "Center of mass in i3d")
schema:register(XMLValueType.VECTOR_TRANS, basePath .. ".component(?)#inertiaScale", "Scales the inertia, defining how the mass is distributed around the object (x y z, x = inertia around the local x axis). Inertia quadratically depends on the object radius. E.g. using an inertiaScale of 4 is equal to having a 2 times larger object along the given axis", "1 1 1")
schema:register(XMLValueType.INT, basePath .. ".component(?)#solverIterationCount", "Solver iterations count")
schema:register(XMLValueType.BOOL, basePath .. ".component(?)#motorized", "Is motorized component", "set by motorized specialization")
schema:register(XMLValueType.BOOL, basePath .. ".component(?)#collideWithAttachables", "Collides with attachables", false)
schema:register(XMLValueType.INT, basePath .. ".joint(?)#component1", "First component of the joint")
schema:register(XMLValueType.INT, basePath .. ".joint(?)#component2", "Second component of the joint")
schema:register(XMLValueType.NODE_INDEX, basePath .. ".joint(?)#node", "Joint node")
schema:register(XMLValueType.NODE_INDEX, basePath .. ".joint(?)#nodeActor1", "Actor node of second component", "Joint node")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#rotLimit", "Rotation limit", "0 0 0")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#transLimit", "Translation limit", "0 0 0")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#rotMinLimit", "Min rotation limit", "inversed rotation limit")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#transMinLimit", "Min translation limit", "inversed translation limit")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#rotLimitSpring", "Rotation spring limit", "0 0 0")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#rotLimitDamping", "Rotation damping limit", "1 1 1")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#rotLimitForceLimit", "Rotation limit force limit (-1 = infinite)", "-1 -1 -1")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#transLimitForceLimit", "Translation limit force limit (-1 = infinite)", "-1 -1 -1")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#transLimitSpring", "Translation spring limit", "0 0 0")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#transLimitDamping", "Translation damping limit", "1 1 1")
schema:register(XMLValueType.NODE_INDEX, basePath .. ".joint(?)#zRotationNode", "Position of joints z rotation")
schema:register(XMLValueType.BOOL, basePath .. ".joint(?)#breakable", "Joint is breakable", false)
schema:register(XMLValueType.FLOAT, basePath .. ".joint(?)#breakForce", "Joint force until it breaks", 10)
schema:register(XMLValueType.FLOAT, basePath .. ".joint(?)#breakTorque", "Joint torque until it breaks", 10)
schema:register(XMLValueType.BOOL, basePath .. ".joint(?)#enableCollision", "Enable collision between both components", false)
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#maxRotDriveForce", "Max rotational drive force", "0 0 0")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#rotDriveVelocity", "Rotational drive velocity")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#rotDriveRotation", "Rotational drive rotation")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#rotDriveSpring", "Rotational drive spring", "0 0 0")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#rotDriveDamping", "Rotational drive damping", "0 0 0")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#transDriveVelocity", "Translational drive velocity")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#transDrivePosition", "Translational drive position")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#transDriveSpring", "Translational drive spring", "0 0 0")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#transDriveDamping", "Translational drive damping", "1 1 1")
schema:register(XMLValueType.VECTOR_3, basePath .. ".joint(?)#maxTransDriveForce", "Max translational drive force", "0 0 0")
schema:register(XMLValueType.BOOL, basePath .. ".joint(?)#initComponentPosition", "Defines if the component is translated and rotated during loading based on joint movement", true)
schema:register(XMLValueType.BOOL, basePath .. ".collisionPair(?)#enabled", "Collision between components enabled")
schema:register(XMLValueType.INT, basePath .. ".collisionPair(?)#component1", "Index of first component")
schema:register(XMLValueType.INT, basePath .. ".collisionPair(?)#component2", "Index of second component")
end
---
function Vehicle.new(isServer, isClient, customMt)
local self = Object.new(isServer, isClient, customMt or Vehicle_mt)
self.finishedLoading = false
self.isDeleted = false
self.updateLoopIndex = -1
self.sharedLoadRequestId = nil
self.loadingState = VehicleLoadingState.OK
self.loadingStep = SpecializationLoadStep.CREATED
self.loadingTasks = {}
self.readyForFinishLoading = false
-- The unique id of vehicle used to reference it from elsewhere.
self.uniqueId = nil
self.actionController = VehicleActionController.new(self)
return self
end
---
function Vehicle:setFilename(filename)
self.configFileName = filename
self.configFileNameClean = Utils.getFilenameInfo(filename, true)
self.customEnvironment, self.baseDirectory = Utils.getModNameAndBaseDirectory(filename)
end
---
function Vehicle:setConfigurations(configurations, boughtConfigurations, configurationData)
self.configurations, self.boughtConfigurations = configurations, boughtConfigurations
self.configurationData = configurationData or self.configurationData
if self.configurationData == nil then
self.configurationData = {}
end
end
---
function Vehicle:setType(typeDef)
assertWithCallstack(self.configFileName ~= nil, "Setting vehicle type without setting a filename previously. Call 'setFilename' first!")
if self.configurations ~= nil then
local configItem = ConfigurationUtil.getConfigItemByConfigId(self.configFileName, "vehicleType", self.configurations["vehicleType"])
if configItem ~= nil then
if configItem.vehicleType ~= nil then
local configType = g_vehicleTypeManager:getTypeByName(configItem.vehicleType, self.customEnvironment)
if configType ~= nil then
typeDef = configType
else
Logging.warning("Unknown vehicle type '%s' in configuration for '%s'", configItem.vehicleType, self.configFileName)
end
end
end
end
SpecializationUtil.initSpecializationsIntoTypeClass(g_vehicleTypeManager, typeDef, self)
end
---
function Vehicle:setLoadCallback(loadCallbackFunction, loadCallbackFunctionTarget, loadCallbackFunctionArguments)
self.loadCallbackFunction = loadCallbackFunction
self.loadCallbackFunctionTarget = loadCallbackFunctionTarget
self.loadCallbackFunctionArguments = loadCallbackFunctionArguments
end
---
function Vehicle:loadCallback()
if self.loadCallbackFunction ~= nil then
self.loadCallbackFunction(self.loadCallbackFunctionTarget, self, self.loadingState, self.loadCallbackFunctionArguments)
self.loadCallbackFunction = nil
end
end
---
function Vehicle:load(vehicleLoadingData)
self.vehicleLoadingData = vehicleLoadingData
self:setLoadingStep(SpecializationLoadStep.PRE_LOAD)
self.isVehicleSaved = vehicleLoadingData.isSaved
if self.type == nil then
Logging.xmlWarning(self.xmlFile, "Unable to find vehicleType")
self:setLoadingState(VehicleLoadingState.ERROR)
return self.loadingState
end
self.actionEvents = {}
self.xmlFile = XMLFile.load("vehicleXML", self.configFileName, Vehicle.xmlSchema)
self.savegame = vehicleLoadingData.savegameData
self.isAddedToPhysics = false
local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
if storeItem ~= nil then
self.brand = g_brandManager:getBrandByIndex(storeItem.brandIndex)
self.lifetime = storeItem.lifetime
end
self.externalSoundsFilename = self.xmlFile:getValue("vehicle.base.sounds#filename")
if self.externalSoundsFilename ~= nil then
self.externalSoundsFilename = Utils.getFilename(self.externalSoundsFilename, self.baseDirectory)
self.externalSoundsFile = XMLFile.load("TempExternalSounds", self.externalSoundsFilename, Vehicle.xmlSchemaSounds)
end
self.soundVolumeFactor = self.xmlFile:getValue("vehicle.base.sounds#volumeFactor")
-- pass function pointers from specializations to 'self'
SpecializationUtil.copyTypeFunctionsInto(self.type, self)
-- check if one of the configurations is not set - e.g. if new configurations are available but not in savegame
local item = g_storeManager:getItemByXMLFilename(self.configFileName)
if item ~= nil and item.configurations ~= nil then
-- check if the loaded configurations do match the configuration sets
-- if not we apply the set which has the most common configurations
-- e.g. if a new configuration was added to the configuration set we make sure we don't break old savegames
if item.configurationSets ~= nil and #item.configurationSets > 0 then
if not ConfigurationUtil.getConfigurationsMatchConfigSets(self.configurations, item.configurationSets) then
local closestSet, closestSetMatches = ConfigurationUtil.getClosestConfigurationSet(self.configurations, item.configurationSets)
if closestSet ~= nil then
for configName, index in pairs(closestSet.configurations) do
self.configurations[configName] = index
end
Logging.xmlInfo(self.xmlFile, "Savegame configurations do not match the configuration sets! Apply closest configuration set '%s' with %d matching configurations.", closestSet.name, closestSetMatches)
end
end
end
for configName, _ in pairs(item.configurations) do
local defaultConfigId = StoreItemUtil.getDefaultConfigId(item, configName)
if self.configurations[configName] == nil then
ConfigurationUtil.setConfiguration(self, configName, defaultConfigId)
end
-- base configuration is always included
ConfigurationUtil.addBoughtConfiguration(g_vehicleConfigurationManager, self, configName, defaultConfigId)
end
-- check if currently used configurations are still available
for configName, value in pairs(self.configurations) do
if item.configurations[configName] == nil then
Logging.xmlWarning(self.xmlFile, "Configurations are not present anymore. Ignoring this configuration (%s)!", configName)
self.configurations[configName] = nil
self.boughtConfigurations[configName] = nil
else
local defaultConfigId = StoreItemUtil.getDefaultConfigId(item, configName)
if #item.configurations[configName] < value then
Logging.xmlWarning(self.xmlFile, "Configuration with index '%d' is not present anymore. Using default configuration instead! (%s)", value, configName)
if self.boughtConfigurations[configName] ~= nil then
self.boughtConfigurations[configName][value] = nil
if next(self.boughtConfigurations[configName]) == nil then
self.boughtConfigurations[configName] = nil
end
end
ConfigurationUtil.setConfiguration(self, configName, defaultConfigId)
else
ConfigurationUtil.addBoughtConfiguration(g_vehicleConfigurationManager, self, configName, value)
end
end
end
end
SpecializationUtil.createSpecializationEnvironments(self, function(specName, specEntryName)
Logging.xmlError(self.xmlFile, "The vehicle specialization '%s' could not be added because variable '%s' already exists!", specName, specEntryName)
self:setLoadingState(VehicleLoadingState.ERROR)
end)
SpecializationUtil.raiseEvent(self, "onPreLoad", self.savegame)
if self.loadingState ~= VehicleLoadingState.OK then
Logging.xmlError(self.xmlFile, "Vehicle pre-loading failed!")
self.xmlFile:delete()
return false
end
ConfigurationUtil.raiseConfigurationItemEvent(self, "onPreLoad")
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.filename", "vehicle.base.filename") --FS17 to FS19
self.i3dFilename = Utils.getFilename(self.xmlFile:getValue("vehicle.base.filename"), self.baseDirectory)
if string.contains(self.i3dFilename, "\\") then
Logging.xmlWarning(self.xmlFile, "Filename contains backslashes, which are not allowed! (%s)", "vehicle.base.filename")
end
self:setLoadingStep(SpecializationLoadStep.AWAIT_I3D)
self.sharedLoadRequestId = g_i3DManager:loadSharedI3DFileAsync(self.i3dFilename, true, false, self.i3dFileLoaded, self)
return nil
end
---
function Vehicle:i3dFileLoaded(i3dNode, failedReason, arguments, i3dLoadingId)
if i3dNode == 0 then
self:setLoadingState(VehicleLoadingState.ERROR)
Logging.xmlError(self.xmlFile, "Vehicle i3d loading failed!")
self:loadCallback()
return
end
self.i3dNode = i3dNode
setVisibility(i3dNode, false)
g_asyncTaskManager:addTask(function()
self:loadFinished()
end)
end
---
function Vehicle:loadFinished()
local realNumComponents
local componentsKey
local numComponents
self:addAsyncTask(function()
self:setLoadingState(VehicleLoadingState.OK)
self:setLoadingStep(SpecializationLoadStep.LOAD)
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.forcedMapHotspotType", "vehicle.base.mapHotspot#type") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.base.forcedMapHotspotType", "vehicle.base.mapHotspot#type") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.speedLimit#value", "vehicle.base.speedLimit#value") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.steeringAxleNode#index", "vehicle.base.steeringAxle#node") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.size#width", "vehicle.base.size#width") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.size#length", "vehicle.base.size#length") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.size#widthOffset", "vehicle.base.size#widthOffset") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.size#lengthOffset", "vehicle.base.size#lengthOffset") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.typeDesc", "vehicle.base.typeDesc") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.components", "vehicle.base.components") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.components.component", "vehicle.base.components.component") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.base.components.component1", "vehicle.base.components.component") --FS17 to FS19
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, "vehicle.base.mapHotspot#hasDirection") --FS22 to FS25
end, "Vehicle - Deprecated Check")
self:addAsyncTask(function()
local savegame = self.savegame
if savegame ~= nil then
self.tourId = nil
local tourId = savegame.xmlFile:getValue(savegame.key.."#tourId")
if tourId ~= nil then
self.tourId = tourId
g_guidedTourManager:addVehicle(self, self.tourId)
end
end
self.age = 0
self.propertyState = self.vehicleLoadingData.propertyState
self:setOwnerFarmId(self.vehicleLoadingData.ownerFarmId, true)
if savegame ~= nil then
local uniqueId = savegame.xmlFile:getValue(savegame.key .. "#uniqueId", nil)
if uniqueId ~= nil then
self:setUniqueId(uniqueId)
end
if not savegame.ignoreFarmId then
-- Load this early: it used by the vehicle load functions already
local farmId = savegame.xmlFile:getValue(savegame.key .. "#farmId", AccessHandler.EVERYONE)
if g_farmManager.mergedFarms ~= nil and g_farmManager.mergedFarms[farmId] ~= nil then
farmId = g_farmManager.mergedFarms[farmId]
end
self:setOwnerFarmId(farmId, true)
end
end
self.price = self.vehicleLoadingData.price
if self.price == 0 or self.price == nil then
local storeItem = g_storeManager:getItemByXMLFilename(self.configFileName)
self.price = StoreItemUtil.getDefaultPrice(storeItem, self.configurations)
end
self.typeDesc = self.xmlFile:getValue("vehicle.base.typeDesc", "TypeDescription", self.customEnvironment, true)
for name, configDesc in pairs(g_vehicleConfigurationManager:getConfigurations()) do
local configurationKey = string.format("%s(%d)", configDesc.configurationKey, (self.configurations[name] or 1) - 1)
local typeDesc = self.xmlFile:getValue(configurationKey .. "#typeDesc", nil, self.customEnvironment, false)
if typeDesc ~= nil then
self.typeDesc = typeDesc
end
end
self.synchronizePosition = self.xmlFile:getValue("vehicle.base.synchronizePosition", true)
self.highPrecisionPositionSynchronization = false
self.supportsPickUp = self.xmlFile:getValue("vehicle.base.supportsPickUp", false)
self.canBeReset = self.xmlFile:getValue("vehicle.base.canBeReset", true)
self.showInVehicleOverview = self.xmlFile:getValue("vehicle.base.showInVehicleMenu", true)
self.rootNode = getChildAt(self.i3dNode, 0)
self.serverMass = 0
self.precalculatedMass = 0 -- mass of vehicle that is not included in serverMass (e.g. wheels)
self.isMassDirty = false
self.currentUpdateDistance = 0
self.lastDistanceToCamera = 0
self.lodDistanceCoeff = getLODDistanceCoeff()
self.viewDistanceCoeff = getViewDistanceCoeff()
self.components = {}
self.vehicleNodes = {}
realNumComponents = getNumOfChildren(self.i3dNode)
local rootPosition = {0,0,0}
local componentConfigurationId = self.configurations["component"] or 1
componentsKey = string.format("vehicle.base.componentConfigurations.componentConfiguration(%d)", componentConfigurationId - 1)
if not self.xmlFile:hasProperty(componentsKey) then
componentsKey = "vehicle.base.components"
end
numComponents = self.xmlFile:getValue(componentsKey .. "#numComponents", realNumComponents)
self.maxComponentMass = self.xmlFile:getValue(componentsKey .. "#maxMass", math.huge) / 1000
self.rootLevelNodes = {}
for i=1, realNumComponents do
local rootLevelNode = {}
rootLevelNode.node = getChildAt(self.i3dNode, i - 1)
rootLevelNode.isInactive = true
if not getVisibility(rootLevelNode.node) then
Logging.xmlDevWarning(self.xmlFile, "Found hidden component '%s' in i3d file. Components are not allowed to be hidden!", getName(rootLevelNode.node))
end
setVisibility(rootLevelNode.node, false)
table.insert(self.rootLevelNodes, rootLevelNode)
end
for componentIndex, componentKey in self.xmlFile:iterator(componentsKey .. ".component") do
if componentIndex > numComponents then
Logging.xmlWarning(self.xmlFile, "Invalid components count. I3D file has '%d' components, but tried to load component no. '%d'!", numComponents, componentIndex+1)
break
end
local i3dIndex = self.xmlFile:getValue(componentKey .. "#index", componentIndex) - 1
local component = {}
component.node = getChildAt(self.i3dNode, i3dIndex)
if self:loadComponentFromXML(component, self.xmlFile, componentKey, rootPosition, componentIndex) then
local x,y,z = getWorldTranslation(component.node)
local qx,qy,qz,qw = getWorldQuaternion(component.node)
component.networkInterpolators = {}
component.networkInterpolators.position = InterpolatorPosition.new(x, y, z)
component.networkInterpolators.quaternion = InterpolatorQuaternion.new(qx, qy, qz, qw)
table.insert(self.components, component)
end
end
for _, component in ipairs(self.components) do
link(getRootNode(), component.node)
end
end, "Vehicle - Components Loading")
self:addAsyncTask(function()
-- root level nodes represent all nodes on root level
-- components and inactive components which have not been loaded
-- this is used to initialize the i3D mapping still correctly for the unused component nodes, so we don't have to adjust the whole xml file
for _, rootLevelNode in ipairs(self.rootLevelNodes) do
for _, component in ipairs(self.components) do
if component.node == rootLevelNode.node then
rootLevelNode.isInactive = false
end
end
if rootLevelNode.isInactive then
-- inactive components are stored hidden in the root component
local x, y, z = getWorldTranslation(rootLevelNode.node)
local rx, ry, rz = getWorldRotation(rootLevelNode.node)
link(self.components[1].node, rootLevelNode.node)
setWorldTranslation(rootLevelNode.node, x, y, z)
setWorldRotation(rootLevelNode.node, rx, ry, rz)
setRigidBodyType(rootLevelNode.node, RigidBodyType.NONE)
I3DUtil.iterateRecursively(rootLevelNode.node, function(node)
if getIsCompoundChild(node) then
setIsCompoundChild(node, false)
end
end)
end
end
delete(self.i3dNode)
self.i3dNode = nil
self.numComponents = #self.components
if numComponents ~= self.numComponents then
Logging.xmlWarning(self.xmlFile, "I3D file offers '%d' objects, but '%d' components have been loaded!", numComponents, self.numComponents)
end
if Vehicle.DEBUG_RANDOM_FAIL_LOADING and math.random() > 0.75 then
self.numComponents = 0
end
if self.numComponents == 0 then
Logging.xmlWarning(self.xmlFile, "No components defined for vehicle!")
self:setLoadingState(VehicleLoadingState.ERROR)
self:loadCallback()
end
end, "Vehicle - I3D Delete")
self:addAsyncTask(function()
self.defaultMass = 0
for j=1, #self.components do
self.defaultMass = self.defaultMass + self.components[j].defaultMass
end
-- load i3d mappings
self.i3dMappings = {}
I3DUtil.loadI3DMapping(self.xmlFile, "vehicle", self.rootLevelNodes, self.i3dMappings, realNumComponents)
end, "Vehicle - I3D mapping")
self:addAsyncTask(function()
-- need to be defined in vehicle because all vehicles can define a steering axle ref node
self.steeringAxleNode = self.xmlFile:getValue("vehicle.base.steeringAxle#node", nil, self.components, self.i3dMappings)
if self.steeringAxleNode == nil then
self.steeringAxleNode = self.components[1].node
end
self:loadSchemaOverlay(self.xmlFile)
end, "Vehicle - Schema Overlays")
self:addAsyncTask(function()
-- load component joints
self.componentJoints = {}
for componentJointIndex, componentJointKey in self.xmlFile:iterator(componentsKey .. ".joint") do
local index1 = self.xmlFile:getValue(componentJointKey.."#component1")
local index2 = self.xmlFile:getValue(componentJointKey.."#component2")
XMLUtil.checkDeprecatedXMLElements(self.xmlFile, componentJointKey .. "#index", componentJointKey .. "#node") --FS17 to FS19
if index1 == nil or index2 == nil then
Logging.xmlWarning(self.xmlFile, "Missing component index in component joint '%s'", componentJointKey)
break
end
local jointNode = self.xmlFile:getValue(componentJointKey.."#node", nil, self.components, self.i3dMappings)
if jointNode ~= nil and jointNode ~= 0 then
local jointDesc = {}
if self:loadComponentJointFromXML(jointDesc, self.xmlFile, componentJointKey, componentJointIndex-1, jointNode, index1, index2) then
table.insert(self.componentJoints, jointDesc)
jointDesc.index = #self.componentJoints
end
end
end
end, "Vehicle - Component Joints")
self:addAsyncTask(function()
self.collisionPairs = {}
for collisionPairIndex, collisionPairKey in self.xmlFile:iterator(componentsKey .. ".collisionPair") do
local enabled = self.xmlFile:getValue(collisionPairKey.."#enabled")
local index1 = self.xmlFile:getValue(collisionPairKey.."#component1")
local index2 = self.xmlFile:getValue(collisionPairKey.."#component2")
if index1 ~= nil and index2 ~= nil and enabled ~= nil then
local component1 = self.components[index1]
local component2 = self.components[index2]
if component1 ~= nil and component2 ~= nil then
if not enabled then
table.insert(self.collisionPairs, {component1=component1, component2=component2, enabled=enabled})
end
else
Logging.xmlWarning(self.xmlFile, "Failed to load collision pair '%s'. Unknown component indices. Indices start with 1.", collisionPairKey)
end
end
end
end, "Vehicle - Collision Pairs")
self:addAsyncTask(function()
self.supportsRadio = self.xmlFile:getValue("vehicle.base.supportsRadio", true)
self.allowsInput = self.xmlFile:getValue("vehicle.base.input#allowed", true)
self.size = StoreItemUtil.getSizeValuesFromXML(self.configFileName, self.xmlFile, "vehicle", 0, self.configurations)
end, "Vehicle - Size")
self:addAsyncTask(function()
self.yRotationOffset = self.xmlFile:getValue("vehicle.base.size#yRotation", 0.0)
self.showTailwaterDepthWarning = false
self.thresholdTailwaterDepthWarning = self.xmlFile:getValue("vehicle.base.tailwaterDepth#warning", self.size.height * 0.25)
self.thresholdTailwaterDepth = self.xmlFile:getValue("vehicle.base.tailwaterDepth#threshold", self.size.height * 0.75)
self.networkTimeInterpolator = InterpolationTime.new(1.2)
self.movingDirection = 0
self.rotatedTime = 0
self.isBroken = false
self.forceIsActive = false
self.finishedFirstUpdate = false
self.lastPosition = nil
self.lastSpeed = 0
self.lastSpeedReal = 0
self.lastSpeedSmoothed = 0
self.lastSignedSpeed = 0
self.lastSignedSpeedReal = 0
self.lastMovedDistance = 0
self.lastSpeedAcceleration = 0
self.lastMoveTime = -10000
self.operatingTime = 0
self.allowSelection = self.xmlFile:getValue("vehicle.base.selection#allowed", true)
self.isInWater = false
self.isInShallowWater = false
self.isInMediumWater = false
self.waterY = -200
self.tailwaterDepth = -200
self.waterCheckPosition = {0, 0, 0}
self.currentSelection = {object=nil, index=0, subIndex=1}
self.selectionObject = {index=0, isSelected=false, vehicle=self, subSelections={}}
self.childVehicles = {self} -- table including all attached children and the vehicle itself
self.childVehicleHash = "" -- string with each child vehicles table address (can be used to compare and detect if the vehicles have been changed)
self.rootVehicle = self
self.registeredActionEvents = {}
self.actionEventUpdateRequested = false
self.vehicleDirtyFlag = self:getNextDirtyFlag()
if g_currentMission ~= nil and g_currentMission.environment ~= nil then