This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
TSX_EnhancedVehicle.lua
1548 lines (1348 loc) · 66.5 KB
/
TSX_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: TSX_EnhancedVehicle
--
-- Author: ZhooL
-- email: ls19@dark-world.de
-- @Date: 19.10.2020
-- @Version: 1.6.4.1
--[[
CHANGELOG
2020-10-19 - V1.6.4.1
+ added spanish translation (thanks to eltrueno) #51
2019-04-17 - V1.6.4.0
+ added italian translation (thanks to zed636) #42
* update of polish translation (thanks to KITT3000) #43
2019-04-14 - V1.6.3.1
* fix log warning #34
* rework of modDesc files (thanks to KITT3000)
2019-01-20 - V1.6.3.0
* updated to support the migration of KeyboardSteer to VehicleControlAddon (vca)
2019-01-15 - V1.6.2.0
* talked to Mogli12 about compatibility between EV and KS and instead of disabling other mods functions the player (thats you) should decide which mods Shuttle Control/Shift should be used
to comply to that EV will no longer disable stuff, but display an annoying warning text on screen to instruct you how to proceed choosing a shuttle control/shift
+ added global options to enable/disable shuttle shift, differentials and hydraulics
+ added functions for other mods to enable/disable EnhancedVehicle functions
+ the "beep beep" is back
2019-01-14 - V1.6.1.0
+ added functionality to turn on/off both differentials the same time (no default keybinding)
2019-01-14 - V1.6.0.2
* adapt keyboardSteer integration to new version
2019-01-13 - V1.6.0.1
+ added french translation (thanks boloss)
* changed the way the hydraulic stuff works. should now work on most machinery
* changed how we setup actionEvents and InputBindungs
* another change in integration of keyboardSteer camera stuff
2019-01-12 - V1.6.0.0
+ implemented four new keybindings for hydraulic front+rear up/down and on/off (default: lAlt+1 to 4)
2019-01-11 - V1.5.1.2
* (shuttle shift) better integration with keyboardSteer. backward looking camera should work again
* (shuttle shift) changed behavior: when vehicle moves (without throttle) and opposite direction is selected it will brake
* (shuttle shift) bugfix for those damn vehicles with build-in reverse driving mechanism
2019-01-10 - V1.5.1.1
* (shuttle shift) bugfix for shuttle not working when a device with own motor is attached (like the big woodcutter)
* (shuttle shift) reverse lights are now working again when driving backwards. But reverse driving warning sound (beep beep) is still broken.
+ (shuttle shift) added some sounds
2019-01-09 - V1.5.1.0
+ (shuttle shift) added two keybindings (default: insert and delete) for direct selection of forward/reverse driving direction
+ (shuttle shift) implemented a parking break (default key: end). when active, you can't move the vehicle... obviously
+ status of diff locks and drive mode per vehicle are now stored in savegame as well
+ try to disable conflicting keyboardSteer Mod functions (I'm sorry, Mogli12)
2019-01-09 - V1.5.0.2
* bugfix for XML config is being resettet on every game start
2019-01-09 - V1.5.0.1
* fix for log warning about performance of audio sample (wav -> ogg)
* moved all media files to subfolder
2019-01-08 - V1.5.0.0
+ implemented shuttle shift functionality (per vehicle). press assigned key (default: Space) to change driving direction and (default: LCTRL+Space) to turn shuttle shift on/off
+ shuttle shift status per vehicle is stored in savegame
+ added shuttle shift status display left of speedMeter. The green arrow shows the selected driving direction. If shuttle shift is disabled the display turns gray-transparent.
+ added global option "shuttleDefaultIsOn" to choose whether shuttle shift is ON per default when entering "new" vehicles (default: OFF)
* moved differential status display to right-bottom corner of speedMeter
2019-01-06 - V1.4.4.0
* completely rewrote the XML config handling. it's much more flexible now for future usage
2019-01-05 - V1.4.3.0
* replaced ugly text display of diff status by a neat graphic
+ added "clonk" sound when switching diff or drive mode (and global option to turn it off)
+ added global option to choose whether keybindings are displayed in the help menu or not
+ added keybinding (default: KEYPAD *) to reload XML config on the fly
2019-01-04 - V1.4.2.0
+ added "Make Feinstaub great again" feature. vehicles without AdBlue (DEF) will produce more black'n'blue exhaust smoke
* gave keyboard binding display in help menu a very low priority to not disturb the display of more important bindings
* changed the 2WD behavior again. should not be so wobbly any longer.
+ moved global variables like fontSize to XML config
2019-01-03 - V1.4.1.0
* reworked HUD elements positioning. should fix positions once and for all regardless of screen resolutions and GUI scaling (press "KeyPad /" to adept)
* workaround (it displays "0") for attachments without a damage model (no spec_wearable)
* changed the differential behavior for 2WD. this may cause some wobbly side effects on most vehicles but it's more correct now
2019-01-02 - V1.4.0.0
* fixed warning about the background overlay image (png -> dds)
+ config is now stored in XML file
+ position of HUD elements can be moved or enabled/disabled in XML file
* rewrote the key binding/key press stuff
+ key bindings can now be changed in the options menu
+ added config reset functionality and keybinding. use this if you messed up the XML or changed the GUI scale
+ if mod 'keyboardSteerMogli' is detected we move some HUD elements to let them not overlap
* moved the rpm and temperature HUD elements inside the speedmeter
* don't display not working HUD elements as a multiplayer (and not being host) client
2019-01-01 - V1.3.1.1
* bugfix for dedicated servers
* bugfix for clients not reacting on key press (stupid GIANTS engine again)
2019-01-01 - V1.3.1.0
+ added background overlay to make colored text better readable
2018-12-31 - V1.3.0.0
* first release
license: https://creativecommons.org/licenses/by-nc-sa/4.0/
]]--
debug = 0 -- 0=0ff, 1=some, 2=everything, 3=madness
local myName = "TSX_EnhancedVehicle"
-- #############################################################################
TSX_EnhancedVehicle = {}
TSX_EnhancedVehicle.modDirectory = g_currentModDirectory
TSX_EnhancedVehicle.confDirectory = getUserProfileAppPath().. "modsSettings/TSX_EnhancedVehicle/"
-- for debugging purpose
TSX_dbg = false
TSX_dbg1 = 0
TSX_dbg2 = 0
TSX_dbg3 = 0
-- some global stuff - DONT touch
TSX_EnhancedVehicle.diff_overlayWidth = 512
TSX_EnhancedVehicle.diff_overlayHeight = 1024
TSX_EnhancedVehicle.dir_overlayWidth = 64
TSX_EnhancedVehicle.dir_overlayHeight = 256
TSX_EnhancedVehicle.uiScale = 1
if g_gameSettings.uiScale ~= nil then
if debug > 1 then print("-> uiScale: "..TSX_EnhancedVehicle.uiScale) end
TSX_EnhancedVehicle.uiScale = g_gameSettings.uiScale
end
TSX_EnhancedVehicle.sections = { 'fuel', 'dmg', 'misc', 'rpm', 'temp', 'diff', 'shuttle' }
TSX_EnhancedVehicle.actions = {}
TSX_EnhancedVehicle.actions.global = { 'TSX_EnhancedVehicle_RESET',
'TSX_EnhancedVehicle_RELOAD' }
TSX_EnhancedVehicle.actions.diff = { 'TSX_EnhancedVehicle_FD',
'TSX_EnhancedVehicle_RD',
'TSX_EnhancedVehicle_BD',
'TSX_EnhancedVehicle_DM' }
TSX_EnhancedVehicle.actions.shuttle = { 'TSX_EnhancedVehicle_SHUTTLE_ONOFF',
'TSX_EnhancedVehicle_SHUTTLE_SWITCH',
'TSX_EnhancedVehicle_SHUTTLE_FWD',
'TSX_EnhancedVehicle_SHUTTLE_REV',
'TSX_EnhancedVehicle_SHUTTLE_PARK' }
TSX_EnhancedVehicle.actions.hydraulic = { 'TSX_EnhancedVehicle_AJ_REAR_UPDOWN',
'TSX_EnhancedVehicle_AJ_REAR_ONOFF',
'TSX_EnhancedVehicle_AJ_FRONT_UPDOWN',
'TSX_EnhancedVehicle_AJ_FRONT_ONOFF' }
if TSX_dbg then
for _, v in pairs({ 'TSX_DBG1_UP', 'TSX_DBG1_DOWN', 'TSX_DBG2_UP', 'TSX_DBG2_DOWN', 'TSX_DBG3_UP', 'TSX_DBG3_DOWN' }) do
table.insert(TSX_EnhancedVehicle.actions, v)
end
end
-- some colors
TSX_EnhancedVehicle.color = {
black = { 0, 0, 0, 1 },
white = { 1, 1, 1, 1 },
red = { 255/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 },
dmg = { 86/255, 142/255, 42/255, 1 },
fuel = { 124/255, 90/255, 8/255, 1 },
adblue = { 48/255, 78/255, 249/255, 1 },
}
-- for overlays
TSX_EnhancedVehicle.overlay = {}
-- load sound effects
if g_dedicatedServerInfo == nil then
local file, id
TSX_EnhancedVehicle.sounds = {}
for _, id in ipairs({"diff_lock", "brakeOn", "brakeOff", "shifter"}) do
TSX_EnhancedVehicle.sounds[id] = createSample(id)
file = TSX_EnhancedVehicle.modDirectory.."media/"..id..".ogg"
loadSample(TSX_EnhancedVehicle.sounds[id], file, false)
end
end
-- check for KeyboardSteer or VehicleControlAddon
mogli_loaded = false
if g_modIsLoaded.FS19_KeyboardSteer ~= nil or g_modIsLoaded.FS19_VehicleControlAddon ~= nil then
mogli_loaded = true
end
-- #############################################################################
function TSX_EnhancedVehicle.prerequisitesPresent(specializations)
if debug > 1 then print("-> " .. myName .. ": prerequisites ") end
return true
end
-- #############################################################################
function TSX_EnhancedVehicle.registerEventListeners(vehicleType)
if debug > 1 then print("-> " .. myName .. ": registerEventListeners ") end
for _,n in pairs( { "onLoad", "onPostLoad", "saveToXMLFile", "onUpdate", "onDraw", "onReadStream", "onWriteStream", "onRegisterActionEvents", "onEnterVehicle", "onReverseDirectionChanged" } ) do
SpecializationUtil.registerEventListener(vehicleType, n, TSX_EnhancedVehicle)
end
end
-- #############################################################################
-- ### function for others mods to enable/disable EnhancedVehicle functions
-- ### name: shuttle, differential, hydraulic
-- ### state: true or false
function TSX_EnhancedVehicle:functionEnable(name, state)
if name == "shuttle" then
lC:setConfigValue("global.functions", "shuttleIsEnabled", state)
TSX_EnhancedVehicle.functionShuttleIsEnabled = state
end
if name == "differential" then
lC:setConfigValue("global.functions", "differentialIsEnabled", state)
TSX_EnhancedVehicle.functionDifferentialIsEnabled = state
end
if name == "hydraulic" then
lC:setConfigValue("global.functions", "hydraulicIsEnabled", state)
TSX_EnhancedVehicle.functionHydraulicIsEnabled = state
end
end
-- #############################################################################
-- ### function for others mods to get EnhancedVehicle functions status
-- ### name: shuttle, differential, hydraulic
-- ### returns true or false
function TSX_EnhancedVehicle:functionStatus(name)
if name == "shuttle" then
return(lC:getConfigValue("global.functions", "shuttleIsEnabled"))
end
if name == "differential" then
return(lC:getConfigValue("global.functions", "differentialIsEnabled"))
end
if name == "hydraulic" then
return(lC:getConfigValue("global.functions", "hydraulicIsEnabled"))
end
return(nil)
end
-- #############################################################################
function TSX_EnhancedVehicle:activateConfig()
-- here we will "move" our config from the libConfig internal storage to the variables we actually use
-- functions
TSX_EnhancedVehicle.functionShuttleIsEnabled = lC:getConfigValue("global.functions", "shuttleIsEnabled")
TSX_EnhancedVehicle.functionDifferentialIsEnabled = lC:getConfigValue("global.functions", "differentialIsEnabled")
TSX_EnhancedVehicle.functionHydraulicIsEnabled = lC:getConfigValue("global.functions", "hydraulicIsEnabled")
-- globals
TSX_EnhancedVehicle.fontSize = lC:getConfigValue("global.text", "fontSize")
TSX_EnhancedVehicle.textPadding = lC:getConfigValue("global.text", "textPadding")
TSX_EnhancedVehicle.overlayBorder = lC:getConfigValue("global.text", "overlayBorder")
TSX_EnhancedVehicle.overlayTransparancy = lC:getConfigValue("global.text", "overlayTransparancy")
TSX_EnhancedVehicle.showKeysInHelpMenu = lC:getConfigValue("global.misc", "showKeysInHelpMenu")
TSX_EnhancedVehicle.soundIsOn = lC:getConfigValue("global.misc", "soundIsOn")
TSX_EnhancedVehicle.shuttleDefaultIsOn = lC:getConfigValue("global.misc", "shuttleDefaultIsOn")
-- HUD stuff
for _, section in pairs(TSX_EnhancedVehicle.sections) do
TSX_EnhancedVehicle[section] = {}
TSX_EnhancedVehicle[section].enabled = lC:getConfigValue("hud."..section, "enabled")
TSX_EnhancedVehicle[section].posX = lC:getConfigValue("hud."..section, "posX")
TSX_EnhancedVehicle[section].posY = lC:getConfigValue("hud."..section, "posY")
end
TSX_EnhancedVehicle.diff.zoomFactor = lC:getConfigValue("hud.diff", "zoomFactor")
TSX_EnhancedVehicle.shuttle.zoomFactor = lC:getConfigValue("hud.shuttle", "zoomFactor")
-- Feinstaub
TSX_EnhancedVehicle.feinstaub = {}
TSX_EnhancedVehicle.feinstaub.enabled = lC:getConfigValue("feinstaub", "enabled")
TSX_EnhancedVehicle.feinstaub.min = lC:getConfigValue("feinstaub", "min")
TSX_EnhancedVehicle.feinstaub.max = lC:getConfigValue("feinstaub", "max")
-- convert string to float to avoid later shader errors
for _i=1,4 do
TSX_EnhancedVehicle.feinstaub.min[_i] = tonumber(TSX_EnhancedVehicle.feinstaub.min[_i])
TSX_EnhancedVehicle.feinstaub.max[_i] = tonumber(TSX_EnhancedVehicle.feinstaub.max[_i])
end
end
-- #############################################################################
function TSX_EnhancedVehicle:resetConfig(disable)
if debug > 0 then print("-> " .. myName .. ": resetConfig ") end
disable = false or disable
local _x, _y
if g_gameSettings.uiScale ~= nil then
TSX_EnhancedVehicle.uiScale = g_gameSettings.uiScale
-- local screenWidth, screenHeight = getScreenModeInfo(getScreenMode())
if debug > 1 then print("-> uiScale: "..TSX_EnhancedVehicle.uiScale) end
end
-- to make life easier
local baseX = g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterX
local baseY = g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterY
-- support for keyboardSteer
ksm = 0
if mogli_loaded then
ksm = 0.07 * TSX_EnhancedVehicle.uiScale
if debug > 1 then print("-> found KeyboardSteer or VehicleControlAddon. Adjusting some HUD elements") end
end
-- start fresh
lC:clearConfig()
-- functions
if disable then
lC:addConfigValue("global.functions", "shuttleIsEnabled", "bool", false)
else
lC:addConfigValue("global.functions", "shuttleIsEnabled", "bool", true)
end
lC:addConfigValue("global.functions", "differentialIsEnabled", "bool", true)
lC:addConfigValue("global.functions", "hydraulicIsEnabled", "bool", true)
-- globals
lC:addConfigValue("global.text", "fontSize", "float", 0.01)
lC:addConfigValue("global.text", "textPadding", "float", 0.001)
lC:addConfigValue("global.text", "overlayBorder", "float", 0.003)
lC:addConfigValue("global.text", "overlayTransparancy", "float", 0.75)
lC:addConfigValue("global.misc", "showKeysInHelpMenu", "bool", true)
lC:addConfigValue("global.misc", "soundIsOn", "bool", true)
lC:addConfigValue("global.misc", "shuttleDefaultIsOn", "bool", false)
-- fuel
if g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeIconElement ~= nil then
_x = baseX + (g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeRadiusX / 2.3)
_y = baseY + (g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeRadiusY * 1.8) + ksm
end
lC:addConfigValue("hud.fuel", "enabled", "bool", true)
lC:addConfigValue("hud.fuel", "posX", "float", _x or 0)
lC:addConfigValue("hud.fuel", "posY", "float", _y or 0)
-- dmg
if g_currentMission.inGameMenu.hud.speedMeter.damageGaugeIconElement ~= nil then
_x = baseX - (g_currentMission.inGameMenu.hud.speedMeter.damageGaugeRadiusX / 2.3)
_y = baseY + (g_currentMission.inGameMenu.hud.speedMeter.damageGaugeRadiusY * 1.8) + ksm
end
lC:addConfigValue("hud.dmg", "enabled", "bool", true)
lC:addConfigValue("hud.dmg", "posX", "float", _x or 0)
lC:addConfigValue("hud.dmg", "posY", "float", _y or 0)
-- misc
if g_currentMission.inGameMenu.hud.speedMeter.operatingTimeElement ~= nil then
_x = baseX
_y = lC:getConfigValue("global.text", "overlayBorder") * 1
end
lC:addConfigValue("hud.misc", "enabled", "bool", true)
lC:addConfigValue("hud.misc", "posX", "float", _x or 0)
lC:addConfigValue("hud.misc", "posY", "float", _y or 0)
-- rpm
if g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterX ~= nil then
_x = baseX - (g_currentMission.inGameMenu.hud.speedMeter.damageGaugeRadiusX / 1.8)
_y = baseY
end
lC:addConfigValue("hud.rpm", "enabled", "bool", true)
lC:addConfigValue("hud.rpm", "posX", "float", _x or 0)
lC:addConfigValue("hud.rpm", "posY", "float", _y or 0)
-- temp
if g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterX ~= nil then
_x = baseX + (g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeRadiusX / 1.8)
_y = baseY
end
lC:addConfigValue("hud.temp", "enabled", "bool", true)
lC:addConfigValue("hud.temp", "posX", "float", _x or 0)
lC:addConfigValue("hud.temp", "posY", "float", _y or 0)
-- diff
lC:addConfigValue("hud.diff", "zoomFactor", "float", 18)
if g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeIconElement ~= nil then
local _w, _h = getNormalizedScreenValues(TSX_EnhancedVehicle.diff_overlayWidth / lC:getConfigValue("hud.diff", "zoomFactor") * TSX_EnhancedVehicle.uiScale, TSX_EnhancedVehicle.diff_overlayHeight / lC:getConfigValue("hud.diff", "zoomFactor") * TSX_EnhancedVehicle.uiScale)
_x = baseX + (g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeRadiusX * 1.18)
_y = baseY - (g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeRadiusY * 1.28)
end
lC:addConfigValue("hud.diff", "enabled", "bool", true)
lC:addConfigValue("hud.diff", "posX", "float", _x or 0)
lC:addConfigValue("hud.diff", "posY", "float", _y or 0)
-- shuttle shift indicator
lC:addConfigValue("hud.shuttle", "zoomFactor", "float", 3.5)
if g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeIconElement ~= nil then
local _w, _h = getNormalizedScreenValues(TSX_EnhancedVehicle.dir_overlayWidth / lC:getConfigValue("hud.shuttle", "zoomFactor") * TSX_EnhancedVehicle.uiScale, TSX_EnhancedVehicle.dir_overlayHeight / lC:getConfigValue("hud.shuttle", "zoomFactor") * TSX_EnhancedVehicle.uiScale)
_x = baseX - (g_currentMission.inGameMenu.hud.speedMeter.damageGaugeRadiusX * 1.575)
_y = baseY - (_h / 2)
end
lC:addConfigValue("hud.shuttle", "enabled", "bool", true)
lC:addConfigValue("hud.shuttle", "posX", "float", _x or 0)
lC:addConfigValue("hud.shuttle", "posY", "float", _y or 0)
-- Feinstaub
lC:addConfigValue("feinstaub", "enabled", "bool", true)
lC:addConfigValue("feinstaub", "min", "table", { 0.5, 0.5, 0.5, 1.5 })
lC:addConfigValue("feinstaub", "max", "table", { 0, 0, 0.04, 5 })
end
-- #############################################################################
function TSX_EnhancedVehicle:onLoad(savegame)
if debug > 1 then print("-> " .. myName .. ": onLoad" .. mySelf(self)) end
-- export functions for other mods
self.functionEnable = TSX_EnhancedVehicle.functionEnable
self.functionStatus = TSX_EnhancedVehicle.functionStatus
end
-- #############################################################################
function TSX_EnhancedVehicle:onPostLoad(savegame)
if debug > 1 then print("-> " .. myName .. ": onPostLoad" .. mySelf(self)) end
self.reverseLights = false
-- (server) set defaults when vehicle is "new"
-- vData
-- 1 - frontDiffIsOn
-- 2 - backDiffIsOn
-- 3 - drive mode
-- 4 - shuttle isForward
-- 5 - shuttle inOn
-- 6 - shuttle parkBreakIsOn
if self.isServer then
if self.vData == nil then
self.vData = {}
self.vData.is = { true, true, -1, false, true, false }
self.vData.want = { false, false, 1, true, false, true }
if TSX_EnhancedVehicle.shuttleDefaultIsOn then
self.vData.is[5] = false
self.vData.want[5] = true
end
self.vData.torqueRatio = { 0.5, 0.5, 0.5 }
self.vData.maxSpeedRatio = { 1.0, 1.0, 1.0 }
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
if debug > 0 then print("--> setup of vData done" .. mySelf(self)) end
end
-- load vehicle shuttle status from savegame
if savegame ~= nil then
local xmlFile = savegame.xmlFile
local key = savegame.key ..".TSX_EnhancedVehicle"
local _data
for _, _data in pairs( { {1, 'frontDiffIsOn'}, {2, 'backDiffIsOn'}, {5, 'shuttleIsOn'}, {4, 'shuttleIsForward'}, {6, 'shuttleBreakIsOn'}, {3, 'driveMode'} }) do
local idx = _data[1]
local _v
if idx == 3 then
_v = getXMLInt(xmlFile, key.."#".. _data[2])
else
_v = getXMLBool(xmlFile, key.."#".. _data[2])
end
if _v ~= nil then
if idx == 3 then
self.vData.is[idx] = -1
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.is[idx] = false
self.vData.want[idx] = true
if debug > 1 then print("--> found ".._data[2].."=true in savegame" .. mySelf(self)) end
else
self.vData.is[idx] = true
self.vData.want[idx] = false
if debug > 1 then print("--> found ".._data[2].."=false in savegame" .. mySelf(self)) end
end
end
end
end
end
end
end
-- #############################################################################
function TSX_EnhancedVehicle:saveToXMLFile(xmlFile, key)
if debug > 1 then print("-> " .. myName .. ": saveToXMLFile" .. mySelf(self)) end
setXMLBool(xmlFile, key.."#frontDiffIsOn", self.vData.is[1])
setXMLBool(xmlFile, key.."#backDiffIsOn", self.vData.is[2])
setXMLBool(xmlFile, key.."#shuttleIsOn", self.vData.is[5])
setXMLBool(xmlFile, key.."#shuttleIsForward", self.vData.is[4])
setXMLBool(xmlFile, key.."#shuttleBreakIsOn", self.vData.is[6])
setXMLInt(xmlFile, key.."#driveMode", self.vData.is[3])
end
-- #############################################################################
function TSX_EnhancedVehicle:onUpdate(dt)
if debug > 2 then print("-> " .. myName .. ": onUpdate " .. dt .. ", S: " .. tostring(self.isServer) .. ", C: " .. tostring(self.isClient) .. mySelf(self)) end
-- (server) process changes between "is" and "want"
if self.isServer and self.vData ~= nil then
-- front diff
if self.vData.is[1] ~= self.vData.want[1] then
if TSX_EnhancedVehicle.functionDifferentialIsEnabled 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 TSX_EnhancedVehicle.functionDifferentialIsEnabled 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 TSX_EnhancedVehicle.functionDifferentialIsEnabled 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
-- shuttle shift on/off
if self.vData.is[5] ~= self.vData.want[5] then
if TSX_EnhancedVehicle.functionShuttleIsEnabled then
if self.vData.want[5] then
-- force setting of drive direction
self.vData.is[4] = not self.vData.want[4]
if debug > 0 then print("--> ("..self.rootNode..") changed shuttle shift isOn to: ON") end
else
-- reset drive direction to normal
if self.spec_reverseDriving ~= nil and self.spec_reverseDriving.isReverseDriving ~= nil then
self.spec_drivable.reverserDirection = self.spec_reverseDriving.isReverseDriving and -1 or 1
else
self.spec_drivable.reverserDirection = 1
end
if debug > 0 then print("--> ("..self.rootNode..") changed shuttle shift isOn to: OFF") end
end
end
self.vData.is[5] = self.vData.want[5]
end
-- shuttle shift switch direction
if self.vData.is[4] ~= self.vData.want[4] then
if TSX_EnhancedVehicle.functionShuttleIsEnabled then
if self.vData.want[4] then
self.spec_drivable.reverserDirection = 1
if debug > 0 then print("--> ("..self.rootNode..") changed shuttle shift isForward to: TRUE") end
else
self.spec_drivable.reverserDirection = -1
if debug > 0 then print("--> ("..self.rootNode..") changed shuttle shift isForward to: FALSE") end
end
-- turn around driving direction if vehicle is in reverse driving mode
local _isRD = 1
if self.spec_reverseDriving ~= nil and self.spec_reverseDriving.isReverseDriving ~= nil then
_isRD = self.spec_reverseDriving.isReverseDriving and -1 or 1
end
self.spec_drivable.reverserDirection = self.spec_drivable.reverserDirection * _isRD
end
self.vData.is[4] = self.vData.want[4]
end
-- shuttle shift parking break
if self.vData.is[6] ~= self.vData.want[6] then
if TSX_EnhancedVehicle.functionShuttleIsEnabled then
if self.vData.want[6] then
if debug > 0 then print("--> ("..self.rootNode..") changed shuttle shift breakIsOn to: TRUE") end
else
if debug > 0 then print("--> ("..self.rootNode..") changed shuttle shift breakIsOn to: FALSE") end
end
end
self.vData.is[6] = self.vData.want[6]
end
end
-- on client side only
if TSX_EnhancedVehicle.functionShuttleIsEnabled then
if self.isClient and self:getIsVehicleControlledByPlayer() then
if self.reverseSample ~= nil then
if self.reverseLights then
if not g_soundManager:getIsSamplePlaying(self.reverseSample) then
-- beep beep
g_soundManager:playSample(self.reverseSample)
end
else
if g_soundManager:getIsSamplePlaying(self.reverseSample) then
-- no beep beep
g_soundManager:stopSample(self.reverseSample)
end
end
end
end
end
end
-- #############################################################################
function TSX_EnhancedVehicle:onDraw()
if debug > 2 then print("-> " .. myName .. ": onDraw, S: " .. tostring(self.isServer) .. ", C: " .. tostring(self.isClient) .. mySelf(self)) end
-- only on client side and GUI is visible
if self.isClient and not g_gui:getIsGuiVisible() and self:getIsControlled() then
local vcaShuttleCtrl = false
if type( self.vcaExternalGetShuttleCtrl ) == "function" then
vcaShuttleCtrl = self:vcaExternalGetShuttleCtrl()
end
local fS = TSX_EnhancedVehicle.fontSize * TSX_EnhancedVehicle.uiScale
local tP = TSX_EnhancedVehicle.textPadding * TSX_EnhancedVehicle.uiScale
-- show mod conflict warning (very bad implementation :-( )
if TSX_EnhancedVehicle.functionShuttleIsEnabled and (vcaShuttleCtrl or self.ksmShuttleCtrl or self.ksmShuttleIsOn) then
setTextColor(1, 1, 1, 1)
setTextAlignment(RenderText.ALIGN_LEFT)
setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_MIDDLE)
setTextBold(true)
warning_txt = string.format("%s\n%s\n\n%s\n%s\n%s\n\n%s\n%s\n%s\n\n(*) %s", g_i18n:getText("EV_KS_warning1"), g_i18n:getText("EV_KS_warning2"), g_i18n:getText("EV_KS_warning3"),
g_i18n:getText("EV_KS_warning4"), g_i18n:getText("EV_KS_warning5"), g_i18n:getText("EV_KS_warning6"),
g_i18n:getText("EV_KS_warning7"), g_i18n:getText("EV_KS_warning8"), lC.confFile)
w = getTextWidth(fS*1.6, warning_txt)
renderText(0.5-(w/2), 0.25, fS*1.6, warning_txt)
end
-- render debug stuff
if TSX_dbg then
setTextColor(1,0,0,1)
setTextAlignment(RenderText.ALIGN_CENTER)
setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_MIDDLE)
setTextBold(true)
renderText(0.5, 0.5, 0.025, "dbg1: "..TSX_dbg1..", dbg2: "..TSX_dbg2..", dbg3: "..TSX_dbg3)
-- render some help points into speedMeter
setTextColor(1,0,0,1)
setTextAlignment(RenderText.ALIGN_CENTER)
setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_MIDDLE)
setTextBold(false)
renderText(g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterX, g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterY, 0.01, "O")
renderText(g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterX + g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeRadiusX, g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterY + g_currentMission.inGameMenu.hud.speedMeter.fuelGaugeRadiusY, 0.01, "O")
renderText(g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterX - g_currentMission.inGameMenu.hud.speedMeter.damageGaugeRadiusX, g_currentMission.inGameMenu.hud.speedMeter.gaugeCenterY + g_currentMission.inGameMenu.hud.speedMeter.damageGaugeRadiusY, 0.01, "O")
end
-- prepare overlays
if TSX_EnhancedVehicle.overlay["fuel"] == nil then
TSX_EnhancedVehicle.overlay["fuel"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/overlay_bg.dds")
setOverlayColor(TSX_EnhancedVehicle.overlay["fuel"], 0, 0, 0, TSX_EnhancedVehicle.overlayTransparancy)
end
if TSX_EnhancedVehicle.overlay["dmg"] == nil then
TSX_EnhancedVehicle.overlay["dmg"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/overlay_bg.dds")
setOverlayColor(TSX_EnhancedVehicle.overlay["dmg"], 0, 0, 0, TSX_EnhancedVehicle.overlayTransparancy)
end
if TSX_EnhancedVehicle.overlay["misc"] == nil then
TSX_EnhancedVehicle.overlay["misc"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/overlay_bg.dds")
setOverlayColor(TSX_EnhancedVehicle.overlay["misc"], 0, 0, 0, TSX_EnhancedVehicle.overlayTransparancy)
end
if TSX_EnhancedVehicle.overlay["diff_bg"] == nil then
TSX_EnhancedVehicle.overlay["diff_bg"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/overlay_diff_bg.dds")
setOverlayColor(TSX_EnhancedVehicle.overlay["diff_bg"], 0, 0, 0, 1)
end
if TSX_EnhancedVehicle.overlay["diff_front"] == nil then
TSX_EnhancedVehicle.overlay["diff_front"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/overlay_diff_front.dds")
end
if TSX_EnhancedVehicle.overlay["diff_back"] == nil then
TSX_EnhancedVehicle.overlay["diff_back"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/overlay_diff_back.dds")
end
if TSX_EnhancedVehicle.overlay["diff_dm"] == nil then
TSX_EnhancedVehicle.overlay["diff_dm"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/overlay_diff_dm.dds")
end
if TSX_EnhancedVehicle.overlay["dir_fwd"] == nil then
TSX_EnhancedVehicle.overlay["dir_fwd"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/direction_indicator_fwd.dds")
end
if TSX_EnhancedVehicle.overlay["dir_rev"] == nil then
TSX_EnhancedVehicle.overlay["dir_rev"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/direction_indicator_rev.dds")
end
if TSX_EnhancedVehicle.overlay["dir_neutral"] == nil then
TSX_EnhancedVehicle.overlay["dir_neutral"] = createImageOverlay(TSX_EnhancedVehicle.modDirectory .. "media/direction_indicator_neutral.dds")
end
-- ### do the fuel stuff ###
if self.spec_fillUnit ~= nil and TSX_EnhancedVehicle.fuel.enabled then
-- get values
fuel_diesel_current = -1
fuel_adblue_current = -1
for _, fillUnit in ipairs(self.spec_fillUnit.fillUnits) do
if fillUnit.fillType == 32 then -- Diesel
fuel_diesel_max = fillUnit.capacity
fuel_diesel_current = fillUnit.fillLevel
end
if fillUnit.fillType == 33 then -- AdBlue
fuel_adblue_max = fillUnit.capacity
fuel_adblue_current = fillUnit.fillLevel
end
end
-- prepare text
h = 0
fuel_txt_usage = ""
fuel_txt_diesel = ""
fuel_txt_adblue = ""
if fuel_diesel_current >= 0 then
fuel_txt_diesel = string.format("%.1f l/%.1f l", fuel_diesel_current, fuel_diesel_max)
h = h + fS + tP
end
if fuel_adblue_current >= 0 then
fuel_txt_adblue = string.format("%.1f l/%.1f l", fuel_adblue_current, fuel_adblue_max)
h = h + fS + tP
end
if self.spec_motorized.isMotorStarted == true and self.isServer then
fuel_txt_usage = string.format("%.2f l/h", self.spec_motorized.lastFuelUsage)
h = h + fS + tP
end
-- render overlay
w = getTextWidth(fS, fuel_txt_diesel)
tmp = getTextWidth(fS, fuel_txt_adblue)
if tmp > w then
w = tmp
end
tmp = getTextWidth(fS, fuel_txt_usage)
if tmp > w then
w = tmp
end
renderOverlay(TSX_EnhancedVehicle.overlay["fuel"], TSX_EnhancedVehicle.fuel.posX - TSX_EnhancedVehicle.overlayBorder, TSX_EnhancedVehicle.fuel.posY - TSX_EnhancedVehicle.overlayBorder, w + (TSX_EnhancedVehicle.overlayBorder*2), h + (TSX_EnhancedVehicle.overlayBorder*2))
-- render text
tmpY = TSX_EnhancedVehicle.fuel.posY
setTextAlignment(RenderText.ALIGN_LEFT)
setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_BOTTOM)
setTextBold(false)
if fuel_txt_diesel ~= "" then
setTextColor(unpack(TSX_EnhancedVehicle.color.fuel))
renderText(TSX_EnhancedVehicle.fuel.posX, tmpY, fS, fuel_txt_diesel)
tmpY = tmpY + fS + tP
end
if fuel_txt_adblue ~= "" then
setTextColor(unpack(TSX_EnhancedVehicle.color.adblue))
renderText(TSX_EnhancedVehicle.fuel.posX, tmpY, fS, fuel_txt_adblue)
tmpY = tmpY + fS + tP
end
if fuel_txt_usage ~= "" then
setTextColor(1,1,1,1)
renderText(TSX_EnhancedVehicle.fuel.posX, tmpY, fS, fuel_txt_usage)
end
setTextColor(1,1,1,1)
end
-- ### do the damage stuff ###
if self.spec_wearable ~= nil and TSX_EnhancedVehicle.dmg.enabled then
-- prepare text
h = 0
dmg_txt = ""
if self.spec_wearable.totalAmount ~= nil then
dmg_txt = string.format("%s: %.1f", self.typeDesc, (self.spec_wearable.totalAmount * 100)) .. "%"
h = h + fS + tP
end
dmg_txt2 = ""
if self.spec_attacherJoints ~= nil then
getDmg(self.spec_attacherJoints)
end
-- render overlay
w = getTextWidth(fS, dmg_txt)
tmp = getTextWidth(fS, dmg_txt2) + 0.005
if tmp > w then
w = tmp
end
renderOverlay(TSX_EnhancedVehicle.overlay["dmg"], TSX_EnhancedVehicle.dmg.posX - TSX_EnhancedVehicle.overlayBorder - w, TSX_EnhancedVehicle.dmg.posY - TSX_EnhancedVehicle.overlayBorder, w + (TSX_EnhancedVehicle.overlayBorder * 2), h + (TSX_EnhancedVehicle.overlayBorder * 2))
-- render text
setTextColor(1,1,1,1)
setTextAlignment(RenderText.ALIGN_RIGHT)
setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_BOTTOM)
setTextColor(unpack(TSX_EnhancedVehicle.color.dmg))
setTextBold(false)
renderText(TSX_EnhancedVehicle.dmg.posX, TSX_EnhancedVehicle.dmg.posY, fS, dmg_txt)
setTextColor(1,1,1,1)
renderText(TSX_EnhancedVehicle.dmg.posX, TSX_EnhancedVehicle.dmg.posY + fS + tP, fS, dmg_txt2)
end
-- ### do the misc stuff ###
if self.spec_motorized ~= nil and TSX_EnhancedVehicle.misc.enabled then
-- prepare text
misc_txt = string.format("%.1f", self:getTotalMass(true)) .. "t (total: " .. string.format("%.1f", self:getTotalMass()) .. " t)"
-- render overlay
w = getTextWidth(fS, misc_txt)
h = getTextHeight(fS, misc_txt)
renderOverlay(TSX_EnhancedVehicle.overlay["misc"], TSX_EnhancedVehicle.misc.posX - TSX_EnhancedVehicle.overlayBorder - (w/2), TSX_EnhancedVehicle.misc.posY - TSX_EnhancedVehicle.overlayBorder, w + (TSX_EnhancedVehicle.overlayBorder * 2), h + (TSX_EnhancedVehicle.overlayBorder * 2))
-- render text
setTextColor(1,1,1,1)
setTextAlignment(RenderText.ALIGN_CENTER)
setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_BOTTOM)
setTextBold(false)
renderText(TSX_EnhancedVehicle.misc.posX, TSX_EnhancedVehicle.misc.posY, fS, misc_txt)
end
-- ### do the rpm stuff ###
if self.spec_motorized ~= nil and TSX_EnhancedVehicle.rpm.enabled then
-- prepare text
rpm_txt = "--\nrpm"
if self.spec_motorized.isMotorStarted == true then
rpm_txt = string.format("%i\nrpm", self.spec_motorized.motor.lastMotorRpm)
end
-- render text
setTextColor(1,1,1,1)
setTextAlignment(RenderText.ALIGN_CENTER)
setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_TOP)
setTextBold(true)
renderText(TSX_EnhancedVehicle.rpm.posX, TSX_EnhancedVehicle.rpm.posY, fS, rpm_txt)
end
-- ### do the temperature stuff ###
if self.spec_motorized ~= nil and TSX_EnhancedVehicle.temp.enabled and self.isServer then
-- prepare text
temp_txt = "--\n°C"
if self.spec_motorized.isMotorStarted == true then
temp_txt = string.format("%i\n°C", self.spec_motorized.motorTemperature.value)
end
-- render text
setTextColor(1,1,1,1)
setTextAlignment(RenderText.ALIGN_CENTER)
setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_TOP)
setTextBold(true)
renderText(TSX_EnhancedVehicle.temp.posX, TSX_EnhancedVehicle.temp.posY, fS, temp_txt)
end
-- ### do the differential stuff ###
if TSX_EnhancedVehicle.functionDifferentialIsEnabled and self.spec_motorized ~= nil and TSX_EnhancedVehicle.diff.enabled then
-- prepare text
_txt = {}
_txt.color = { "green", "green", "gray" }
if self.vData ~= nil then
if self.vData.is[1] then
_txt.color[1] = "red"
end
if self.vData.is[2] then
_txt.color[2] = "red"
end
if self.vData.is[3] == 0 then
_txt.color[3] = "gray"
end
if self.vData.is[3] == 1 then
_txt.color[3] = "yellow"
end
if self.vData.is[3] == 2 then
_txt.color[3] = "gray"
end
end
-- render overlay
w, h = getNormalizedScreenValues(TSX_EnhancedVehicle.diff_overlayWidth / TSX_EnhancedVehicle.diff.zoomFactor * TSX_EnhancedVehicle.uiScale, TSX_EnhancedVehicle.diff_overlayHeight / TSX_EnhancedVehicle.diff.zoomFactor * TSX_EnhancedVehicle.uiScale)
setOverlayColor(TSX_EnhancedVehicle.overlay["diff_front"], unpack(TSX_EnhancedVehicle.color[_txt.color[1]]))
setOverlayColor(TSX_EnhancedVehicle.overlay["diff_back"], unpack(TSX_EnhancedVehicle.color[_txt.color[2]]))
setOverlayColor(TSX_EnhancedVehicle.overlay["diff_dm"], unpack(TSX_EnhancedVehicle.color[_txt.color[3]]))
renderOverlay(TSX_EnhancedVehicle.overlay["diff_bg"], TSX_EnhancedVehicle.diff.posX, TSX_EnhancedVehicle.diff.posY, w, h)
renderOverlay(TSX_EnhancedVehicle.overlay["diff_front"], TSX_EnhancedVehicle.diff.posX, TSX_EnhancedVehicle.diff.posY, w, h)
renderOverlay(TSX_EnhancedVehicle.overlay["diff_back"], TSX_EnhancedVehicle.diff.posX, TSX_EnhancedVehicle.diff.posY, w, h)
renderOverlay(TSX_EnhancedVehicle.overlay["diff_dm"], TSX_EnhancedVehicle.diff.posX, TSX_EnhancedVehicle.diff.posY, w, h)
end
-- ### do the shuttle shift stuff ###
if TSX_EnhancedVehicle.functionShuttleIsEnabled and self.vData ~= nil and TSX_EnhancedVehicle.shuttle.enabled then
local _color = { "gray", "gray", "gray" }
local _trans = 0.25
-- prepare
if self.vData.is[5] then
if self.vData.is[4] then
_color = { "green", "gray", "gray" }
_trans = 1
end
if not self.vData.is[4] then
_color = { "gray", "gray", "green" }
_trans = 1
end
if self.vData.is[6] then
_color = { "gray", "red", "gray" }
_trans = 1
end
end
if not self:getIsVehicleControlledByPlayer() then
_trans = 0.25
end
-- render overlay
w, h = getNormalizedScreenValues(TSX_EnhancedVehicle.dir_overlayWidth / TSX_EnhancedVehicle.shuttle.zoomFactor * TSX_EnhancedVehicle.uiScale, TSX_EnhancedVehicle.dir_overlayHeight / TSX_EnhancedVehicle.shuttle.zoomFactor * TSX_EnhancedVehicle.uiScale)
local _col = { unpack(TSX_EnhancedVehicle.color[_color[1]]) }
_col[4] = _trans
setOverlayColor(TSX_EnhancedVehicle.overlay["dir_fwd"], unpack(_col))
_col = { unpack(TSX_EnhancedVehicle.color[_color[2]]) }
_col[4] = _trans
setOverlayColor(TSX_EnhancedVehicle.overlay["dir_neutral"], unpack(_col))
_col = { unpack(TSX_EnhancedVehicle.color[_color[3]]) }
_col[4] = _trans
setOverlayColor(TSX_EnhancedVehicle.overlay["dir_rev"], unpack(_col))
renderOverlay(TSX_EnhancedVehicle.overlay["dir_fwd"], TSX_EnhancedVehicle.shuttle.posX, TSX_EnhancedVehicle.shuttle.posY, w, h)
renderOverlay(TSX_EnhancedVehicle.overlay["dir_neutral"], TSX_EnhancedVehicle.shuttle.posX, TSX_EnhancedVehicle.shuttle.posY, w, h)
renderOverlay(TSX_EnhancedVehicle.overlay["dir_rev"], TSX_EnhancedVehicle.shuttle.posX, TSX_EnhancedVehicle.shuttle.posY, w, h)
end
-- reset text stuff to "defaults"
setTextColor(1,1,1,1)
setTextAlignment(RenderText.ALIGN_LEFT)
setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_BASELINE)
setTextBold(false)
end
end
-- #############################################################################
function TSX_EnhancedVehicle:onReadStream(streamId, connection)
if debug > 1 then print("-> " .. myName .. ": onReadStream - " .. streamId .. mySelf(self)) end
if self.vData == nil then
self.vData = {}
self.vData.is = {}
self.vData.want = {}
end
-- receive initial data from server
self.vData.is[1] = streamReadBool(streamId)
self.vData.is[2] = streamReadBool(streamId)
self.vData.is[3] = streamReadInt8(streamId)
self.vData.is[4] = streamReadBool(streamId)
self.vData.is[5] = streamReadBool(streamId)
self.vData.is[6] = streamReadBool(streamId)
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
-- #############################################################################