This repository has been archived by the owner on Jan 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
gearboxMogli.lua
executable file
·10183 lines (9106 loc) · 413 KB
/
gearboxMogli.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
--***************************************************************
--
-- gearboxMogli
--
-- version 2.200 by mogli (biedens)
--
--***************************************************************
local gearboxMogliVersion=2.200
-- allow modders to include this source file together with mogliBase.lua in their mods
if gearboxMogli == nil or gearboxMogli.version == nil or gearboxMogli.version < gearboxMogliVersion then
--***************************************************************
if _G[g_currentModName..".mogliBase"] == nil then
source(Utils.getFilename("mogliBase.lua", g_currentModDirectory))
end
_G[g_currentModName..".mogliBase"].newClass( "gearboxMogli", "mrGbMS" )
--***************************************************************
gearboxMogli.version = gearboxMogliVersion
gearboxMogli.huge = 1E+9
gearboxMogli.eps = 1E-9
gearboxMogli.factor30pi = 9.5492965855137201461330258023509
gearboxMogli.factorpi30 = 0.10471975511965977461542144610932
gearboxMogli.rpmRatedMinus = 100 -- 100 -- min RPM at 900 RPM
gearboxMogli.rpmMinus = 300 -- 100 -- min RPM at 900 RPM
gearboxMogli.rpmPlus = 300 -- braking at 2350 RPM
gearboxMogli.minRpmInSpeedHudDelta= 500
gearboxMogli.maxRpmInSpeedHudDelta= 2500
gearboxMogli.autoShiftRpmDiff = gearboxMogli.huge -- 200
gearboxMogli.autoShiftPowerRatio = 1.03
gearboxMogli.autoShiftMaxDeltaRpm = 1E-3
gearboxMogli.minClutchPercent = 0.01
gearboxMogli.minClutchPercentStd = 0.5
gearboxMogli.minClutchPercentTC = 0.2
gearboxMogli.minClutchPercentTCL = 0.2
gearboxMogli.maxClutchPercentTC = 0.96
gearboxMogli.clutchPercentShift = 0.2
gearboxMogli.clutchLoopTimes = 10
gearboxMogli.clutchLoopDelta = 10
gearboxMogli.minHydrostaticFactor = 5e-3
gearboxMogli.fixedRatioDeltaRatio = 0.01 -- allow 1% deviation for hydrostatic and fixed ratio
gearboxMogli.maxGearRatio = 37699.11184 -- 0.01 km/h @1000 RPM / gear ratio might be bigger, but no clutch in this case
gearboxMogli.minGearRatio = 1.508 -- 250 km/h @1000 RPM / gear ratio might be bigger, but no clutch in this case
gearboxMogli.maxHydroGearRatio = gearboxMogli.maxGearRatio / 500 -- 5.0 km/h @1000 RPM / gear ratio might be bigger, but no clutch in this case
gearboxMogli.maxManualGearRatio = gearboxMogli.maxGearRatio / 20 -- 0.2 km/h @1000 RPM / gear ratio might be bigger, but no clutch in this case
gearboxMogli.maxRatioFactorR = gearboxMogli.huge -- 2000 -- 0.001km/h @1000 RPM if combined with maxHydroGearRatio
gearboxMogli.brakeFxSpeed = 2.5 -- m/s = 9 km/h
gearboxMogli.rpmReduction = 0.925 -- 7.5% --0.85 -- 15% RPM reduction allowed e.g. 330 RPM for 2200 rated RPM
gearboxMogli.maxPowerLimit = 0.97 -- 97% max power is equal to max power
gearboxMogli.maxMaxPowerRatio = 1.0 -- RPM where shift to maxMaxPowerRpm starts
gearboxMogli.autoShiftUpRatio = 0.98 --
gearboxMogli.smoothLittle = 0.2
gearboxMogli.smoothFast = 0.12
gearboxMogli.smoothMedium = 0.04
gearboxMogli.smoothSlow = 0.01
gearboxMogli.hydroEffDiff = 0
gearboxMogli.hydroEffDiffInc = 50
gearboxMogli.hydroEffMin = 0.5
gearboxMogli.motorSmoothRpmDiff = 10
gearboxMogli.ptoRpmHydroDiff = 25
gearboxMogli.ptoRpmThrottleDiff = 50
gearboxMogli.lastMotorRpmDiffReal = 50
gearboxMogli.powerFactor0 = 0.1424083769633507853403141361257
gearboxMogli.powerFactorP = gearboxMogli.powerFactor0 / 1.36
gearboxMogli.powerFactorPI = 1.36 / gearboxMogli.powerFactor0
gearboxMogli.fuelFactor = 1/(830*60*60*1000)-- 830 g per liter per hour => liter per millisecond
gearboxMogli.accDeadZone = 0.1
gearboxMogli.blowOffVentilTime0 = 1500
gearboxMogli.blowOffVentilTime1 = 1000
gearboxMogli.blowOffVentilTime2 = 100
gearboxMogli.debugGearShift = false
gearboxMogli.globalsLoaded = false
gearboxMogli.ptoSpeedLimitMin = 3 / 3.6 -- minimal speed limit
gearboxMogli.ptoSpeedLimitIni = 0.2 / 3.6 -- initial offset for ptoSpeedLimit
gearboxMogli.ptoSpeedLimitOff = 2.0 / 3.6 -- turn off ptoSpeedLimit
gearboxMogli.ptoSpeedLimitDec = 0.2 / 3600 -- brake
gearboxMogli.ptoSpeedLimitInc = 1.0 / 3600 -- accelerate by 2 km/h per second
gearboxMogli.ptoSpeedLimitRatio = 0.05
gearboxMogli.ptoSpeedLimitTime = 300
gearboxMogli.combineUseRealArea = true
gearboxMogli.AIPowerShift = "P"
gearboxMogli.AIGearboxOff = "N"
gearboxMogli.AIAllAuto = "A"
gearboxMogli.AIGearboxOn = "Y"
gearboxMogli.kmhTOms = 5 / 18
gearboxMogli.extraSpeedLimit = 0.15
gearboxMogli.extraSpeedLimitMs = gearboxMogli.extraSpeedLimit / 3.6
gearboxMogli.deltaLimitTimeMs = 500
gearboxMogli.speedLimitBrake = 2 / 3.6 -- m/s
gearboxMogli.speedLimitRpmDiff = 1 --5
gearboxMogli.motorBrakeTimeInv = 0.003
gearboxMogli.motorBrakeFactor = 0.8
gearboxMogli.motorLoadExp = 1.5
gearboxMogli.gearShiftingNoThrottle = 178 -- just a big integer
gearboxMogli.trustClutchRpmTimer = 50
gearboxMogli.brakeForceLimitRpm = 25
gearboxMogli.setSprayLevel = true -- digging wheels increas the spray level
gearboxMogli.enabledAtClient = true
gearboxMogli.simplifiedAtClient = false
gearboxMogliGlobals = {}
gearboxMogliGlobals.debugPrint = false
gearboxMogliGlobals.debugInfo = false
gearboxMogliGlobals.transmissionEfficiency= 0.96
-- Giants is cheating: 0.86 * 0.88 = 0.7568 > 0.72 => torqueFactor = 0.86 * 0.88 / ( 0.72 * 0.94 )
gearboxMogliGlobals.torqueFactor = 1 --0.86 * 0.88 / ( 0.72 * gearboxMogliGlobals.transmissionEfficiency )
gearboxMogliGlobals.blowOffVentilVol = 0.14
gearboxMogliGlobals.drawTargetRpm = false
gearboxMogliGlobals.drawReqPower = false
gearboxMogliGlobals.defaultOn = true
gearboxMogliGlobals.noDisable = false
gearboxMogliGlobals.disableManual = false
gearboxMogliGlobals.blowOffVentilRpmRatio = 0.7
gearboxMogliGlobals.minTimeToShift = 1 -- ms
gearboxMogliGlobals.minTimeToShiftReverse = 500 -- ms
gearboxMogliGlobals.maxTimeToSkipGear = 251 -- ms
gearboxMogliGlobals.autoShiftTimeoutLong = 3000 -- ms
gearboxMogliGlobals.autoShiftTimeoutShort = 400 -- ms -- let it go up to ratedRPM !!!
gearboxMogliGlobals.autoShiftTimeoutHydroL= 1000 -- ms
gearboxMogliGlobals.autoShiftTimeoutHydroS= 0 -- ms
gearboxMogliGlobals.shiftEffectTime = 251 -- ms
gearboxMogliGlobals.shiftTimeMsFactor = 1
gearboxMogliGlobals.playGrindingSound = true
gearboxMogliGlobals.defaultHudMode = 1 -- 0: no HUD, 1: big HUD, 2: small HUD with gear name only
gearboxMogliGlobals.hudPositionX = 0.84
gearboxMogliGlobals.hudPositionY = 0.7
gearboxMogliGlobals.hudTextSize = 0.02
gearboxMogliGlobals.hudTitleSize = 0.03
gearboxMogliGlobals.hudBorder = 0.005
gearboxMogliGlobals.hudWidth = 0.15
gearboxMogliGlobals.stallWarningTime = 250
gearboxMogliGlobals.stallMotorOffTime = 1250
gearboxMogliGlobals.realFuelUsage = true
gearboxMogliGlobals.idleFuelTorqueRatio = 0.3
gearboxMogliGlobals.defaultLiterPerSqm = 1.2 -- 1.2 l/m² for wheat
gearboxMogliGlobals.combineDefaultSpeed = 8 -- km/h
gearboxMogliGlobals.combineDynamicRatio = 0.6
gearboxMogliGlobals.combineDynamicChopper = 0.8
gearboxMogliGlobals.calculateCombinePower = true -- calculate power consumption of combine/cutter
gearboxMogliGlobals.dtDeltaTargetFast = 0.0003 -- 3 1/3 second
gearboxMogliGlobals.dtDeltaTargetSlow = 0.00014 -- 7 seconds
gearboxMogliGlobals.ddsDirectory = "dds/"
gearboxMogliGlobals.initMotorOnLoad = true
gearboxMogliGlobals.ptoSpeedLimit = true
gearboxMogliGlobals.clutchExp = 1.0
gearboxMogliGlobals.clutchFactor = 1.5 -- 1.2
gearboxMogliGlobals.grindingMinRpmDelta = 200
gearboxMogliGlobals.grindingMaxRpmSound = 600
gearboxMogliGlobals.grindingMaxRpmDelta = gearboxMogli.huge
gearboxMogliGlobals.defaultEnableAI = gearboxMogli.AIPowerShift
gearboxMogliGlobals.autoHold = false -- true
gearboxMogliGlobals.minAutoGearSpeed = 1.0 -- 0.2777 -- m/s
gearboxMogliGlobals.minAbsSpeed = 1.0 -- km/h
gearboxMogliGlobals.brakeNeutralTimeout = 1000 -- ms
gearboxMogliGlobals.brakeNeutralLimit = -0.3
gearboxMogliGlobals.DefaultRevUpMs0 = 2000 -- ms time between idle and rated RPM w/o load
gearboxMogliGlobals.DefaultRevUpMs1 = 15000 -- ms time between idle and rated RPM with full load
gearboxMogliGlobals.DefaultRevUpMsH = 30000 -- ms time between idle and rated RPM with full load (hydrostat)
gearboxMogliGlobals.DefaultRevUpMs2 = 750 -- ms time between idle and rated RPM in neutral
gearboxMogliGlobals.DefaultRevDownMs = 1500 -- ms time between rated and idle RPM
gearboxMogliGlobals.HydroSpeedIdleRedux = 1e-3 -- 0.04 -- default reduce by 10 km/h per second => 0.4 km/h with const. RPM and w/o acc.
gearboxMogliGlobals.smoothGearRatio = true -- smooth gear ratio with hydrostatic drive
gearboxMogliGlobals.smoothGearRatioTC = true -- smooth gear ratio with torque converter
gearboxMogliGlobals.hydroMaxTorqueInput = 0 -- 2
gearboxMogliGlobals.hydroMaxTorqueOutput = 0 -- 3
gearboxMogliGlobals.hydroMaxTorqueDirect = 0 -- 4
gearboxMogliGlobals.minClutchTimeManual = 3000 -- ms; time from 0% to 100% for the digital manual clutch
gearboxMogliGlobals.momentOfInertiaBase = 1 -- J in unit kg m^2; for a cylinder with mass m and radius r: J = 0.5 * m * r^2
gearboxMogliGlobals.momentOfInertia = 4 -- J in unit kg m^2; for a cylinder with mass m and radius r: J = 0.5 * m * r^2
gearboxMogliGlobals.inertiaToDampingRatio = 0.333
gearboxMogliGlobals.momentOfInertiaMin = 1e-4 -- 0.5 * 1e-3 is already multiplied by 1e-3!!!
gearboxMogliGlobals.brakeForceRatio = 0.03 -- tested, see issue #101
gearboxMogliGlobals.maxRpmThrottle = 0.9
gearboxMogliGlobals.maxRpmThrottleAuto = true
gearboxMogliGlobals.noSpeedMatching = false -- option to disable speed matching for all vehicles
gearboxMogliGlobals.autoStartStop = false -- option to enable auto start stop for all vechiles
gearboxMogliGlobals.noAutoStartStop = false -- option to disable auto start stop for all vechiles
gearboxMogliGlobals.useMrUWP = 10
gearboxMogliGlobals.reduceMOIClutchLimit = 0.5 -- reduce moment of inertia if clutch is below 50%
gearboxMogliGlobals.reduceMOILowRatio = false -- reduce moment of inertia at low gear ratio, default is off
gearboxMogliGlobals.reduceMOILowSpeed = false -- reduce moment of inertia at low speed, default is off
gearboxMogliGlobals.accThrottleExp = 1.5
gearboxMogliGlobals.accelerateToLimit = 5 -- km/h per second
gearboxMogliGlobals.decAccToLimitRatio = 2 -- decelerateToLimit = accelerateToLimit * decAccToLimitRatio
gearboxMogliGlobals.onlyTwoSpeeds = false -- only two CC speeds instead of three
gearboxMogliGlobals.manual4wd = true -- diff lock
gearboxMogliGlobals.maxDeltaAccPerMs = 0.003 -- max delta for acceleration; it takes 333 ms from 0 to 1
gearboxMogliGlobals.uiFixedRatioStep = 2
gearboxMogliGlobals.uiHandThrottleStep = 50 -- 50 RPM step, little more to avoid runding problems
gearboxMogliGlobals.clutchAxisOpen = -0.9 -- clutch axis from value from -1 to -0.9 => clutch = 0
gearboxMogliGlobals.clutchAxisClosed = 0.9 -- clutch axis from value from 0.9 to 1 => clutch = 1
gearboxMogliGlobals.ptoRpmFactor = 0.900 -- 0.75 -- reduce PTO RPM; e.g. 1900 with PTO and 2200 rated RPM
gearboxMogliGlobals.ptoRpmFactorEco = 2/3 -- 0.5 -- reduce PTO RPM in eco mode; e.g. 1600 with PTO and 2200 rated RPM
gearboxMogliGlobals.minTargetRpmFactor = 0.3 -- reduce PTO RPM in eco mode; e.g. 1600 with PTO and 2200 rated RPM
gearboxMogliGlobals.hydroRpmFactor = 0.3 -- reduce PTO RPM in eco mode; e.g. 1600 with PTO and 2200 rated RPM
gearboxMogliGlobals.increaseRpmForPTO = true -- increase RPM automatically if PTO is turned on
gearboxMogliGlobals.engineHumVolume = 1 -- volume of engine hum sound above max target RPM
gearboxMogliGlobals.shiftingBaseVolume = 1 -- volume factor of gear shifting sound
gearboxMogliGlobals.handbrakeBaseVolume = 1 -- volume factor of gear handbrake sound
gearboxMogliGlobals.slipPloughDefault = -1 -- 0: always off; 1: always on; -1: check for FS17_ForRealModule03_GroundResponse and FS17_ForRealModule01_CropDestruction
gearboxMogliGlobals.clutchSpeedOneButton = 4 -- 1 ~ 0%; 4 ~ 30%; 11 ~ 100%; 21 ~ 200%
gearboxMogliGlobals.maxSlipFactor = 1.2 -- digging wheels starts if wheel is 20% faster than ground speed
gearboxMogliGlobals.maxSlipInc = 0.4 -- additional 40% at full steering angle
gearboxMogliGlobals.lockedDiffSpeedLimit = 25 -- speed limit with 4wd on
--**********************************************************************************************************
-- gearboxMogli.prerequisitesPresent 7
--**********************************************************************************************************
function gearboxMogli.prerequisitesPresent(specializations)
return true
end
--**********************************************************************************************************
-- gearboxMogli:load
--**********************************************************************************************************
function gearboxMogli:load(savegame)
local key
key = string.format("vehicle.motorConfigurations.motorConfiguration(%d).gearboxMogli", self.configurations.motor-1)
if hasXMLProperty(self.xmlFile, key) then
gearboxMogli.initFromXml(self,self.xmlFile,key,nil,"vehicle",true)
return
end
key = "vehicle.motorConfigurations.motorConfiguration(0).gearboxMogli"
if hasXMLProperty(self.xmlFile, key) then
gearboxMogli.initFromXml(self,self.xmlFile,key,nil,"vehicle",true)
return
end
key = "vehicle.gearboxMogli"
if hasXMLProperty(self.xmlFile, key) then
gearboxMogli.initFromXml(self,self.xmlFile,key,nil,"vehicle",true)
return
end
end
--**********************************************************************************************************
-- gearboxMogli.getNoNil2
--**********************************************************************************************************
function gearboxMogli.getNoNil2( v0, v1, v2, use2 )
if v0 == nil then
if v2 ~= nil and use2 then
return v2
end
return v1
end
return v0
end
--**********************************************************************************************************
-- gearboxMogli generic getter methods
--**********************************************************************************************************
gearboxMogli.stateWithSetGet = { "IsOnOff",
"CurrentGear",
"CurrentRange",
"CurrentRange2",
"Automatic",
"AllAuto",
"NeutralActive",
"ReverseActive",
"SpeedLimiter",
"HandThrottle",
"MaxTarget",
"MinTarget",
"FixedRatio",
"AutoClutch",
"ManualClutch",
"AccelerateToLimit",
"EcoMode",
"HudMode" }
for _,state in pairs( gearboxMogli.stateWithSetGet ) do
gearboxMogli["mrGbMGet"..state] = function(self)
return self.mrGbMS[state]
end
gearboxMogli["mrGbMSet"..state] = function(self, value, noEventSend )
gearboxMogli.mbSetState( self, state, value, noEventSend )
end
end
--**********************************************************************************************************
-- gearboxMogli:initClient
--**********************************************************************************************************
function gearboxMogli:initClient()
-- state
self.mrGbMS = {}
-- locals used for calculations
self.mrGbML = {}
-- draw
self.mrGbMD = {}
-- backup
self.mrGbMB = {}
if self.mrGbMG == nil then
if not( gearboxMogli.globalsLoaded ) then
gearboxMogli.globalsLoaded = true
file = gearboxMogli.modsDirectory.."gearboxAddonConfig.xml"
if fileExists(file) then
gearboxMogli.globalsLoad( file, "vehicles.gearboxMogliGlobals", gearboxMogliGlobals, true )
end
gearboxMogliGlobals.hudWidth = Utils.clamp( 16.0 * g_screenHeight * gearboxMogliGlobals.hudWidth / ( 9.0 * g_screenWidth ), 0.05, 0.3 )
if gearboxMogliGlobals.hudWidth + gearboxMogliGlobals.hudPositionX > 1 then
gearboxMogliGlobals.hudPositionX = 1 - gearboxMogliGlobals.hudWidth
end
end
self.mrGbMG = gearboxMogliGlobals
end
self.mrGbMSetState = gearboxMogli.mbSetState
self.mrGbMDoGearShift = gearboxMogli.mrGbMDoGearShift
gearboxMogli.initStateHandling( self )
gearboxMogli.registerState( self, "IsOn", false, gearboxMogli.mrGbMOnSetIsOn )
gearboxMogli.registerState( self, "BlowOffVentilPlay",false )
gearboxMogli.registerState( self, "GrindingGearsVol", 0 )--, gearboxMogli.debugEvent )
gearboxMogli.registerState( self, "DrawText", "off" )
gearboxMogli.registerState( self, "DrawText2", "off" )
gearboxMogli.registerState( self, "G27Mode", 0 )
gearboxMogli.registerState( self, "WarningText", "", gearboxMogli.mrGbMOnSetWarningText )
gearboxMogli.registerState( self, "InfoText", "", gearboxMogli.mrGbMOnSetInfoText )
gearboxMogli.registerState( self, "ConstantRpm", false )
gearboxMogli.registerState( self, "NoUpdateStream",false, gearboxMogli.mrGbMOnSetNoUpdateStream )
gearboxMogli.registerState( self, "NUSMessage", {}, gearboxMogli.mrGbMOnSetNUSMessage )
gearboxMogli.registerState( self, "AutoCloseTimer",0 )
gearboxMogli.registerState( self, "DoubleClutch", 0 )
gearboxMogli.registerState( self, "ToolIsDirty2", true )
gearboxMogli.registerState( self, "ShuttleFactor", 0.5 )
gearboxMogli.registerState( self, "NoRetarderSound", false )
gearboxMogli.registerState( self, "NeutralNoSync", false )
gearboxMogli.registerState( self, "MotorBrake", false )
gearboxMogli.registerState( self, "UnlockDiff", false )
gearboxMogli.registerState( self, "GPSActive", false )
self.mrGbMS.ToolIsDirty = false
--**********************************************************************************************************
-- state variables with setter methods
for _,state in pairs( gearboxMogli.stateWithSetGet ) do
self["mrGbMSet"..state] = gearboxMogli["mrGbMSet"..state]
self["mrGbMGet"..state] = gearboxMogli["mrGbMGet"..state]
end
gearboxMogli.registerState( self, "IsOnOff", false )
gearboxMogli.registerState( self, "CurrentGear", 1, gearboxMogli.mrGbMOnSetGear )
gearboxMogli.registerState( self, "CurrentRange", 1, gearboxMogli.mrGbMOnSetRange )
gearboxMogli.registerState( self, "CurrentRange2", 1, gearboxMogli.mrGbMOnSetRange2 )
gearboxMogli.registerState( self, "NewGear", 0, gearboxMogli.mrGbMOnSetNewGear )
gearboxMogli.registerState( self, "NewRange", 0, gearboxMogli.mrGbMOnSetNewRange )
gearboxMogli.registerState( self, "NewRange2", 0, gearboxMogli.mrGbMOnSetNewRange2 )
gearboxMogli.registerState( self, "NewReverse", false, gearboxMogli.mrGbMOnSetNewReverse )
gearboxMogli.registerState( self, "IsNeutral", true )
gearboxMogli.registerState( self, "Automatic", true, gearboxMogli.mrGbMOnSetAutomatic )
gearboxMogli.registerState( self, "ReverseActive", false, gearboxMogli.mrGbMOnSetReverse )
gearboxMogli.registerState( self, "NeutralActive", true, gearboxMogli.mrGbMOnSetNeutral )
gearboxMogli.registerState( self, "Handbrake", false )
gearboxMogli.registerState( self, "AutoHold", false, gearboxMogli.mrGbMOnSetAutoHold )
gearboxMogli.registerState( self, "AutoClutch", true )
gearboxMogli.registerState( self, "ManualClutch", 1, gearboxMogli.mrGbMOnSetManualClutch )
gearboxMogli.registerState( self, "HandThrottle", 0 )
gearboxMogli.registerState( self, "MinTarget", 0 )
gearboxMogli.registerState( self, "MaxTarget", 0 )
gearboxMogli.registerState( self, "FixedRatio", 0 )
gearboxMogli.registerState( self, "SpeedLimiter", false )
gearboxMogli.registerState( self, "AllAuto", false )
gearboxMogli.registerState( self, "AllAuto2", false )
gearboxMogli.registerState( self, "AllAutoMode", 7, gearboxMogli.mrGbMOnSetAllAutoMode )
gearboxMogli.registerState( self, "EcoMode", false )
gearboxMogli.registerState( self, "HudMode", self.mrGbMG.defaultHudMode )
gearboxMogli.registerState( self, "CurrentGearSpeed", 0 )
gearboxMogli.registerState( self, "AutoMinGearSpeed", 0 )
gearboxMogli.registerState( self, "AutoMaxGearSpeed", 0 )
gearboxMogli.registerState( self, "AutoShiftRequest", 0 )
gearboxMogli.registerState( self, "GearShifterMode", 0 )
gearboxMogli.registerState( self, "ShuttleShifterMode", 0 )
gearboxMogli.registerState( self, "Range1ShifterMode", 0 )
gearboxMogli.registerState( self, "Range2ShifterMode", 0 )
gearboxMogli.registerState( self, "ManualDiffLock", 1 )
gearboxMogli.registerState( self, "DiffLockMiddle", false )
gearboxMogli.registerState( self, "DiffLockFront", false )
gearboxMogli.registerState( self, "DiffLockBack", false )
gearboxMogli.registerState( self, "MinAutoGearSpeed", 0 )
gearboxMogli.registerState( self, "MaxAutoGearSpeed", 0 )
--********************************************** ************************************************************
-- special getter functions for motor parameters
self.mrGbMGetClutchPercent = gearboxMogli.mrGbMGetClutchPercent
self.mrGbMGetAutoClutchPercent = gearboxMogli.mrGbMGetAutoClutchPercent
self.mrGbMGetCurrentRPM = gearboxMogli.mrGbMGetCurrentRPM
self.mrGbMGetTargetRPM = gearboxMogli.mrGbMGetTargetRPM
self.mrGbMGetMotorLoad = gearboxMogli.mrGbMGetMotorLoad
self.mrGbMGetUsedPower = gearboxMogli.mrGbMGetUsedPower
self.mrGbMGetThroughPut = gearboxMogli.mrGbMGetThroughPut
self.mrGbMGetModeText = gearboxMogli.mrGbMGetModeText
self.mrGbMGetModeShortText = gearboxMogli.mrGbMGetModeShortText
self.mrGbMGetGearText = gearboxMogli.mrGbMGetGearText
self.mrGbMGetIsOn = gearboxMogli.mrGbMGetIsOn
self.mrGbMGetAutoStartStop = gearboxMogli.mrGbMGetAutoStartStop
self.mrGbMGetAutoShiftGears = gearboxMogli.mrGbMGetAutoShiftGears
self.mrGbMGetAutoShiftRange = gearboxMogli.mrGbMGetAutoShiftRange
self.mrGbMGetAutoShiftRange2 = gearboxMogli.mrGbMGetAutoShiftRange2
self.mrGbMGetGearSpeed = gearboxMogli.mrGbMGetGearSpeed
self.mrGbMGetGearNumber = gearboxMogli.mrGbMGetGearNumber
self.mrGbMGetRangeNumber = gearboxMogli.mrGbMGetRangeNumber
self.mrGbMGetRange2Number = gearboxMogli.mrGbMGetRange2Number
self.mrGbMGetHasAllAuto = gearboxMogli.mrGbMGetHasAllAuto
self.mrGbMGetAutoHold = gearboxMogli.mrGbMGetAutoHold
self.mrGbMGetOnlyHandThrottle = gearboxMogli.mrGbMGetOnlyHandThrottle
self.mrGbMGetHydrostaticFactor = gearboxMogli.mrGbMGetHydrostaticFactor
self.mrGbMSetLanuchGear = gearboxMogli.mrGbMSetLanuchGear
self.mrGbMGetEqualizedRpm = gearboxMogli.mrGbMGetEqualizedRpm
self.mrGbMGetFuelUsageRate = gearboxMogli.mrGbMGetFuelUsageRate
self.mrGbMGetDecelerateToLimit = gearboxMogli.mrGbMGetDecelerateToLimit
self.mrGbMGetDiffLockMiddle = gearboxMogli.mrGbMGetDiffLockMiddle
self.mrGbMGetDiffLockFront = gearboxMogli.mrGbMGetDiffLockFront
self.mrGbMGetDiffLockBack = gearboxMogli.mrGbMGetDiffLockBack
self.mrGbMGetModifyDifferentials = gearboxMogli.mrGbMGetModifyDifferentials
--**********************************************************************************************************
self.mrGbML.lastSumDt = 0
self.mrGbML.soundSumDt = 0
self.mrGbML.lastShiftTime = 0
self.mrGbML.autoShiftTime = 0
self.mrGbML.lastGearSpeed = 0
self.mrGbML.warningTimer = 0
self.mrGbML.infoTimer = 0
self.mrGbML.manualClutchTime = 0
self.mrGbML.gearShiftingNeeded = 0
self.mrGbML.gearShiftingTime = 0
self.mrGbML.clutchShiftingTime = 0
self.mrGbML.doubleClutch = 0
self.mrGbML.lastReverse = false
self.mrGbML.dirtyFlag = self:getNextDirtyFlag()
self.mrGbML.wantedAcceleration = 0
self.mrGbML.blowOffVentilTime0 = 0
self.mrGbML.blowOffVentilTime1 = 0
self.mrGbML.blowOffVentilTime2 = -1
self.mrGbML.oneButtonClutchTimer = 0
self.mrGbML.strawDisableTime = 0
self.mrGbML.currentCuttersArea = 0
self.mrGbML.currentRealArea = 0
self.mrGbML.maxRealArea = 0
self.mrGbML.cutterAreaPerSecond = 0
self.mrGbML.realAreaPerSecond = 0
self.mrGbML.updateStreamErrors = 0
self.mrGbML.MotorLoad = 0
self.mrGbML.DirectionChangeTime = 0
self.mrGbML.motorSoundLoadFactor = 0
if gearboxMogli.ovArrowUpWhite == nil then
local w = math.floor(0.012 * g_screenWidth) / g_screenWidth * gearboxMogli.getUiScale()
local h = w * g_screenAspectRatio
local x = g_currentMission.speedMeterIconOverlay.x
local y = g_currentMission.speedMeterIconOverlay.y
x = x + 0.2*w
y = y + g_currentMission.vehicleHudBg.height - h
gearboxMogli.ovArrowUpWhite = Overlay:new("ovArrowUpWhite", Utils.getFilename( self.mrGbMG.ddsDirectory.."arrow_up_white.dds", gearboxMogli.baseDirectory), x, y, w, h)
gearboxMogli.ovArrowUpGray = Overlay:new("ovArrowUpGray", Utils.getFilename( self.mrGbMG.ddsDirectory.."arrow_up_gray.dds", gearboxMogli.baseDirectory), x, y, w, h)
gearboxMogli.ovArrowDownWhite = Overlay:new("ovArrowDownWhite", Utils.getFilename( self.mrGbMG.ddsDirectory.."arrow_down_white.dds", gearboxMogli.baseDirectory), x, y, w, h)
gearboxMogli.ovArrowDownGray = Overlay:new("ovArrowDownGray", Utils.getFilename( self.mrGbMG.ddsDirectory.."arrow_down_gray.dds", gearboxMogli.baseDirectory), x, y, w, h)
gearboxMogli.ovHandBrakeUp = Overlay:new("ovHandBrakeUp", Utils.getFilename( self.mrGbMG.ddsDirectory.."hand_brake_up.dds", gearboxMogli.baseDirectory), x, y, w, h)
gearboxMogli.ovHandBrakeDown = Overlay:new("ovHandBrakeDown", Utils.getFilename( self.mrGbMG.ddsDirectory.."hand_brake_down.dds", gearboxMogli.baseDirectory), x, y, w, h)
x = x + 1.1*w
gearboxMogli.ovDiffLockMiddle = Overlay:new("ovDiffLockMiddle", Utils.getFilename( self.mrGbMG.ddsDirectory.."diff_lock_middle.dds", gearboxMogli.baseDirectory), x, y, w, h)
x = x + 1.1*w
gearboxMogli.ovDiffLockFront = Overlay:new("ovDiffLockFront", Utils.getFilename( self.mrGbMG.ddsDirectory.."diff_lock_front.dds", gearboxMogli.baseDirectory), x, y, w, h)
x = x + 1.1*w
gearboxMogli.ovDiffLockBack = Overlay:new("ovDiffLockBack", Utils.getFilename( self.mrGbMG.ddsDirectory.."diff_lock_back.dds", gearboxMogli.baseDirectory), x, y, w, h)
end
self.mrGbMD.lastTgt = 0
self.mrGbMD.Tgt = 0
self.mrGbMD.lastClutch = 0
self.mrGbMD.Clutch = 0
self.mrGbMD.lastPower = 0
self.mrGbMD.Power = 0
self.mrGbMD.lastRate = 0
self.mrGbMD.Rate = 0
self.mrGbMD.lastHydro = 255
self.mrGbMD.Hydro = 255
self.mrGbMD.lastSlip = 0
self.mrGbMD.Slip = 0
self.mrGbML.lastAcceleration = 0
self.mrGbML.lastBrakePedal = 1
self.mrGbML.fuelUsageRaw = 0
self.mrGbML.fuelUsageRate = 0
self.mrGbML.fuelUsageAvg = 0
self.mrGbML.fuelUsageDt = 0
self.mrGbML.fuelUsageClient = 0
end
--**********************************************************************************************************
-- gearboxMogli:mrGbMGetEqualizedRpm
--**********************************************************************************************************
function gearboxMogli:mrGbMGetEqualizedRpm( r )
--return math.min( self.mrGbMS.OrigMaxRpm, self.mrGbMS.OrigMinRpm + math.max( 0, ( r - self.mrGbMS.IdleRpm ) ) * self.mrGbMS.EqualizedRpmFactor )
if r < self.mrGbMS.IdleRpm then
return self.mrGbMS.OrigMinRpm
end
return self.mrGbMS.OrigMinRpm + ( r - self.mrGbMS.IdleRpm ) * self.mrGbMS.EqualizedRpmFactor
end
--**********************************************************************************************************
-- gearboxMogli:mrGbMGetFuelUsageRate
--**********************************************************************************************************
function gearboxMogli:mrGbMGetFuelUsageRate( getRawValue )
if self.isServer then
if getRawValue then
return self.mrGbML.fuelUsageRaw
end
return self.mrGbML.fuelUsageRate
end
return self.mrGbML.fuelUsageClient
end
function gearboxMogli.getBit3( value, bit )
if value <= 0 then
return 0
elseif value >= 7 then
return 1
elseif bit == 1 then
if value == 1 or value == 3 or value == 5 then
return 1
end
return 0
elseif bit == 2 then
if value == 2 or value == 3 or value == 6 then
return 1
end
return 0
elseif bit == 3 then
if value == 4 or value == 5 or value == 6 then
return 1
end
return 0
end
end
--**********************************************************************************************************
-- gearboxMogli.completeXMLGearboxEntry
--**********************************************************************************************************
function gearboxMogli.completeXMLGearboxEntry( xmlFile, baseName, fixEntry )
local newEntry = fixEntry
newEntry.reverseOnly = getXMLBool( xmlFile, baseName .. "#reverseOnly" )
newEntry.forwardOnly = getXMLBool( xmlFile, baseName .. "#forwardOnly" )
newEntry.minGear = getXMLInt( xmlFile, baseName .. "#minGear" )
newEntry.maxGear = getXMLInt( xmlFile, baseName .. "#maxGear" )
newEntry.minRange = getXMLInt( xmlFile, baseName .. "#minRange" )
newEntry.maxRange = getXMLInt( xmlFile, baseName .. "#maxRange" )
newEntry.minRange2 = getXMLInt( xmlFile, baseName .. "#minRange2" )
newEntry.maxRange2 = getXMLInt( xmlFile, baseName .. "#maxRange2" )
newEntry.upShiftMs = getXMLFloat(xmlFile, baseName .. "#upShiftTimeMs" )
newEntry.downShiftMs = getXMLFloat(xmlFile, baseName .. "#downShiftTimeMs" )
return newEntry
end
--**********************************************************************************************************
-- gearboxMogli:initFromXml
--**********************************************************************************************************
function gearboxMogli:initFromXml(xmlFile,xmlString,xmlMotor,xmlSource,serverAndClient,motorConfig)
--**************************************************************************************************
if xmlSource == "vehicle" then
self.mrGbMG = {}
for n,v in pairs( gearboxMogliGlobals ) do
self.mrGbMG[n] = v
end
self.mrGbMG.playGrindingSound = false
gearboxMogli.globalsLoad2( xmlFile, "vehicle.gearboxMogliGlobals", self.mrGbMG )
self.mrGbMG.hudWidth = Utils.clamp( 16.0 * g_screenHeight * self.mrGbMG.hudWidth / ( 9.0 * g_screenWidth ), 0.05, 0.3 )
if self.mrGbMG.hudWidth + self.mrGbMG.hudPositionX > 1 then
self.mrGbMG.hudPositionX = 1 - self.mrGbMG.hudWidth
end
gearboxMogli.noInputWarning = true
else
if not( gearboxMogli.globalsLoaded ) then
gearboxMogli.globalsLoaded = true
file = gearboxMogli.modsDirectory.."gearboxAddonConfig.xml"
if fileExists(file) then
gearboxMogli.globalsLoad( file, "vehicles.gearboxMogliGlobals", gearboxMogliGlobals, true )
end
gearboxMogliGlobals.hudWidth = Utils.clamp( 16.0 * g_screenHeight * gearboxMogliGlobals.hudWidth / ( 9.0 * g_screenWidth ), 0.05, 0.3 )
if gearboxMogliGlobals.hudWidth + gearboxMogliGlobals.hudPositionX > 1 then
gearboxMogliGlobals.hudPositionX = 1 - gearboxMogliGlobals.hudWidth
end
end
self.mrGbMG = gearboxMogliGlobals
end
--**************************************************************************************************
gearboxMogli.initClient( self )
local excludeList = {}
local default
if not ( serverAndClient ) then
if self.mrGbMS ~= nil then
for n,_ in pairs(self.mrGbMS) do
excludeList[n] = true
end
end
end
--**************************************************************************************************
self.mrGbMS.TransmissionName = getXMLString(xmlFile, xmlString .. "#name" )
self.mrGbMS.ConfigVersion = Utils.getNoNil(getXMLFloat(xmlFile, xmlString .. "#version" ),1.4)
self.mrGbMS.NoDisable = Utils.getNoNil(getXMLBool( xmlFile, xmlString .. "#noDisable" ),self.mrGbMG.noDisable)
self.mrGbMS.showHud = Utils.getNoNil(getXMLBool( xmlFile, xmlString .. "#showHud" ),true)
self.mrGbMS.DrawTargetRpm = Utils.getNoNil(getXMLBool( xmlFile, xmlString .. "#drawTargetRpm" ),self.mrGbMG.drawTargetRpm)
self.mrGbMS.DrawReqPower = Utils.getNoNil(getXMLBool( xmlFile, xmlString .. "#drawTargetRpm" ),self.mrGbMG.drawReqPower)
self.mrGbMS.SwapGearRangeKeys = Utils.getNoNil(getXMLBool( xmlFile, xmlString .. "#swapGearRangeKeys" ),false)
self.mrGbMS.SwapGearRangeKeys0 = self.mrGbMS.SwapGearRangeKeys
self.mrGbMS.TransmissionEfficiency = Utils.getNoNil(getXMLFloat(xmlFile, xmlString .. "#transmissionEfficiency"), gearboxMogliGlobals.transmissionEfficiency)
self.mrGbMS.IdleRpm = math.max( Utils.getNoNil(getXMLFloat(xmlFile, xmlString .. "#idleRpm"), self.motor.minRpm ), self.motor.minRpm )
self.mrGbMS.OrigMinRpm = self.motor.minRpm
self.mrGbMS.OrigMaxRpm = self.motor.maxRpm
self.mrGbMS.OrigRatedRpm = self.mrGbMS.IdleRpm
do
local maxPower = 0
for _,k in pairs(self.motor.torqueCurve.keyframes) do
p = k.time * k.v
if maxPower < p then
maxPower = p
end
if k.v > 0 and p >= 0.9 * maxPower then
self.mrGbMS.OrigRatedRpm = k.time
end
end
end
self.mrGbMS.CurMinRpm = math.max( self.mrGbMS.IdleRpm - gearboxMogli.rpmMinus, 0 )
self.mrGbMS.CurMaxRpm = math.max( self.mrGbMS.OrigRatedRpm + gearboxMogli.rpmPlus, self.mrGbMS.OrigMaxRpm )
self.mrGbMS.EngineHumRpm = math.min( self.motor.maxRpm + gearboxMogli.rpmRatedMinus, self.mrGbMS.CurMaxRpm - 1 )
self.mrGbMS.RatedRpm = math.min( Utils.getNoNil(getXMLFloat(xmlFile, xmlString .. "#ratedRpm"), self.mrGbMS.OrigRatedRpm ), self.motor.maxRpm )
self.mrGbMS.AccelerateToLimit = self.mrGbMG.accelerateToLimit
self.mrGbMS.MinTargetRpm = getXMLFloat(xmlFile, xmlString .. "#minTargetRpm")
self.mrGbMS.MaxTargetRpm = getXMLFloat(xmlFile, xmlString .. "#maxTargetRpm")
self.mrGbMS.IdleEnrichment = Utils.getNoNil(getXMLFloat(xmlFile, xmlString .. "#idleEnrichment"), 0.1 )
default = 0
if self.motor.brakeForce > gearboxMogli.eps then
default = self.mrGbMG.brakeForceRatio / self.motor.brakeForce
end
self.mrGbMS.BrakeForceRatio = Utils.getNoNil(getXMLFloat(xmlFile, xmlString .. "#brakeForceRatio"), default )
self.mrGbMS.FuelPerDistanceMinSpeed = getXMLFloat( xmlFile, xmlString .. "#fuelPerDistanceMinSpeed" )
--**************************************************************************************************
self.mrGbMS.RpmInSpeedHud = getXMLBool( xmlFile, xmlString .. "#rpmInSpeedHud")
self.mrGbMS.MinHudRpm = getXMLFloat(xmlFile, xmlString .. "#minHudRpm")
self.mrGbMS.MaxHudRpm = getXMLFloat(xmlFile, xmlString .. "#maxHudRpm")
--**************************************************************************************************
self.mrGbMS.Engine = {}
self.mrGbMS.Sound = {}
self.mrGbMS.Engine.maxTorque = 0
self.mrGbMS.Engine.maxTorqueRpm = 0
self.mrGbMS.Engine.minRpm = gearboxMogli.huge
self.mrGbMS.Engine.maxRpm = 0
self.mrGbMS.TorqueFactor = 1
local torqueI = 0
local torqueP = 0
local realEngineBaseKey = nil
local baseIdle = 50 * math.floor( 0.5 + 0.02 * math.max( 0.4545 * self.mrGbMS.RatedRpm, self.mrGbMS.IdleRpm ) )
local minTgtDft = 10 * math.floor( 0.5 + 0.10 * ( baseIdle + self.mrGbMG.minTargetRpmFactor * ( self.mrGbMS.RatedRpm - baseIdle ) ) )
if xmlMotor ~= nil then
for i=1,3 do
local key
if i == 1 then
if self.configurations.motor ~= nil then
if motorConfig == nil then
key = string.format(xmlMotor..".engines.engine(%d)", self.configurations.motor-1)
elseif motorConfig[self.configurations.motor] ~= nil then
key = string.format(xmlMotor..".engines.engine(%d)", motorConfig[self.configurations.motor]-1)
end
end
elseif i == 2 then
key = xmlMotor..".engines.engine(0)"
else
key = xmlMotor..".realEngine"
end
if key ~= nil and getXMLFloat(xmlFile, key..".torque(0)#rpm") ~= nil then
realEngineBaseKey = key
break
end
end
else
local key = xmlString..".realEngine"
if key ~= nil and getXMLFloat(xmlFile, key..".torque(0)#rpm") ~= nil then
realEngineBaseKey = key
end
end
if realEngineBaseKey ~= nil then
local s = getXMLString( xmlFile, realEngineBaseKey.."#name" )
if self.configurations.motor ~= nil then
local t = getXMLString( self.xmlFile, string.format("vehicle.motorConfigurations.motorConfiguration(%d)#name",self.configurations.motor-1))
self.mrGbMS.EngineName = t
if t == "$l10n_configuration_valueDefault" or t == "l10n_configuration_valueDefault" then
self.mrGbMS.EngineName = s
if s ~= nil then
--print('FS17_GearboxAddon: Engine name: "'..s..'"')
end
elseif s == nil then
--print('FS17_GearboxAddon: Vehicle motorConfiguration name: "'..t..'"')
elseif s ~= t then
self.mrGbMS.EngineName = s
print('FS17_GearboxAddon: Warning! Engine names to not match: "'..s..'" <> "'..t..'"')
else
--print('FS17_GearboxAddon: Engine and vehicle motorConfiguration name: "'..t..'"')
end
elseif s ~= nil then
self.mrGbMS.EngineName = s
--print('FS17_GearboxAddon: Engine name: "'..s..'"')
end
local d = getXMLString( xmlFile, realEngineBaseKey.."#displayName" )
if d ~= nil then
self.mrGbMS.EngineName = d
end
while true do
local key = string.format(realEngineBaseKey..".torque(%d)", torqueI)
local rpm = getXMLFloat(xmlFile, key.."#rpm")
local torque = getXMLFloat(xmlFile, key.."#motorTorque")
if torque == nil then
torque = getXMLFloat(xmlFile, key.."#ptoTorque")
if torque ~= nil then
torque = torque / self.mrGbMS.TransmissionEfficiency
end
end
if torque == nil or rpm == nil then --or fuelUsageRatio==nil then
break
end
if self.mrGbMS.Engine.torqueValues == nil then
--print("loading motor with new torque curve")
self.mrGbMS.Engine.torqueValues = {}
local tf = self.mrGbMG.torqueFactor
if self.mrIsMrVehicle then
tf = 1
end
self.mrGbMS.TorqueFactor = Utils.getNoNil(getXMLFloat(xmlFile, realEngineBaseKey.."#torqueFactor"), tf) / 1000
end
torque = torque * self.mrGbMS.TorqueFactor
self.mrGbMS.Engine.torqueValues[torqueI+1] = {v=torque, time = rpm}
if torque>self.mrGbMS.Engine.maxTorque + gearboxMogli.eps then
self.mrGbMS.Engine.maxTorqueRpm = rpm
end
if torque>self.mrGbMS.Engine.maxTorque then
self.mrGbMS.Engine.maxTorque = torque
end
local ecoTorque = getXMLFloat(xmlFile, key.."#motorTorqueEco")
if ecoTorque == nil then
ecoTorque = getXMLFloat(xmlFile, key.."#ptoTorqueEco")
if ecoTorque ~= nil then
ecoTorque = ecoTorque / self.mrGbMS.TransmissionEfficiency
end
end
if ecoTorque ~= nil
and ( ecoTorque > 0 or self.mrGbMS.Engine.ecoTorqueValues ~= nil ) then
ecoTorque = ecoTorque * self.mrGbMS.TorqueFactor
if self.mrGbMS.Engine.ecoTorqueValues == nil then
self.mrGbMS.Engine.ecoTorqueValues = {}
end
table.insert( self.mrGbMS.Engine.ecoTorqueValues, {v=ecoTorque, time = rpm} )
end
local fuelUsageRatio = getXMLFloat(xmlFile, key.."#fuelUsageRatio")
if fuelUsageRatio ~= nil and fuelUsageRatio > 0 then
if self.mrGbMS.Engine.fuelUsageValues == nil then
self.mrGbMS.Engine.fuelUsageValues = {}
end
table.insert( self.mrGbMS.Engine.fuelUsageValues, {v=fuelUsageRatio, time = rpm} )
end
if self.mrGbMS.Engine.maxRpm < rpm
and ( torque > 0 or torqueP > 0 ) then
self.mrGbMS.Engine.maxRpm = rpm
end
if self.mrGbMS.Engine.minRpm > rpm
and torque > 0 then
self.mrGbMS.Engine.minRpm = rpm
end
torqueI = torqueI + 1
torqueP = torque
end
if torqueI > 0 then
self.mrGbMS.IdleRpm = Utils.getNoNil(getXMLFloat(xmlFile, realEngineBaseKey.."#idleRpm"), 800)
self.mrGbMS.RatedRpm = Utils.getNoNil(getXMLFloat(xmlFile, realEngineBaseKey.."#ratedRpm"), 2100)
self.mrGbMS.CurMinRpm = Utils.getNoNil(getXMLFloat(xmlFile, realEngineBaseKey.."#minRpm"), math.max( self.mrGbMS.IdleRpm - gearboxMogli.rpmMinus, self.mrGbMS.Engine.minRpm ))
self.mrGbMS.CurMaxRpm = self.mrGbMS.Engine.maxRpm + gearboxMogli.rpmPlus
self.mrGbMS.EngineHumRpm = self.mrGbMS.Engine.maxRpm
if self.mrGbMS.MinTargetRpm == nil then
self.mrGbMS.MinTargetRpm = math.max( self.mrGbMS.Engine.maxTorqueRpm * gearboxMogli.rpmReduction, minTgtDft )
end
local m = getXMLFloat(xmlFile, realEngineBaseKey.."#maxRpm")
if m ~= nil then
self.mrGbMS.MaxTargetRpm = m
elseif self.mrGbMS.MaxTargetRpm == nil then
self.mrGbMS.MaxTargetRpm = 0.5 * ( self.mrGbMS.RatedRpm + math.max(self.mrGbMS.RatedRpm, self.mrGbMS.Engine.maxRpm ) )
end
baseIdle = math.max( 0.475 * self.mrGbMS.RatedRpm, self.mrGbMS.IdleRpm )
end
self.mrGbMS.BoostMinSpeed = Utils.getNoNil( getXMLFloat(xmlFile, realEngineBaseKey.."#boostMinSpeed"), 30 ) / 3.6
end
self.mrGbMS.ConfigId = self.configurations.GearboxAddon
self.mrGbMS.BoughtIds = {}
if self.boughtConfigurations ~= nil and type( self.boughtConfigurations.GearboxAddon ) == "table" then
for id,b in pairs(self.boughtConfigurations.GearboxAddon) do
if b then
table.insert( self.mrGbMS.BoughtIds, id )
end
end
end
if self.mrGbMS.TransmissionName ~= nil then
if self.mrGbMS.EngineName == nil then
self.mrGbMS.EngineName = self.mrGbMS.TransmissionName
else
self.mrGbMS.EngineName = self.mrGbMS.EngineName.." "..self.mrGbMS.TransmissionName
end
end
if self.mrGbMS.MinTargetRpm == nil then
self.mrGbMS.MinTargetRpm = minTgtDft
end
if self.mrGbMS.MaxTargetRpm == nil then
self.mrGbMS.MaxTargetRpm = 0.5 * ( self.mrGbMS.RatedRpm + math.max( self.mrGbMS.RatedRpm, self.mrGbMS.EngineHumRpm ) )
elseif self.mrGbMS.MaxTargetRpm < self.mrGbMS.RatedRpm then
if self.mrGbMS.Engine.torqueValues == nil then
print('FS17_GearboxAddon: Warning! engine maxRpm < engine ratedRpm')
else
print('FS17_GearboxAddon: Warning! maxTargetRpm ratedRpm')
end
self.mrGbMS.MaxTargetRpm = self.mrGbMS.RatedRpm
end
self.mrGbMS.MaxTargetRpmRatio = self.mrGbMS.MaxTargetRpm / self.mrGbMS.RatedRpm
if self.mrGbMS.Engine.fuelUsageValues == nil then
local fuelUsageRatio = getXMLFloat(xmlFile, xmlString.."#minFuelUsageRatio")
if fuelUsageRatio == nil then
self.mrGbMS.GlobalFuelUsageRatio = Utils.getNoNil( getXMLFloat(xmlFile, xmlString.."#fuelUsageRatio"), 230 )
else
self.mrGbMS.GlobalFuelUsageRatio = fuelUsageRatio / 0.9
end
end
local maxTorque = 0
if torqueI > 0 then
maxTorque = self.mrGbMS.Engine.maxTorque
else
maxTorque = self.motor.torqueCurve:getMaximum()
end
local function getRpm( f )
return baseIdle + Utils.clamp( f, 0, 1 ) * math.max( 0, self.mrGbMS.MaxTargetRpm - baseIdle )
end
self.mrGbMS.Sound.MaxRpm = getXMLFloat(xmlFile, xmlString .. "#soundMaxRpm")
if self.mrGbMS.Sound.MaxRpm == nil then
self.mrGbMS.Sound.MaxRpm = self.mrGbMS.OrigRatedRpm
end
self.mrGbMS.HydraulicRpm = Utils.getNoNil(getXMLFloat(xmlFile, xmlString .. "#hydraulicRpm"),
10 * math.floor( 0.5 + 0.10 * getRpm( self.mrGbMG.hydroRpmFactor ) ) )
--**************************************************************************************************
-- PTO RPM
--**************************************************************************************************
self.mrGbMS.PtoRpm = Utils.getNoNil( getXMLFloat(xmlFile, xmlString .. "#ptoRpm"),
50 * math.floor( 0.5 + 0.02 * getRpm( self.mrGbMG.ptoRpmFactor ) ) )
self.mrGbMS.PtoRpmEco = Utils.getNoNil( getXMLFloat(xmlFile, xmlString .. "#ptoRpmEco"),
50 * math.floor( 0.5 + 0.02 * getRpm( self.mrGbMG.ptoRpmFactorEco ) ) )
if self.mrGbMS.PtoRpmEco > self.mrGbMS.PtoRpm then
self.mrGbMS.PtoRpmEco = self.mrGbMS.PtoRpm
end
local maxPtoTorqueRatio = 0.5
local maxPtoTorqueSpeed = 10
self.mrGbMS.OnlyHandThrottle = Utils.getNoNil(getXMLBool( xmlFile, xmlString .. "#onlyHandThrottle" ), false)
self.mrGbMS.MinHandThrottle = Utils.getNoNil(getXMLFloat(xmlFile, xmlString .. "#minHandThrottle" ), 0.5)
self.mrGbMS.PtoSpeedLimit = Utils.getNoNil(getXMLBool( xmlFile, xmlString .. "#ptoSpeedLimit"), self.mrGbMG.ptoSpeedLimit )
--**************************************************************************************************
-- combine
--**************************************************************************************************
if SpecializationUtil.hasSpecialization(Combine, self.specializations) then
self.mrGbMS.IsCombine = true
local width = getXMLFloat(xmlFile, xmlString .. ".combine#defaultWidth")
local speed = Utils.getNoNil( getXMLFloat(xmlFile, xmlString .. ".combine#defaultSpeed"), self.mrGbMG.combineDefaultSpeed )
maxPtoTorqueSpeed = math.min( maxPtoTorqueSpeed, speed )
local f = gearboxMogli.powerFactorPI * 7 / speed
local du0, dc0, dci, dp0, dpi = 0, 0, 0, 0, 0
local storeItem = StoreItemsUtil.storeItemsByXMLFilename[self.configFileName:lower()]
if storeItem ~= nil and storeItem.category == "forageHarvesters" then
dp0 = 30 * maxTorque
dpi = 9.200
else
dp0 = 50 * maxTorque
dc0 = 3.2* maxTorque
dpi = 6
dci = 0.383
end
if width ~= nil then
local defaultFruit = getXMLString(xmlFile, xmlString .. ".combine#defaultFruit")
local defaultLiterPerSqm = self.mrGbMG.defaultLiterPerSqm
if defaultFruit == nil and storeItem ~= nil and storeItem.category == "forageHarvesters" then
defaultFruit = "chaff"
end
if defaultFruit == nil
or defaultFruit == "wheat" then
defaultLiterPerSqm = 1.2
elseif defaultFruit == "barley" then
defaultLiterPerSqm = 1.1
elseif defaultFruit == "rape" then
defaultLiterPerSqm = 0.6
elseif defaultFruit == "maize" then
defaultLiterPerSqm = 1.2
elseif defaultFruit == "potato" then
defaultLiterPerSqm = 4
elseif defaultFruit == "sugarBeet" then
defaultLiterPerSqm = 3.5
elseif defaultFruit == "grass" then
defaultLiterPerSqm = 1.2
elseif defaultFruit == "dryGrass" then
defaultLiterPerSqm = 1.2
elseif defaultFruit == "chaff" then
defaultLiterPerSqm = 3.9
else
print('FS17_GearboxAddon: Warning! Unknown fruit type: "'..tostring(defaultFruit)..'"' )
end
defaultLiterPerSqm = defaultLiterPerSqm * self.mrGbMG.defaultLiterPerSqm / 1.2
local factor = Utils.getNoNil( getXMLFloat(xmlFile, xmlString .. ".combine#defaultLiterPerSqm"), defaultLiterPerSqm )
local dynamicRatio = getXMLFloat(xmlFile, xmlString .. ".combine#dynamicRatio")
if defaultFruit == "chaff"
or ( defaultFruit == nil and defaultLiterPerSqm > 3 ) then
if dynamicRatio == nil then
dynamicRatio = self.mrGbMG.combineDynamicChopper
end
du0 = 0
dc0 = 0
dci = 0
dp0 = width * 60 * ( 1 - dynamicRatio )
dpi = 11.5 * dynamicRatio
else
if dynamicRatio == nil then
dynamicRatio = self.mrGbMG.combineDynamicRatio
end
du0 = 6 + width
dp0 = width * 25 * ( 1 - dynamicRatio )
dpi = 10 * dynamicRatio
dc0 = dp0 * 0.06/0.94
dci = dpi * 0.06/0.94
end
end