-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFS25_EnhancedVehicle.lua
2646 lines (2285 loc) · 117 KB
/
FS25_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: FS25_EnhancedVehicle
--
-- Author: Majo76
-- email: ls (at) majo76 (dot) de
-- @Date: 07.12.2024
-- @Version: 1.1.3.1
--[[
CHANGELOG
2024-12-07 - V1.1.3.1
* forgot to update the modDesc version *doh*
2024-12-07 - V1.1.3.0
* HUD elements dmg and fuel can now be moved correctly by changing offsetX/Y in XML config
+ added translation: da, cz, es, hu
2024-12-02 - V1.1.2.2
+ several bugfixes, code optimizations and translations additions/updates
- revert NormalizeAngle code change
2024-11-30 - V1.1.1.0
+ added new feature: front/rear hydraulic unfold/fold on keypress
+ added translations: ru, cs, pl
2024-11-26 - V1.1.0.0
+ the configuration menu is back. yay!
* (finally) fixed too many EV key bindings are shown in help menu
2024-11-24 - V1.0.1.0
+ added odometer / tripmeter (driven kilometer display) based on Giants modding tutorial
- disabled configuration menu (for now)
2024-11-12 - V1.0.0.0
+ initial release for FS25
- removed support for different fuel/dmg positions
license: https://creativecommons.org/licenses/by-nc-sa/4.0/
]]--
local myName = "FS25_EnhancedVehicle"
FS25_EnhancedVehicle = {}
local FS25_EnhancedVehicle_mt = Class(FS25_EnhancedVehicle)
-- #############################################################################
function FS25_EnhancedVehicle:new(mission, modDirectory, modName, i18n, gui, inputManager, messageCenter)
if debug > 1 then print("-> " .. myName .. ": new ") end
local self = {}
setmetatable(self, FS25_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
FS25_EnhancedVehicle.hud = {}
FS25_EnhancedVehicle.fS = g_currentMission.hud.speedMeter:scalePixelToScreenHeight(12)
FS25_EnhancedVehicle.sections = { 'fuel', 'dmg', 'misc', 'rpm', 'temp', 'diff', 'track', 'park', 'odo' }
FS25_EnhancedVehicle.actions = {}
FS25_EnhancedVehicle.actions.global = { 'FS25_EnhancedVehicle_MENU' }
FS25_EnhancedVehicle.actions.park = { 'FS25_EnhancedVehicle_PARK' }
FS25_EnhancedVehicle.actions.odo = { 'FS25_EnhancedVehicle_ODO_MODE' }
FS25_EnhancedVehicle.actions.snap = { 'FS25_EnhancedVehicle_SNAP_ONOFF',
'FS25_EnhancedVehicle_SNAP_REVERSE',
'FS25_EnhancedVehicle_SNAP_OPMODE',
'FS25_EnhancedVehicle_SNAP_CALC_WW',
'FS25_EnhancedVehicle_SNAP_GRID_RESET',
'FS25_EnhancedVehicle_SNAP_LINES_MODE',
'FS25_EnhancedVehicle_SNAP_TRACK',
'FS25_EnhancedVehicle_SNAP_TRACKP',
'FS25_EnhancedVehicle_SNAP_TRACKW',
'FS25_EnhancedVehicle_SNAP_TRACKO',
'FS25_EnhancedVehicle_SNAP_TRACKJ',
'FS25_EnhancedVehicle_SNAP_HL_MODE',
'FS25_EnhancedVehicle_SNAP_HL_DIST',
'FS25_EnhancedVehicle_SNAP_ANGLE1',
'FS25_EnhancedVehicle_SNAP_ANGLE2',
'FS25_EnhancedVehicle_SNAP_ANGLE3',
'AXIS_MOVE_SIDE_VEHICLE',
'AXIS_ACCELERATE_VEHICLE',
'AXIS_BRAKE_VEHICLE' }
FS25_EnhancedVehicle.actions.diff = { 'FS25_EnhancedVehicle_FD',
'FS25_EnhancedVehicle_RD',
'FS25_EnhancedVehicle_BD',
'FS25_EnhancedVehicle_DM' }
FS25_EnhancedVehicle.actions.hydraulic = { 'FS25_EnhancedVehicle_AJ_REAR_UPDOWN',
'FS25_EnhancedVehicle_AJ_REAR_ONOFF',
'FS25_EnhancedVehicle_AJ_REAR_FOLD',
'FS25_EnhancedVehicle_AJ_FRONT_UPDOWN',
'FS25_EnhancedVehicle_AJ_FRONT_ONOFF',
'FS25_EnhancedVehicle_AJ_FRONT_FOLD' }
-- for key press delay
FS25_EnhancedVehicle.nextActionTime = 0
FS25_EnhancedVehicle.deltaActionTime = 500
FS25_EnhancedVehicle.minActionTime = 31.25
-- some colors
FS25_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 },
fs25green = { 60/255, 118/255, 0/255, 1 },
}
FS25_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
FS25_EnhancedVehicle.sounds = {}
for _, id in ipairs({"diff_lock", "brakeOn", "brakeOff", "snap_on", "snap_off", "hl_approach"}) do
FS25_EnhancedVehicle.sounds[id] = createSample(id)
file = self.modDirectory.."resources/"..id..".ogg"
loadSample(FS25_EnhancedVehicle.sounds[id], file, false)
end
end
return self
end
-- #############################################################################
function FS25_EnhancedVehicle:delete()
if debug > 1 then print("-> " .. myName .. ": delete ") end
-- delete our UI
FS25_EnhancedVehicle.ui_menu:delete()
-- delete our HUD
FS25_EnhancedVehicle.ui_hud:delete()
end
-- #############################################################################
function FS25_EnhancedVehicle:onMissionLoaded(mission)
if debug > 1 then print("-> " .. myName .. ": onMissionLoaded ") end
-- create configuration dialog
FS25_EnhancedVehicle.ui_menu = FS25_EnhancedVehicle_UI.new()
g_gui:loadGui(self.modDirectory.."ui/FS25_EnhancedVehicle_UI.xml", "FS25_EnhancedVehicle_UI", FS25_EnhancedVehicle.ui_menu)
-- create HUD
FS25_EnhancedVehicle.ui_hud = FS25_EnhancedVehicle_HUD:new(mission.hud.speedMeter, mission.hud.gameInfoDisplay, self.modDirectory)
FS25_EnhancedVehicle.ui_hud:load()
-- hook into function, which is called only if the HUD is really visible for a vehicle
mission.hud.drawControlledEntityHUD = Utils.appendedFunction(mission.hud.drawControlledEntityHUD,
function(self)
if self.isVisible then
FS25_EnhancedVehicle.ui_hud:drawHUD()
end
end)
-- hook into function, which sets the vehicle for HUD display
mission.hud.setControlledVehicle = Utils.appendedFunction(mission.hud.setControlledVehicle,
function(self, vehicle)
FS25_EnhancedVehicle.ui_hud:setVehicle(vehicle)
end)
end
-- #############################################################################
function FS25_EnhancedVehicle:loadMap()
print("--> loaded FS25_EnhancedVehicle version " .. self.version .. " (by Majo76) <--");
-- first set our current and default config to default values
FS25_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
FS25_EnhancedVehicle:activateConfig()
end
-- #############################################################################
function FS25_EnhancedVehicle:unloadMap()
print("--> unloaded FS25_EnhancedVehicle version " .. self.version .. " (by Majo76) <--");
end
-- #############################################################################
function FS25_EnhancedVehicle.installSpecializations(vehicleTypeManager, specializationManager, modDirectory, modName)
if debug > 1 then print("-> " .. myName .. ": installSpecializations ") end
specializationManager:addSpecialization("EnhancedVehicle", "FS25_EnhancedVehicle", Utils.getFilename("FS25_EnhancedVehicle.lua", modDirectory), nil)
if specializationManager:getSpecializationByName("EnhancedVehicle") == nil then
print("ERROR: unable to add specialization 'FS25_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 FS25_EnhancedVehicle.prerequisitesPresent(specializations)
if debug > 1 then print("-> " .. myName .. ": prerequisites ") end
return true
end
-- #############################################################################
function FS25_EnhancedVehicle.registerEventListeners(vehicleType)
if debug > 1 then print("-> " .. myName .. ": registerEventListeners ") end
for _,n in pairs( { "onLoad", "onPostLoad", "saveToXMLFile", "onUpdate", "onDraw", "onReadStream", "onWriteStream", "onReadUpdateStream", "onWriteUpdateStream", "onRegisterActionEvents", "onEnterVehicle", "onLeaveVehicle", "onPostAttachImplement", "onPostDetachImplement" } ) do
SpecializationUtil.registerEventListener(vehicleType, n, FS25_EnhancedVehicle)
end
end
-- #############################################################################
-- ### function for others mods to enable/disable EnhancedVehicle functions
-- ### name: differential, hydraulic, snap, park, odometer
-- ### state: true or false
function FS25_EnhancedVehicle:functionEnable(name, state)
if name == "differential" then
lC:setConfigValue("global.functions", "diffIsEnabled", state)
FS25_EnhancedVehicle.functionDiffIsEnabled = state
end
if name == "hydraulic" then
lC:setConfigValue("global.functions", "hydraulicIsEnabled", state)
FS25_EnhancedVehicle.functionHydraulicIsEnabled = state
end
if name == "snap" then
lC:setConfigValue("global.functions", "snapIsEnabled", state)
FS25_EnhancedVehicle.functionSnapIsEnabled = state
end
if name == "park" then
lC:setConfigValue("global.functions", "parkingBrakeIsEnabled", state)
FS25_EnhancedVehicle.functionParkingBrakeIsEnabled = state
end
if name == "odometer" then
lC:setConfigValue("global.functions", "odoMeterIsEnabled", state)
FS25_EnhancedVehicle.functionOdoMeterIsEnabled = state
end
end
-- #############################################################################
-- ### function for others mods to get EnhancedVehicle functions status
-- ### name: differential, hydraulic, snap, park, odometer
-- ### returns true or false
function FS25_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
if name == "odometer" then
return(lC:getConfigValue("global.functions", "odoMeterIsEnabled"))
end
return(nil)
end
-- #############################################################################
function FS25_EnhancedVehicle:activateConfig()
-- here we will "move" our config from the libConfig internal storage to the variables we actually use
-- functions
FS25_EnhancedVehicle.functionDiffIsEnabled = lC:getConfigValue("global.functions", "diffIsEnabled")
FS25_EnhancedVehicle.functionHydraulicIsEnabled = lC:getConfigValue("global.functions", "hydraulicIsEnabled")
FS25_EnhancedVehicle.functionSnapIsEnabled = lC:getConfigValue("global.functions", "snapIsEnabled")
FS25_EnhancedVehicle.functionParkingBrakeIsEnabled = lC:getConfigValue("global.functions", "parkingBrakeIsEnabled")
FS25_EnhancedVehicle.functionOdoMeterIsEnabled = lC:getConfigValue("global.functions", "odoMeterIsEnabled")
-- globals
FS25_EnhancedVehicle.showKeysInHelpMenu = lC:getConfigValue("global.misc", "showKeysInHelpMenu")
FS25_EnhancedVehicle.soundIsOn = lC:getConfigValue("global.misc", "soundIsOn")
-- snap
FS25_EnhancedVehicle.snap = {}
FS25_EnhancedVehicle.snap.snapToAngle = lC:getConfigValue("snap", "snapToAngle")
FS25_EnhancedVehicle.snap.attachmentSpikeHeight = lC:getConfigValue("snap", "attachmentSpikeHeight")
FS25_EnhancedVehicle.snap.trackSpikeHeight = lC:getConfigValue("snap", "trackSpikeHeight")
FS25_EnhancedVehicle.snap.distanceAboveGroundVehicleMiddleLine = lC:getConfigValue("snap", "distanceAboveGroundVehicleMiddleLine")
FS25_EnhancedVehicle.snap.distanceAboveGroundVehicleSideLine = lC:getConfigValue("snap", "distanceAboveGroundVehicleSideLine")
FS25_EnhancedVehicle.snap.distanceAboveGroundAttachmentSideLine = lC:getConfigValue("snap", "distanceAboveGroundAttachmentSideLine")
FS25_EnhancedVehicle.snap.colorVehicleMiddleLine = { lC:getConfigValue("snap.colorVehicleMiddleLine", "red"), lC:getConfigValue("snap.colorVehicleMiddleLine", "green"), lC:getConfigValue("snap.colorVehicleMiddleLine", "blue") }
FS25_EnhancedVehicle.snap.colorVehicleSideLine = { lC:getConfigValue("snap.colorVehicleSideLine", "red"), lC:getConfigValue("snap.colorVehicleSideLine", "green"), lC:getConfigValue("snap.colorVehicleSideLine", "blue") }
FS25_EnhancedVehicle.snap.colorAttachmentSideLine = { lC:getConfigValue("snap.colorAttachmentSideLine", "red"), lC:getConfigValue("snap.colorAttachmentSideLine", "green"), lC:getConfigValue("snap.colorAttachmentSideLine", "blue") }
-- track
FS25_EnhancedVehicle.track = {}
FS25_EnhancedVehicle.track.distanceAboveGround = lC:getConfigValue("track", "distanceAboveGround")
FS25_EnhancedVehicle.track.numberOfTracks = lC:getConfigValue("track", "numberOfTracks")
FS25_EnhancedVehicle.track.showLines = lC:getConfigValue("track", "showLines")
FS25_EnhancedVehicle.track.hideLines = lC:getConfigValue("track", "hideLines")
FS25_EnhancedVehicle.track.hideLinesAfter = lC:getConfigValue("track", "hideLinesAfter")
FS25_EnhancedVehicle.track.hideLinesAfterValue = 0
FS25_EnhancedVehicle.track.color = { lC:getConfigValue("track.color", "red"), lC:getConfigValue("track.color", "green"), lC:getConfigValue("track.color", "blue") }
FS25_EnhancedVehicle.track.headlandSoundTriggerDistance = lC:getConfigValue("track", "headlandSoundTriggerDistance")
-- HUD stuff
for _, section in pairs(FS25_EnhancedVehicle.sections) do
FS25_EnhancedVehicle.hud[section] = {}
FS25_EnhancedVehicle.hud[section].enabled = lC:getConfigValue("hud."..section, "enabled")
FS25_EnhancedVehicle.hud[section].fontSize = lC:getConfigValue("hud."..section, "fontSize")
FS25_EnhancedVehicle.hud[section].offsetX = lC:getConfigValue("hud."..section, "offsetX")
FS25_EnhancedVehicle.hud[section].offsetY = lC:getConfigValue("hud."..section, "offsetY")
end
FS25_EnhancedVehicle.hud.dmg.showAmountLeft = lC:getConfigValue("hud.dmg", "showAmountLeft")
FS25_EnhancedVehicle.hud.colorActive = { lC:getConfigValue("hud.colorActive", "red"), lC:getConfigValue("hud.colorActive", "green"), lC:getConfigValue("hud.colorActive", "blue"), 1 }
FS25_EnhancedVehicle.hud.colorInactive = { lC:getConfigValue("hud.colorInactive", "red"), lC:getConfigValue("hud.colorInactive", "green"), lC:getConfigValue("hud.colorInactive", "blue"), 1 }
FS25_EnhancedVehicle.hud.colorStandby = { lC:getConfigValue("hud.colorStandby", "red"), lC:getConfigValue("hud.colorStandby", "green"), lC:getConfigValue("hud.colorStandby", "blue"), 1 }
FS25_EnhancedVehicle.sfx_volume = {}
FS25_EnhancedVehicle.sfx_volume.track = lC:getConfigValue("sfx.track", "volume")
FS25_EnhancedVehicle.sfx_volume.brake = lC:getConfigValue("sfx.brake", "volume")
FS25_EnhancedVehicle.sfx_volume.diff = lC:getConfigValue("sfx.diff", "volume")
FS25_EnhancedVehicle.sfx_volume.hl_approach = lC:getConfigValue("sfx.hl_approach", "volume")
end
-- #############################################################################
function FS25_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)
lC:addConfigValue("global.functions", "odoMeterIsEnabled", "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)
-- odoMeter
lC:addConfigValue("hud.odo", "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 more colors
lC:addConfigValue("hud.colorActive", "red", "float", 60/255)
lC:addConfigValue("hud.colorActive", "green", "float", 118/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 FS25_EnhancedVehicle:onLoad(savegame)
if debug > 1 then print("-> " .. myName .. ": onLoad" .. mySelf(self)) end
-- export functions for other mods
self.functionEnable = FS25_EnhancedVehicle.functionEnable
self.functionStatus = FS25_EnhancedVehicle.functionStatus
end
-- #############################################################################
function FS25_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
-- 14 - odo meter
-- 15 - trip meter
-- 16 - odo mode
-- initialize vehicle data with defaults
self.vData = {}
self.vData.is = { nil, nil, nil, 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, 0.0, 0.0, 0 }
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 }
self.vData.dirtyFlag = self:getNextDirtyFlag()
self.vData.networkThreshold = 10 -- send odo/tripMeter updates every 10 meters
self.vData.odoDistanceSent = 0 -- last odo value sent
self.vData.tripDistanceSent = 0 -- last trip value sent
-- (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 ..".FS25_EnhancedVehicle.EnhancedVehicle"
local _data
for _, _data in pairs( { {1, 'frontDiffIsOn'}, {2, 'backDiffIsOn'}, {3, 'driveMode'}, {13, 'parkingBrakeIsOn'}, {14, 'odoMeter'}, {15, 'tripMeter'}, {16, 'odoMode'} }) do
local idx = _data[1]
local _v
if idx == 3 or idx == 16 then
_v = getXMLInt(xmlFile.handle, key.."#".. _data[2])
elseif (idx == 14 or idx == 15) then
_v = getXMLFloat(xmlFile.handle, key.."#".. _data[2])
else
_v = getXMLBool(xmlFile.handle, key.."#".. _data[2])
end
if _v ~= nil then
if (idx == 3 or idx == 14 or idx == 15 or idx == 16) 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
FS25_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 FS25_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
if self.vData.is[14] ~= nil then setXMLFloat(xmlFile.handle, key.."#odoMeter", self.vData.is[14]) else print("-> EV: saveToXMLFile warning [14]") end
if self.vData.is[15] ~= nil then setXMLFloat(xmlFile.handle, key.."#tripMeter", self.vData.is[15]) else print("-> EV: saveToXMLFile warning [15]") end
if self.vData.is[16] ~= nil then setXMLInt(xmlFile.handle, key.."#odoMode", self.vData.is[16]) else print("-> EV: saveToXMLFile warning [16]") end
end
-- #############################################################################
function FS25_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
self.vData.is[14] = streamReadFloat32(streamId) -- odoMeter
self.vData.is[15] = streamReadFloat32(streamId) -- tripMeter
self.vData.is[16] = streamReadInt8(streamId) -- odo mode
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 FS25_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])
streamWriteFloat32(streamId, self.vData.is[14])
streamWriteFloat32(streamId, self.vData.is[15])
streamWriteInt8(streamId, self.vData.is[16])
end
-- #############################################################################
function FS25_EnhancedVehicle:onReadUpdateStream(streamId, timestamp, connection)
if debug > 2 then print("-> " .. myName .. ": onReadUpdateStream - " .. streamId .. mySelf(self)) end
-- only receive our odo/tripMeter updates
if connection:getIsServer() then
if streamReadBool(streamId) then
self.vData.want[14] = streamReadFloat32(streamId)
self.vData.want[15] = streamReadFloat32(streamId)
end
end
if self.isClient then
self.vData.is[14] = self.vData.want[14]
self.vData.is[15] = self.vData.want[15]
end
end
-- #############################################################################
function FS25_EnhancedVehicle:onWriteUpdateStream(streamId, connection, dirtyMask)
if debug > 2 then print("-> " .. myName .. ": onWriteUpdateStream - " .. streamId .. " / " .. dirtyMask .. mySelf(self)) end
if not connection:getIsServer() then
-- only sent our odo/tripMeter values
if streamWriteBool(streamId, bitAND(dirtyMask, self.vData.dirtyFlag) ~= 0) then
streamWriteFloat32(streamId, self.vData.want[14])
streamWriteFloat32(streamId, self.vData.want[15])
end
end
end
-- #############################################################################
function FS25_EnhancedVehicle:onUpdate(dt)
if debug > 2 then print("-> " .. myName .. ": onUpdate " .. dt .. ", S: " .. tostring(self.isServer) .. ", C: " .. tostring(self.isClient) .. mySelf(self)) end
-- (client)
if FS25_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
FS25_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
FS25_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
FS25_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 < FS25_EnhancedVehicle.track.headlandSoundTriggerDistance then
if self.vData.track.hl_samplePlayed == nil then
playSample(FS25_EnhancedVehicle.sounds["hl_approach"], 1, Between(FS25_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 = FS25_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
FS25_EnhancedVehicle.onActionCall(self, "FS25_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 only ->
if self.isServer and self.vData ~= nil then
-- process odo/tripMeter
if FS25_EnhancedVehicle.functionOdoMeterIsEnabled and self:getIsMotorStarted() then
if self.lastMovedDistance > 0.001 then
self.vData.want[14] = self.vData.want[14] + self.lastMovedDistance
self.vData.want[15] = self.vData.want[15] + self.lastMovedDistance
-- do we want to send an update of values?
if math.abs(self.vData.want[14] - self.vData.odoDistanceSent) > self.vData.networkThreshold then
self:raiseDirtyFlags(self.vData.dirtyFlag)
self.vData.odoDistanceSent = self.vData.want[14]
end
if math.abs(self.vData.want[15] - self.vData.tripDistanceSent) > self.vData.networkThreshold then
self:raiseDirtyFlags(self.vData.dirtyFlag)
self.vData.tripDistanceSent = self.vData.want[15]
end
end
end
-- (server) process changes between "is" and "want"
FS25_EnhancedVehicle:updatevData(self)
end
end
-- #############################################################################
function FS25_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 FS25_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 FS25_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 FS25_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 FS25_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 FS25_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 FS25_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 FS25_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 FS25_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 FS25_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 FS25_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 FS25_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 FS25_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 FS25_EnhancedVehicle.functionParkingBrakeIsEnabled then
if self.vData.want[13] then
if debug > 0 then print("--> ("..self.rootNode..") changed park on to: ON") end
else
if debug > 0 then print("--> ("..self.rootNode..") changed park on to: OFF") end
end
end
self.vData.is[13] = self.vData.want[13]
end
-- odoMeter
if self.vData.is[14] ~= self.vData.want[14] then
if FS25_EnhancedVehicle.functionOdoMeterIsEnabled then
if debug > 2 then print("--> ("..self.rootNode..") changed odoMeter: "..self.vData.want[14]) end
end
self.vData.is[14] = self.vData.want[14]
end
-- tripMeter
if self.vData.is[15] ~= self.vData.want[15] then
if FS25_EnhancedVehicle.functionOdoMeterIsEnabled then
if debug > 2 then print("--> ("..self.rootNode..") changed tripMeter: "..self.vData.want[15]) end
end
self.vData.is[15] = self.vData.want[15]
end
-- odoMode
if self.vData.is[16] ~= self.vData.want[16] then
if FS25_EnhancedVehicle.functionOdoMeterIsEnabled then
if debug > 0 then print("--> ("..self.rootNode..") changed odo mode: "..self.vData.want[16]) end
end
self.vData.is[16] = self.vData.want[16]
end
end
-- #############################################################################
function FS25_EnhancedVehicle:drawVisualizationLines(_step, _segments, _x, _y, _z, _dX, _dZ, _length, _colorR, _colorG, _colorB, _addY, _spikes, _spikeHeight)
_spikes = _spikes or false
-- our draw one line (recursive) function
if _step >= _segments then return end
p1 = { x = _x, y = _y, z = _z }
p2 = { x = p1.x + _dX * _length, y = p1.y, z = p1.z + _dZ * _length }
p2.y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, p2.x, 0, p2.z) + _addY
drawDebugLine(p1.x, p1.y, p1.z, _colorR, _colorG, _colorB, p2.x, p2.y, p2.z, _colorR, _colorG, _colorB)
if _spikes then
drawDebugLine(p2.x, p2.y, p2.z, _colorR, _colorG, _colorB, p2.x, p2.y + _spikeHeight, p2.z, _colorR, _colorG, _colorB)
end
FS25_EnhancedVehicle:drawVisualizationLines(_step + 1, _segments, p2.x, p2.y, p2.z, _dX, _dZ, _length, _colorR, _colorG, _colorB, _addY, _spikes, _spikeHeight)