This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathFS22_EnhancedVehicle.lua
2604 lines (2230 loc) · 114 KB
/
FS22_EnhancedVehicle.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
--
-- Mod: FS22_EnhancedVehicle
--
-- Author: Majo76
-- email: [email protected]
-- @Date: 08.04.2022
-- @Version: 1.2.2.0
--[[
CHANGELOG
2022-04-08 - V1.2.2.0
* fix for rare "nan°" angle display
* translation updates
2022-02-18 - V1.2.1.0
+ added "tüdelü" sound when approaching headland trigger (thx "andre020478" for the sample)
+ added config menu option to specify the distance to headland for the alarm sound
* translation updates
2022-01-30 - V1.2.0.1
* bugfix for parking brake status not saved to savegame
2022-01-25 - V1.2.0.0
+ added a display for the remaining distance to the headland trigger
+ added config option to choose which lines should be displayed (all, none, tracks only, vehicle+working width only)
+ added config XML option to specify sfx volume
* ATTENTION: Way of "how it works" changed:
- Press RShift+Home to switch throught operating modes: "snap to direction" or "snap to track"
- Hold RShift+Home to disable track assistant
- Press RStrg+Numpad1 to (re)calculate working width
* leaving a vehicle will no longer disable snap direction/track
* remapped move offset line from RAlt+Numpad -/+ to RShift+RCtrl+Numpad -/+
2022-01-15 - V1.1.3.1
* translation updates
* updated differential lock sound
2022-01-11 - V1.1.3.0
+ added warning message if parking brake is applied when trying to move vehicle
+ added config XML option to move dmg/fuel HUD display in classic FS19 configuration
+ added config XML option to move misc (weight) HUD display
+ added config XML option to modify inactive/active color of some HUD elements
- removed the requirement to enable/disable functionality of parking brake to be able to use the brake
* small fix in "turn around" function
2022-01-04 - V1.1.2.0
+ re-added the background for dmg/fuel display in classic FS19 configuration
* parking brake should now work in manual transmission(+clutch) mode
* renamed "Handbremse" to "Feststellbremse"
* moved the global settings in configuration menu to the bottom
2022-01-02 - V1.1.1.1
* bugfix working width calculation (again and again...)
2022-01-02 - V1.1.1.0
+ support for Fahrenheit in HUD temperature display
* fixed headland/end of field detection (thx Stephan-S from FS22_AutoDrive)
* small adjustment to steering force (during snap to track)
* bugfix for cruise control issues
2022-01-01 - V1.1.0.0
+ (re)added the parking brake due to high community demand ;-)
+ added option to auto-hide guide lines after x seconds after vehicle follows track
* bugfixes for analog controler input devices (thx "Kotlett")
2021-12-31 - V1.0.1.0
+ added key binding to move vehicle one track to the left/right (in direction of travel; no turning) (rctrl + insert/delete)
+ added config file option to show "spikes" on track lines also
* reworked work width calculation (again). should now detect more attachments.
* changing track layout (position, width, offset) is now much more "smooth" when holding key pressed
* bugfix for display of wrong track numbers when rotating a fake track (thx "Kotlett")
2021-12-30 - V1.0.0.0
+ re-added option to move track and diff HUD elements via config XML
* bugfix for flickering HUD on dedi server when someone switches through vehicles
2021-12-27 - V1.0.0.0-rc5
* bugfix for the HUD being shown in vehicles where it should not be visible
2021-12-27 - V1.0.0.0-rc4
* fixed a rare bug for snap feature not working as expected on dedicated servers (thx "a Bit Brutal")
2021-12-26 - V1.0.0.0-rc3
+ added configuration menu option for "number of visible tracks"
+ added key binding to quickly change headland distance (RShift+Numpad / or RShift+Numpad *)
* bugfix for not being able to steer when globally disabling track assistant when snap to track is enabled
* minor change in calculation of workwidth. should now also work if vehicle and attachments are not aligned in a straight line
* changed default width of "virtual tracks" from 4m to 6m
2021-12-25 - V1.0.0.0-rc2
+ added option to show dmg/fuel above the speedmeter (classic) or on the top-right below the gameinfo panel
* disable follow track when resetting track
* minor modifications on key bindings and actionEvent code
2021-12-23 - V1.0.0.0-rc1
* another bugfix for multiplayer
2021-12-23 - V0.9.9.9
* HUD bugfix for dedicated server
2021-12-23 - V0.9.9.8
* rewritten the complete HUD code. looks better, fits GUI scaling.
+ added key binding to quickly cycle through headland modes
- removed key binding for "resume previous snap direction"
2021-12-20 - V0.9.9.7
+ support to increase/decrease width of calculated tracks
+ added support for "fake" tracks. use this if you have no attachment but want tracks. press rctrl+numpad2 twice.
* bugfix for attachments on attachments
* minor fixes
2021-12-19 - V0.9.9.6
* fixed some logic code bugs
* modified track display above speedometer a bit
2021-12-18 - V0.9.9.5
+ added headland behavior. open configuration menu to configure headland behavior for each vehicle.
2021-12-16 - V0.9.9.4
* display track number even when guide lines are turned off
* changed appearance of track display a bit: #actualtrack -> turnover -> nexttrack
* next track number in game world is rendered in green
2021-12-14 - V0.9.9.3
+ added functionality to move track layout left/right (rctrl+numpad minus/numpad plus)
+ added functionality to move track offset line left/right (rshift+numpad minus/numpad plus)
* smaller bugfixes
2021-12-13 - V0.9.9.2
+ added simple "turn around" feature. (when tracks enabled) press rctrl+home to turn. select amount of tracks to turn left/right by rctrl+num4/num6
+ added a small track number display above the speedometer
+ added a "snap off" sound. Not happy with that yet; it's just the "snap on" sound in reverse
* reworked the complete track handling and display code
* changed default colors: green = active, white = inactive
* small bugfix for negative degree display
2021-12-10 - V0.9.9.1
* fixed track numbers
* improved track handling (can now rotate grid)
2021-12-09 - V0.9.9.0
+ verhicle can now auto steer into the track (press rStrg + End if grid mode is on)
2021-12-07 - V0.9.8.3
* reworked workwidth calculation
+ support for attachments with offset (e.g. plow)
2021-12-06 - V0.9.8.0
+ added grid to visualize tracks (on/off: strg + numpad 1 # recalculate: strg + numpad 2)
2021-12-05 - V0.9.7.0
+ added configuration dialog for mod settings (strg + numpad /)
+ merged "snap to angle" feature to adjust rounding precision
+ merged option to show damage values in "% left" instead of "% damage"
+ added background behind the snap angle display
+ added zoomFactor config variable in XML for zoom of snap angle display
+ added Portuguese translation (thanks to TheChoseOne900)
+ added French translation (thanks to aurelien2023)
2021-11-29 - V0.9.6.0
+ added visualization for snap feature (shift + home)
2021-11-27 - V0.9.5.0
* reworked snap steering behavior
2021-11-26 - V0.9.3.0
* multiplayer fix for snap feature
2021-11-25 - V0.9.2.0
+ added basic "keep current direction" feature
2021-11-25 - V0.9.1.0
* reworked default key bindings
2021-11-25 - V0.9.0.0
* first release for FS22
* !!! WARNING !!! This version of EV has different default key bindings compared to FS19 !!!
* adjusted this and that for FS22 engine changes
+ added fuel support for "electric" and "methane"
- removed all shuttle control related stuff
- removed all "feinstaub" related stuff
license: https://creativecommons.org/licenses/by-nc-sa/4.0/
]]--
local myName = "FS22_EnhancedVehicle"
FS22_EnhancedVehicle = {}
local FS22_EnhancedVehicle_mt = Class(FS22_EnhancedVehicle)
-- #############################################################################
function FS22_EnhancedVehicle:new(mission, modDirectory, modName, i18n, gui, inputManager, messageCenter)
if debug > 1 then print("-> " .. myName .. ": new ") end
local self = {}
setmetatable(self, FS22_EnhancedVehicle_mt)
self.mission = mission
self.modDirectory = modDirectory
self.modName = modName
self.i18n = i18n
self.gui = gui
self.inputManager = inputManager
self.messageCenter = messageCenter
local modDesc = loadXMLFile("modDesc", modDirectory .. "modDesc.xml");
self.version = getXMLString(modDesc, "modDesc.version");
-- some global stuff - DONT touch
FS22_EnhancedVehicle.hud = {}
FS22_EnhancedVehicle.fS = g_currentMission.hud.speedMeter:scalePixelToScreenHeight(12)
FS22_EnhancedVehicle.sections = { 'fuel', 'dmg', 'misc', 'rpm', 'temp', 'diff', 'track', 'park' }
FS22_EnhancedVehicle.actions = {}
FS22_EnhancedVehicle.actions.global = { 'FS22_EnhancedVehicle_MENU' }
FS22_EnhancedVehicle.actions.park = { 'FS22_EnhancedVehicle_PARK' }
FS22_EnhancedVehicle.actions.snap = { 'FS22_EnhancedVehicle_SNAP_ONOFF',
'FS22_EnhancedVehicle_SNAP_REVERSE',
'FS22_EnhancedVehicle_SNAP_OPMODE',
'FS22_EnhancedVehicle_SNAP_CALC_WW',
'FS22_EnhancedVehicle_SNAP_GRID_RESET',
'FS22_EnhancedVehicle_SNAP_LINES_MODE',
'FS22_EnhancedVehicle_SNAP_TRACK',
'FS22_EnhancedVehicle_SNAP_TRACKP',
'FS22_EnhancedVehicle_SNAP_TRACKW',
'FS22_EnhancedVehicle_SNAP_TRACKO',
'FS22_EnhancedVehicle_SNAP_TRACKJ',
'FS22_EnhancedVehicle_SNAP_HL_MODE',
'FS22_EnhancedVehicle_SNAP_HL_DIST',
'FS22_EnhancedVehicle_SNAP_ANGLE1',
'FS22_EnhancedVehicle_SNAP_ANGLE2',
'FS22_EnhancedVehicle_SNAP_ANGLE3',
'AXIS_MOVE_SIDE_VEHICLE',
'AXIS_ACCELERATE_VEHICLE',
'AXIS_BRAKE_VEHICLE' }
FS22_EnhancedVehicle.actions.diff = { 'FS22_EnhancedVehicle_FD',
'FS22_EnhancedVehicle_RD',
'FS22_EnhancedVehicle_BD',
'FS22_EnhancedVehicle_DM' }
FS22_EnhancedVehicle.actions.hydraulic = { 'FS22_EnhancedVehicle_AJ_REAR_UPDOWN',
'FS22_EnhancedVehicle_AJ_REAR_ONOFF',
'FS22_EnhancedVehicle_AJ_FRONT_UPDOWN',
'FS22_EnhancedVehicle_AJ_FRONT_ONOFF' }
-- for key press delay
FS22_EnhancedVehicle.nextActionTime = 0
FS22_EnhancedVehicle.deltaActionTime = 500
FS22_EnhancedVehicle.minActionTime = 31.25
-- some colors
FS22_EnhancedVehicle.color = {
black = { 0, 0, 0, 1 },
white = { 1, 1, 1, 1 },
red = { 255/255, 0/255, 0/255, 1 },
darkred = { 128/255, 0/255, 0/255, 1 },
green = { 0/255, 255/255, 0/255, 1 },
blue = { 0/255, 0/255, 255/255, 1 },
yellow = { 255/255, 255/255, 0/255, 1 },
gray = { 128/255, 128/255, 128/255, 1 },
lgray = { 178/255, 178/255, 178/255, 1 },
dmg = { 255/255, 174/255, 0/255, 1 },
fuel = { 178/255, 214/255, 22/255, 1 },
adblue = { 48/255, 78/255, 249/255, 1 },
electric = { 255/255, 255/255, 0/255, 1 },
methane = { 0/255, 198/255, 255/255, 1 },
ls22blue = { 0/255, 198/255, 253/255, 1 },
}
FS22_EnhancedVehicle.hl_distances = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -12, -14, -16, -18, -20 }
-- load sound effects
if g_dedicatedServerInfo == nil then
local file, id
FS22_EnhancedVehicle.sounds = {}
for _, id in ipairs({"diff_lock", "brakeOn", "brakeOff", "snap_on", "snap_off", "hl_approach"}) do
FS22_EnhancedVehicle.sounds[id] = createSample(id)
file = self.modDirectory.."resources/"..id..".ogg"
loadSample(FS22_EnhancedVehicle.sounds[id], file, false)
end
end
return self
end
-- #############################################################################
function FS22_EnhancedVehicle:delete()
if debug > 1 then print("-> " .. myName .. ": delete ") end
-- delete our UI
FS22_EnhancedVehicle.ui_menu:delete()
-- delete our HUD
FS22_EnhancedVehicle.ui_hud:delete()
end
-- #############################################################################
function FS22_EnhancedVehicle:onMissionLoaded(mission)
if debug > 1 then print("-> " .. myName .. ": onMissionLoaded ") end
g_gui:loadProfiles(self.modDirectory.."ui/guiProfiles.xml")
FS22_EnhancedVehicle.ui_menu = FS22_EnhancedVehicle_UI.new()
g_gui:loadGui(self.modDirectory.."ui/FS22_EnhancedVehicle_UI.xml", "FS22_EnhancedVehicle_UI", FS22_EnhancedVehicle.ui_menu)
FS22_EnhancedVehicle.ui_hud = FS22_EnhancedVehicle_HUD:new(mission.hud.speedMeter, mission.hud.gameInfoDisplay, self.modDirectory)
FS22_EnhancedVehicle.ui_hud:load()
end
-- #############################################################################
function FS22_EnhancedVehicle:loadMap()
print("--> loaded FS22_EnhancedVehicle version " .. self.version .. " (by Majo76) <--");
-- first set our current and default config to default values
FS22_EnhancedVehicle:resetConfig()
-- then read values from disk and "overwrite" current config
lC:readConfig()
-- then write current config (which is now a merge between default values and from disk)
lC:writeConfig()
-- and finally activate current config
FS22_EnhancedVehicle:activateConfig()
end
-- #############################################################################
function FS22_EnhancedVehicle:unloadMap()
print("--> unloaded FS22_EnhancedVehicle version " .. self.version .. " (by Majo76) <--");
end
-- #############################################################################
function FS22_EnhancedVehicle.installSpecializations(vehicleTypeManager, specializationManager, modDirectory, modName)
if debug > 1 then print("-> " .. myName .. ": installSpecializations ") end
specializationManager:addSpecialization("EnhancedVehicle", "FS22_EnhancedVehicle", Utils.getFilename("FS22_EnhancedVehicle.lua", modDirectory), nil)
if specializationManager:getSpecializationByName("EnhancedVehicle") == nil then
print("ERROR: unable to add specialization 'FS22_EnhancedVehicle'")
else
for typeName, typeDef in pairs(vehicleTypeManager.types) do
if SpecializationUtil.hasSpecialization(Drivable, typeDef.specializations) and
SpecializationUtil.hasSpecialization(Enterable, typeDef.specializations) and
SpecializationUtil.hasSpecialization(Motorized, typeDef.specializations) and
not SpecializationUtil.hasSpecialization(Locomotive, typeDef.specializations) and
not SpecializationUtil.hasSpecialization(ConveyorBelt, typeDef.specializations) and
not SpecializationUtil.hasSpecialization(AIConveyorBelt, typeDef.specializations)
then
if debug > 1 then print("--> attached specialization 'EnhancedVehicle' to vehicleType '" .. tostring(typeName) .. "'") end
vehicleTypeManager:addSpecialization(typeName, modName..".EnhancedVehicle")
end
end
end
end
-- #############################################################################
function FS22_EnhancedVehicle.prerequisitesPresent(specializations)
if debug > 1 then print("-> " .. myName .. ": prerequisites ") end
return true
end
-- #############################################################################
function FS22_EnhancedVehicle.registerEventListeners(vehicleType)
if debug > 1 then print("-> " .. myName .. ": registerEventListeners ") end
for _,n in pairs( { "onLoad", "onPostLoad", "saveToXMLFile", "onUpdate", "onDraw", "onReadStream", "onWriteStream", "onRegisterActionEvents", "onEnterVehicle", "onLeaveVehicle", "onPostAttachImplement", "onPostDetachImplement" } ) do
SpecializationUtil.registerEventListener(vehicleType, n, FS22_EnhancedVehicle)
end
end
-- #############################################################################
-- ### function for others mods to enable/disable EnhancedVehicle functions
-- ### name: differential, hydraulic, snap
-- ### state: true or false
function FS22_EnhancedVehicle:functionEnable(name, state)
if name == "differential" then
lC:setConfigValue("global.functions", "diffIsEnabled", state)
FS22_EnhancedVehicle.functionDiffIsEnabled = state
end
if name == "hydraulic" then
lC:setConfigValue("global.functions", "hydraulicIsEnabled", state)
FS22_EnhancedVehicle.functionHydraulicIsEnabled = state
end
if name == "snap" then
lC:setConfigValue("global.functions", "snapIsEnabled", state)
FS22_EnhancedVehicle.functionSnapIsEnabled = state
end
if name == "park" then
lC:setConfigValue("global.functions", "parkingBrakeIsEnabled", state)
FS22_EnhancedVehicle.functionParkingBrakeIsEnabled = state
end
end
-- #############################################################################
-- ### function for others mods to get EnhancedVehicle functions status
-- ### name: differential, hydraulic, snap
-- ### returns true or false
function FS22_EnhancedVehicle:functionStatus(name)
if name == "differential" then
return(lC:getConfigValue("global.functions", "diffIsEnabled"))
end
if name == "hydraulic" then
return(lC:getConfigValue("global.functions", "hydraulicIsEnabled"))
end
if name == "snap" then
return(lC:getConfigValue("global.functions", "snapIsEnabled"))
end
if name == "park" then
return(lC:getConfigValue("global.functions", "parkingBrakeIsEnabled"))
end
return(nil)
end
-- #############################################################################
function FS22_EnhancedVehicle:activateConfig()
-- here we will "move" our config from the libConfig internal storage to the variables we actually use
-- functions
FS22_EnhancedVehicle.functionDiffIsEnabled = lC:getConfigValue("global.functions", "diffIsEnabled")
FS22_EnhancedVehicle.functionHydraulicIsEnabled = lC:getConfigValue("global.functions", "hydraulicIsEnabled")
FS22_EnhancedVehicle.functionSnapIsEnabled = lC:getConfigValue("global.functions", "snapIsEnabled")
FS22_EnhancedVehicle.functionParkingBrakeIsEnabled = lC:getConfigValue("global.functions", "parkingBrakeIsEnabled")
-- globals
FS22_EnhancedVehicle.showKeysInHelpMenu = lC:getConfigValue("global.misc", "showKeysInHelpMenu")
FS22_EnhancedVehicle.soundIsOn = lC:getConfigValue("global.misc", "soundIsOn")
-- snap
FS22_EnhancedVehicle.snap = {}
FS22_EnhancedVehicle.snap.snapToAngle = lC:getConfigValue("snap", "snapToAngle")
FS22_EnhancedVehicle.snap.attachmentSpikeHeight = lC:getConfigValue("snap", "attachmentSpikeHeight")
FS22_EnhancedVehicle.snap.trackSpikeHeight = lC:getConfigValue("snap", "trackSpikeHeight")
FS22_EnhancedVehicle.snap.distanceAboveGroundVehicleMiddleLine = lC:getConfigValue("snap", "distanceAboveGroundVehicleMiddleLine")
FS22_EnhancedVehicle.snap.distanceAboveGroundVehicleSideLine = lC:getConfigValue("snap", "distanceAboveGroundVehicleSideLine")
FS22_EnhancedVehicle.snap.distanceAboveGroundAttachmentSideLine = lC:getConfigValue("snap", "distanceAboveGroundAttachmentSideLine")
FS22_EnhancedVehicle.snap.colorVehicleMiddleLine = { lC:getConfigValue("snap.colorVehicleMiddleLine", "red"), lC:getConfigValue("snap.colorVehicleMiddleLine", "green"), lC:getConfigValue("snap.colorVehicleMiddleLine", "blue") }
FS22_EnhancedVehicle.snap.colorVehicleSideLine = { lC:getConfigValue("snap.colorVehicleSideLine", "red"), lC:getConfigValue("snap.colorVehicleSideLine", "green"), lC:getConfigValue("snap.colorVehicleSideLine", "blue") }
FS22_EnhancedVehicle.snap.colorAttachmentSideLine = { lC:getConfigValue("snap.colorAttachmentSideLine", "red"), lC:getConfigValue("snap.colorAttachmentSideLine", "green"), lC:getConfigValue("snap.colorAttachmentSideLine", "blue") }
-- track
FS22_EnhancedVehicle.track = {}
FS22_EnhancedVehicle.track.distanceAboveGround = lC:getConfigValue("track", "distanceAboveGround")
FS22_EnhancedVehicle.track.numberOfTracks = lC:getConfigValue("track", "numberOfTracks")
FS22_EnhancedVehicle.track.showLines = lC:getConfigValue("track", "showLines")
FS22_EnhancedVehicle.track.hideLines = lC:getConfigValue("track", "hideLines")
FS22_EnhancedVehicle.track.hideLinesAfter = lC:getConfigValue("track", "hideLinesAfter")
FS22_EnhancedVehicle.track.hideLinesAfterValue = 0
FS22_EnhancedVehicle.track.color = { lC:getConfigValue("track.color", "red"), lC:getConfigValue("track.color", "green"), lC:getConfigValue("track.color", "blue") }
FS22_EnhancedVehicle.track.headlandSoundTriggerDistance = lC:getConfigValue("track", "headlandSoundTriggerDistance")
-- HUD stuff
for _, section in pairs(FS22_EnhancedVehicle.sections) do
FS22_EnhancedVehicle.hud[section] = {}
FS22_EnhancedVehicle.hud[section].enabled = lC:getConfigValue("hud."..section, "enabled")
FS22_EnhancedVehicle.hud[section].fontSize = lC:getConfigValue("hud."..section, "fontSize")
FS22_EnhancedVehicle.hud[section].offsetX = lC:getConfigValue("hud."..section, "offsetX")
FS22_EnhancedVehicle.hud[section].offsetY = lC:getConfigValue("hud."..section, "offsetY")
end
FS22_EnhancedVehicle.hud.dmg.showAmountLeft = lC:getConfigValue("hud.dmg", "showAmountLeft")
FS22_EnhancedVehicle.hud.dmgfuelPosition = lC:getConfigValue("hud", "dmgfuelPosition")
FS22_EnhancedVehicle.hud.colorActive = { lC:getConfigValue("hud.colorActive", "red"), lC:getConfigValue("hud.colorActive", "green"), lC:getConfigValue("hud.colorActive", "blue"), 1 }
FS22_EnhancedVehicle.hud.colorInactive = { lC:getConfigValue("hud.colorInactive", "red"), lC:getConfigValue("hud.colorInactive", "green"), lC:getConfigValue("hud.colorInactive", "blue"), 1 }
FS22_EnhancedVehicle.hud.colorStandby = { lC:getConfigValue("hud.colorStandby", "red"), lC:getConfigValue("hud.colorStandby", "green"), lC:getConfigValue("hud.colorStandby", "blue"), 1 }
FS22_EnhancedVehicle.sfx_volume = {}
FS22_EnhancedVehicle.sfx_volume.track = lC:getConfigValue("sfx.track", "volume")
FS22_EnhancedVehicle.sfx_volume.brake = lC:getConfigValue("sfx.brake", "volume")
FS22_EnhancedVehicle.sfx_volume.diff = lC:getConfigValue("sfx.diff", "volume")
FS22_EnhancedVehicle.sfx_volume.hl_approach = lC:getConfigValue("sfx.hl_approach", "volume")
end
-- #############################################################################
function FS22_EnhancedVehicle:resetConfig(disable)
if debug > 0 then print("-> " .. myName .. ": resetConfig ") end
disable = false or disable
-- start fresh
lC:clearConfig()
-- functions
lC:addConfigValue("global.functions", "diffIsEnabled", "bool", true)
lC:addConfigValue("global.functions", "hydraulicIsEnabled", "bool", true)
lC:addConfigValue("global.functions", "snapIsEnabled", "bool", true)
lC:addConfigValue("global.functions", "parkingBrakeIsEnabled", "bool", true)
-- globals
lC:addConfigValue("global.misc", "showKeysInHelpMenu", "bool", true)
lC:addConfigValue("global.misc", "soundIsOn", "bool", true)
-- snap
lC:addConfigValue("snap", "snapToAngle", "float", 10.0)
lC:addConfigValue("snap", "attachmentSpikeHeight", "float", 0.75)
lC:addConfigValue("snap", "trackSpikeHeight", "float", 0)
lC:addConfigValue("snap", "distanceAboveGroundVehicleMiddleLine", "float", 0.3)
lC:addConfigValue("snap", "distanceAboveGroundVehicleSideLine", "float", 0.25)
lC:addConfigValue("snap", "distanceAboveGroundAttachmentSideLine", "float", 0.20)
lC:addConfigValue("snap.colorVehicleMiddleLine", "red", "float", 76/255)
lC:addConfigValue("snap.colorVehicleMiddleLine", "green", "float", 76/255)
lC:addConfigValue("snap.colorVehicleMiddleLine", "blue", "float", 76/255)
lC:addConfigValue("snap.colorVehicleSideLine", "red", "float", 255/255)
lC:addConfigValue("snap.colorVehicleSideLine", "green", "float", 0/255)
lC:addConfigValue("snap.colorVehicleSideLine", "blue", "float", 0/255)
lC:addConfigValue("snap.colorAttachmentSideLine", "red", "float", 100/255)
lC:addConfigValue("snap.colorAttachmentSideLine", "green", "float", 0/255)
lC:addConfigValue("snap.colorAttachmentSideLine", "blue", "float", 0/255)
-- track
lC:addConfigValue("track", "distanceAboveGround", "float", 0.15)
lC:addConfigValue("track", "numberOfTracks", "int", 5)
lC:addConfigValue("track", "showLines", "int", 1)
lC:addConfigValue("track", "hideLines", "bool", false)
lC:addConfigValue("track", "hideLinesAfter", "int", 5)
lC:addConfigValue("track.color", "red", "float", 255/255)
lC:addConfigValue("track.color", "green", "float", 150/255)
lC:addConfigValue("track.color", "blue", "float", 0/255)
lC:addConfigValue("track", "headlandSoundTriggerDistance", "int", 10)
-- fuel
lC:addConfigValue("hud.fuel", "enabled", "bool", true)
lC:addConfigValue("hud.fuel", "fontSize", "int", 12)
lC:addConfigValue("hud.fuel", "offsetX", "int", 0)
lC:addConfigValue("hud.fuel", "offsetY", "int", 0)
-- dmg
lC:addConfigValue("hud.dmg", "enabled", "bool", true)
lC:addConfigValue("hud.dmg", "fontSize", "int", 12)
lC:addConfigValue("hud.dmg", "showAmountLeft", "bool", false)
lC:addConfigValue("hud.dmg", "offsetX", "int", 0)
lC:addConfigValue("hud.dmg", "offsetY", "int", 0)
-- track
lC:addConfigValue("hud.track", "enabled", "bool", true)
lC:addConfigValue("hud.track", "offsetX", "int", 0)
lC:addConfigValue("hud.track", "offsetY", "int", 0)
-- misc
lC:addConfigValue("hud.misc", "enabled", "bool", true)
lC:addConfigValue("hud.misc", "offsetX", "int", 0)
lC:addConfigValue("hud.misc", "offsetY", "int", 0)
-- rpm
lC:addConfigValue("hud.rpm", "enabled", "bool", true)
-- temp
lC:addConfigValue("hud.temp", "enabled", "bool", true)
-- diff
lC:addConfigValue("hud.diff", "enabled", "bool", true)
lC:addConfigValue("hud.diff", "offsetX", "int", 0)
lC:addConfigValue("hud.diff", "offsetY", "int", 0)
-- park
lC:addConfigValue("hud.park", "enabled", "bool", true)
lC:addConfigValue("hud.park", "offsetX", "int", 0)
lC:addConfigValue("hud.park", "offsetY", "int", 0)
-- HUD position for dmg/fuel
lC:addConfigValue("hud", "dmgfuelPosition", "int", 2)
-- HUD more colors
lC:addConfigValue("hud.colorActive", "red", "float", 0/255)
lC:addConfigValue("hud.colorActive", "green", "float", 255/255)
lC:addConfigValue("hud.colorActive", "blue", "float", 0/255)
lC:addConfigValue("hud.colorInactive", "red", "float", 180/255)
lC:addConfigValue("hud.colorInactive", "green", "float", 180/255)
lC:addConfigValue("hud.colorInactive", "blue", "float", 180/255)
lC:addConfigValue("hud.colorStandby", "red", "float", 255/255)
lC:addConfigValue("hud.colorStandby", "green", "float", 174/255)
lC:addConfigValue("hud.colorStandby", "blue", "float", 0/255)
-- sound volumes
lC:addConfigValue("sfx.track", "volume", "float", 0.10)
lC:addConfigValue("sfx.brake", "volume", "float", 0.10)
lC:addConfigValue("sfx.diff", "volume", "float", 0.50)
lC:addConfigValue("sfx.hl_approach", "volume", "float", 0.10)
end
-- #############################################################################
function FS22_EnhancedVehicle:onLoad(savegame)
if debug > 1 then print("-> " .. myName .. ": onLoad" .. mySelf(self)) end
-- export functions for other mods
self.functionEnable = FS22_EnhancedVehicle.functionEnable
self.functionStatus = FS22_EnhancedVehicle.functionStatus
end
-- #############################################################################
function FS22_EnhancedVehicle:onPostLoad(savegame)
if debug > 1 then print("-> " .. myName .. ": onPostLoad" .. mySelf(self)) end
-- vData
-- 1 - frontDiffIsOn
-- 2 - backDiffIsOn
-- 3 - drive mode
-- 4 - snapAngle
-- 5 - snap.enable
-- 6 - snap on track
-- 7 - track px
-- 8 - track pz
-- 9 - track dX
-- 10 - track dZ
-- 11 - track snapx
-- 12 - track snapz
-- 13 - parking brake on
-- initialize vehicle data with defaults
self.vData = {}
self.vData.is = { nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil }
self.vData.want = { false, false, 1, 0.0, false, false, 0, 0, 0, 0, 0, 0, false }
self.vData.torqueRatio = { 0.5, 0.5, 0.5 }
self.vData.maxSpeedRatio = { 1.0, 1.0, 1.0 }
self.vData.rot = 0.0
self.vData.axisSidePrev = 0.0
self.vData.opMode = 0
self.vData.triggerCalculate = false
self.vData.impl = { isCalculated = false }
self.vData.track = { isCalculated = false, deltaTrack = 1, headlandMode = 1, headlandDistance = 9999, isOnField = 0, eofDistance = -1, eofNext = 0 }
-- (server) set some defaults
if self.isServer then
for _, differential in ipairs(self.spec_motorized.differentials) do
if differential.diffIndex1 == 1 then -- front
self.vData.torqueRatio[1] = differential.torqueRatio
self.vData.maxSpeedRatio[1] = differential.maxSpeedRatio
end
if differential.diffIndex1 == 3 then -- back
self.vData.torqueRatio[2] = differential.torqueRatio
self.vData.maxSpeedRatio[2] = differential.maxSpeedRatio
end
if differential.diffIndex1 == 0 and differential.diffIndex1IsWheel == false then -- front_to_back
self.vData.torqueRatio[3] = differential.torqueRatio
self.vData.maxSpeedRatio[3] = differential.maxSpeedRatio
end
end
end
-- load vehicle status from savegame
if savegame ~= nil then
local xmlFile = savegame.xmlFile
local key = savegame.key ..".FS22_EnhancedVehicle.EnhancedVehicle"
local _data
for _, _data in pairs( { {1, 'frontDiffIsOn'}, {2, 'backDiffIsOn'}, {3, 'driveMode'}, {13, 'parkingBrakeIsOn'} }) do
local idx = _data[1]
local _v
if idx == 3 then
_v = getXMLInt(xmlFile.handle, key.."#".. _data[2])
else
_v = getXMLBool(xmlFile.handle, key.."#".. _data[2])
end
if _v ~= nil then
if idx == 3 then
self.vData.want[idx] = _v
if debug > 1 then print("--> found ".._data[2].."=".._v.." in savegame" .. mySelf(self)) end
else
if _v then
self.vData.want[idx] = true
if debug > 1 then print("--> found ".._data[2].."=true in savegame" .. mySelf(self)) end
else
self.vData.want[idx] = false
if debug > 1 then print("--> found ".._data[2].."=false in savegame" .. mySelf(self)) end
end
end
end
end
end
-- update vehicle parameters
if self.isServer then
FS22_EnhancedVehicle:updatevData(self)
elseif self.isClient then
self.vData.is = { unpack(self.vData.want) }
end
if debug > 0 then print("--> setup of vData done" .. mySelf(self)) end
end
-- #############################################################################
function FS22_EnhancedVehicle:saveToXMLFile(xmlFile, key)
if debug > 1 then print("-> " .. myName .. ": saveToXMLFile" .. mySelf(self)) end
if self.vData.is[1] ~= nil then setXMLBool(xmlFile.handle, key.."#frontDiffIsOn", self.vData.is[1]) else print("-> EV: saveToXMLFile warning [1]") end
if self.vData.is[2] ~= nil then setXMLBool(xmlFile.handle, key.."#backDiffIsOn", self.vData.is[2]) else print("-> EV: saveToXMLFile warning [2]") end
if self.vData.is[3] ~= nil then setXMLInt(xmlFile.handle, key.."#driveMode", self.vData.is[3]) else print("-> EV: saveToXMLFile warning [3]") end
if self.vData.is[13] ~= nil then setXMLBool(xmlFile.handle, key.."#parkingBrakeIsOn", self.vData.is[13]) else print("-> EV: saveToXMLFile warning [13]") end
end
-- #############################################################################
function FS22_EnhancedVehicle:onReadStream(streamId, connection)
if debug > 1 then print("-> " .. myName .. ": onReadStream - " .. streamId .. mySelf(self)) end
-- receive initial data from server
self.vData.is[1] = streamReadBool(streamId) -- front diff
self.vData.is[2] = streamReadBool(streamId) -- back diff
self.vData.is[3] = streamReadInt8(streamId) -- drive mode
self.vData.is[4] = streamReadFloat32(streamId) -- snap angle
self.vData.is[5] = streamReadBool(streamId) -- snap.enable
self.vData.is[6] = streamReadBool(streamId) -- snap on track
self.vData.is[7] = streamReadFloat32(streamId) -- snap track px
self.vData.is[8] = streamReadFloat32(streamId) -- snap track pz
self.vData.is[9] = streamReadFloat32(streamId) -- snap track dX
self.vData.is[10] = streamReadFloat32(streamId) -- snap track dZ
self.vData.is[11] = streamReadFloat32(streamId) -- snap track snap x
self.vData.is[12] = streamReadFloat32(streamId) -- snap track snap z
self.vData.is[13] = streamReadBool(streamId) -- parking brake on
if self.isClient then
self.vData.want = { unpack(self.vData.is) }
end
-- if debug then print(DebugUtil.printTableRecursively(self.vData, 0, 0, 2)) end
end
-- #############################################################################
function FS22_EnhancedVehicle:onWriteStream(streamId, connection)
if debug > 1 then print("-> " .. myName .. ": onWriteStream - " .. streamId .. mySelf(self)) end
-- send initial data to client
streamWriteBool(streamId, self.vData.is[1])
streamWriteBool(streamId, self.vData.is[2])
streamWriteInt8(streamId, self.vData.is[3])
streamWriteFloat32(streamId, self.vData.is[4])
streamWriteBool(streamId, self.vData.is[5])
streamWriteBool(streamId, self.vData.is[6])
streamWriteFloat32(streamId, self.vData.is[7])
streamWriteFloat32(streamId, self.vData.is[8])
streamWriteFloat32(streamId, self.vData.is[9])
streamWriteFloat32(streamId, self.vData.is[10])
streamWriteFloat32(streamId, self.vData.is[11])
streamWriteFloat32(streamId, self.vData.is[12])
streamWriteBool(streamId, self.vData.is[13])
end
-- #############################################################################
function FS22_EnhancedVehicle:onUpdate(dt)
if debug > 2 then print("-> " .. myName .. ": onUpdate " .. dt .. ", S: " .. tostring(self.isServer) .. ", C: " .. tostring(self.isClient) .. mySelf(self)) end
-- (client)
if FS22_EnhancedVehicle.functionSnapIsEnabled and self.isClient then
-- delayed onPostDetach
if self.vData.triggerCalculate and self.vData.triggerCalculateTime < g_currentMission.time then
self.vData.triggerCalculate = false
self.vData.opModeOld = self.vData.opMode
if self.vData.opMode > 0 then self.vData.opMode = 1 end
FS22_EnhancedVehicle:enumerateImplements(self)
end
-- get current vehicle position, direction
local isControlled = self.getIsControlled ~= nil and self:getIsControlled()
local isEntered = self.getIsEntered ~= nil and self:getIsEntered()
if isControlled and isEntered then
-- position, direction, rotation
self.vData.px, self.vData.py, self.vData.pz = localToWorld(self.rootNode, 0, 0, 0)
self.vData.dx, self.vData.dy, self.vData.dz = localDirectionToWorld(self.rootNode, 0, 0, 1)
local length = MathUtil.vector2Length(self.vData.dx, self.vData.dz);
self.vData.dirX = self.vData.dx / length
self.vData.dirZ = self.vData.dz / length
-- calculate current rotation
local rot = 180 - math.deg(math.atan2(self.vData.dx, self.vData.dz))
-- if cabin is rotated -> direction should rotate also
if self.spec_drivable.reverserDirection < 0 then
rot = rot + 180
if rot >= 360 then rot = rot - 360 end
end
rot = Round(rot, 1)
if rot >= 360.0 then rot = 0 end
self.vData.rot = rot
-- when track assistant is active and calculated
if self.vData.opMode == 2 and self.vData.track.isCalculated then
-- is a plow attached?
if self.vData.impl.plow ~= nil then
if self.vData.impl.plow.rotationMax ~= self.vData.track.plow then
self.vData.track.plow = self.vData.impl.plow.rotationMax
self.vData.impl.offset = -self.vData.impl.offset
self.vData.track.offset = -self.vData.track.offset
FS22_EnhancedVehicle:updateTrack(self, false, 0, false, 0, true, 0)
end
end
-- get distance to end-of-field each second
if self.vData.track.eofNext < g_currentMission.time then
FS22_EnhancedVehicle:getHeadlandDistance(self)
self.vData.track.eofNext = g_currentMission.time + 500
-- play sound
if self.vData.is[5] and self.vData.is[6] then
if self.vData.track.headlandMode >= 1 and self.vData.track.isOnField > 5 and self.vData.track.eofDistance > 0 then
if self.vData.track.eofDistance < FS22_EnhancedVehicle.track.headlandSoundTriggerDistance then
if self.vData.track.hl_samplePlayed == nil then
playSample(FS22_EnhancedVehicle.sounds["hl_approach"], 1, Between(FS22_EnhancedVehicle.sfx_volume.hl_approach, 0, 10), 0, 0, 0)
self.vData.track.hl_samplePlayed = true
end
else
self.vData.track.hl_samplePlayed = nil
end
end
end
end
-- headland management
if self.vData.is[5] and self.vData.is[6] then
local isOnField = FS22_EnhancedVehicle:getHeadlandInfo(self)
if self.vData.track.isOnField <= 5 and isOnField then
if Round(self.vData.rot, 0) == Round(self.vData.is[4], 0) then
self.vData.track.isOnField = self.vData.track.isOnField + 1
if debug > 1 then print("Headland: enter field") end
end
end
if self.vData.track.isOnField > 5 and not isOnField then
self.vData.track.isOnField = 0
if debug > 1 then print("Headland: left field") end
-- handle headland
if self.vData.track.headlandMode <= 1 then
if debug > 1 then print("Headland: do nothing") end
elseif self.vData.track.headlandMode == 2 then
if debug > 1 then print("Headland: turn around") end
FS22_EnhancedVehicle.onActionCall(self, "FS22_EnhancedVehicle_SNAP_REVERSE", 0, 0, 0, 0)
elseif self.vData.track.headlandMode == 3 then
if debug > 1 then print("Headland: disable cruise control") end
if self.spec_drivable ~= nil and self.spec_drivable.cruiseControl ~= nil then
if self.spec_drivable.cruiseControl.state ~= Drivable.CRUISECONTROL_STATE_OFF then
self:setCruiseControlState(Drivable.CRUISECONTROL_STATE_OFF)
end
end
end
end
end -- <- end headland
else
self.vData.track.eofDistance = -1
end -- <- end track assistant
end
end
-- (server) process changes between "is" and "want"
if self.isServer and self.vData ~= nil then
FS22_EnhancedVehicle:updatevData(self)
end
end
-- #############################################################################
function FS22_EnhancedVehicle:updatevData(self)
if debug > 2 then print("-> " .. myName .. ": updatevData ".. mySelf(self)) end
-- snap angle change
if self.vData.is[4] ~= self.vData.want[4] then
if FS22_EnhancedVehicle.functionSnapIsEnabled then
if debug > 0 then print("--> ("..self.rootNode..") changed snap angle to: "..self.vData.want[4]) end
end
self.vData.is[4] = self.vData.want[4]
end
-- snap.enable
if self.vData.is[5] ~= self.vData.want[5] then
if FS22_EnhancedVehicle.functionSnapIsEnabled then
if self.vData.want[5] then
if debug > 0 then print("--> ("..self.rootNode..") changed snap enable to: ON") end
else
if debug > 0 then print("--> ("..self.rootNode..") changed snap enable to: OFF") end
end
end
self.vData.is[5] = self.vData.want[5]
end
-- snap on track
if self.vData.is[6] ~= self.vData.want[6] then
if FS22_EnhancedVehicle.functionSnapIsEnabled then
if self.vData.want[6] then
if debug > 0 then print("--> ("..self.rootNode..") changed snap on track to: ON") end
else
if debug > 0 then print("--> ("..self.rootNode..") changed snap on track to: OFF") end
end
end
self.vData.is[6] = self.vData.want[6]
end
-- snap track x
if self.vData.is[7] ~= self.vData.want[7] then
if FS22_EnhancedVehicle.functionSnapIsEnabled then
if debug > 0 then print("--> ("..self.rootNode..") changed track px: "..self.vData.want[7]) end
end
self.vData.is[7] = self.vData.want[7]
end
-- snap track z
if self.vData.is[8] ~= self.vData.want[8] then
if FS22_EnhancedVehicle.functionSnapIsEnabled then
if debug > 0 then print("--> ("..self.rootNode..") changed track pz: "..self.vData.want[8]) end
end
self.vData.is[8] = self.vData.want[8]
end
-- snap track dX
if self.vData.is[9] ~= self.vData.want[9] then
if FS22_EnhancedVehicle.functionSnapIsEnabled then
if debug > 0 then print("--> ("..self.rootNode..") changed track dX: "..self.vData.want[9]) end
end
self.vData.is[9] = self.vData.want[9]
end
-- snap track dZ
if self.vData.is[10] ~= self.vData.want[10] then
if FS22_EnhancedVehicle.functionSnapIsEnabled then
if debug > 0 then print("--> ("..self.rootNode..") changed track dZ: "..self.vData.want[10]) end
end
self.vData.is[10] = self.vData.want[10]
end
-- snap track mpx
if self.vData.is[11] ~= self.vData.want[11] then
if FS22_EnhancedVehicle.functionSnapIsEnabled then
if debug > 0 then print("--> ("..self.rootNode..") changed track snap x: "..self.vData.want[11]) end
end
self.vData.is[11] = self.vData.want[11]
end
-- snap track mpz
if self.vData.is[12] ~= self.vData.want[12] then
if FS22_EnhancedVehicle.functionSnapIsEnabled then
if debug > 0 then print("--> ("..self.rootNode..") changed track snap z: "..self.vData.want[12]) end
end
self.vData.is[12] = self.vData.want[12]
end
-- front diff
if self.vData.is[1] ~= self.vData.want[1] then
if FS22_EnhancedVehicle.functionDiffIsEnabled then
if self.vData.want[1] then
updateDifferential(self.rootNode, 0, self.vData.torqueRatio[1], 1)
if debug > 0 then print("--> ("..self.rootNode..") changed front diff to: ON") end
else
updateDifferential(self.rootNode, 0, self.vData.torqueRatio[1], self.vData.maxSpeedRatio[1] * 1000)
if debug > 0 then print("--> ("..self.rootNode..") changed front diff to: OFF") end
end
end
self.vData.is[1] = self.vData.want[1]
end
-- back diff
if self.vData.is[2] ~= self.vData.want[2] then
if FS22_EnhancedVehicle.functionDiffIsEnabled then
if self.vData.want[2] then
updateDifferential(self.rootNode, 1, self.vData.torqueRatio[2], 1)
if debug > 0 then print("--> ("..self.rootNode..") changed back diff to: ON") end
else
updateDifferential(self.rootNode, 1, self.vData.torqueRatio[2], self.vData.maxSpeedRatio[2] * 1000)
if debug > 0 then print("--> ("..self.rootNode..") changed back diff to: OFF") end
end
end
self.vData.is[2] = self.vData.want[2]
end
-- wheel drive mode
if self.vData.is[3] ~= self.vData.want[3] then
if FS22_EnhancedVehicle.functionDiffIsEnabled then
if self.vData.want[3] == 0 then
updateDifferential(self.rootNode, 2, -0.00001, 1)
if debug > 0 then print("--> ("..self.rootNode..") changed wheel drive mode to: 2WD") end
elseif self.vData.want[3] == 1 then
updateDifferential(self.rootNode, 2, self.vData.torqueRatio[3], 1)
if debug > 0 then print("--> ("..self.rootNode..") changed wheel drive mode to: 4WD") end
elseif self.vData.want[3] == 2 then
updateDifferential(self.rootNode, 2, 1, 0)
if debug > 0 then print("--> ("..self.rootNode..") changed wheel drive mode to: FWD") end
end
end
self.vData.is[3] = self.vData.want[3]
end
-- park brake on
if self.vData.is[13] ~= self.vData.want[13] then
if FS22_EnhancedVehicle.functionParkingBrakeIsEnabled then
if self.vData.want[13] then
if debug > 0 then print("--> ("..self.rootNode..") changed park on to: ON") end
else