@@ -39,10 +39,13 @@ function keyboardSteerMogli.globalsReset( createIfMissing )
3939 KSMGlobals .speedFxInc = 0
4040 KSMGlobals .axisForwardSmooth = 0
4141 KSMGlobals .enableAnalogCtrl = false
42+ KSMGlobals .axisForwardGearbox = false
43+ KSMGlobals .debugPrint = false
4244
4345-- defaults
4446 KSMGlobals .ksmSteeringIsOn = false
4547 KSMGlobals .ksmCameraIsOn = false
48+ KSMGlobals .ksmCamInsideIsOn = false
4649 KSMGlobals .ksmDrawIsOn = false
4750 KSMGlobals .ksmReverseIsOn = false
4851
9396
9497keyboardSteerMogli .globalsReset (false )
9598
99+ function keyboardSteerMogli .debugPrint ( ... )
100+ if KSMGlobals .debugPrint then
101+ print ( ... )
102+ end
103+ end
104+
96105function keyboardSteerMogli :isValidCam ( index , createIfMissing )
97106 local i = Utils .getNoNil ( index , self .camIndex )
98107
@@ -103,8 +112,8 @@ function keyboardSteerMogli:isValidCam( index, createIfMissing )
103112 and self .cameras [i ].isRotatable then
104113 if self .ksmCameras [i ] == nil then
105114 if createIfMissing then
106- self .ksmCameras [i ] = { rotation = KSMGlobals . ksmCameraIsOn ,
107- rev = KSMGlobals . ksmReverseIsOn ,
115+ self .ksmCameras [i ] = { rotation = keyboardSteerMogli . getDefaultRotation ( self , i ) ,
116+ rev = keyboardSteerMogli . getDefaultReverse ( self , i ) ,
108117 zero = self .cameras [i ].rotY ,
109118 last = self .cameras [i ].rotY ,
110119 smooth = self .cameras [i ].rotY }
121130function keyboardSteerMogli :load (xmlFile )
122131 self .ksmScaleFx = keyboardSteerMogli .scaleFx
123132 self .ksmSetState = keyboardSteerMogli .mbSetState
133+ self .ksmIsValidCam = keyboardSteerMogli .isValidCam
124134
125135 keyboardSteerMogli .registerState ( self , " ksmSteeringIsOn" , false )
126136 keyboardSteerMogli .registerState ( self , " ksmAnalogIsOn" , false )
@@ -148,32 +158,20 @@ function keyboardSteerMogli:load(xmlFile)
148158 self .ksmDirChangeTimer = 0
149159 self .ksmChangeDir = false
150160 self .ksmAddMirror = true
151- -- if g_settingsRearMirrors and g_rearMirrorsAvailable then
152- -- self.ksmAddMirror = false
153- -- else
154- self .mirrorAvailable = self .ksmMirror
155- -- end
156-
157- -- self:ksmSetState( "ksmSteeringIsOn", KSMGlobals.ksmSteeringIsOn,true )
161+ self .mirrorAvailable = self .ksmMirror
162+
158163 if KSMGlobals .ksmSteeringIsOn then
159164 self :ksmSetState ( " ksmSteeringIsOn" , true , true )
160165 end
161166 if KSMGlobals .enableAnalogCtrl then
162167 self :ksmSetState ( " ksmAnalogIsOn" , true , true )
163168 end
164169
165- self .ksmCameras = {}
170+ self .ksmCameras = {}
166171
167172 for i ,c in pairs (self .cameras ) do
168- if keyboardSteerMogli .isValidCam ( self , i , true ) then
169- if c .isInside and SpecializationUtil .hasSpecialization (Combine , self .specializations ) then
170- self .ksmCameras [i ].rev = false
171- end
172- end
173- end
174-
175- self .ksmCameraDefaultOn = KSMGlobals .ksmCameraIsOn
176- self .ksmReverseDefaultOn = KSMGlobals .ksmReverseIsOn
173+ self :ksmIsValidCam ( i , true )
174+ end
177175end
178176
179177function keyboardSteerMogli :update (dt )
@@ -216,7 +214,7 @@ function keyboardSteerMogli:update(dt)
216214 end
217215
218216 if newRot ~= nil
219- and keyboardSteerMogli . isValidCam ( self ) then
217+ and self : ksmIsValidCam ( ) then
220218 local diff = self .cameras [self .camIndex ].rotY - self .ksmCameras [self .camIndex ].last
221219 self .cameras [self .camIndex ].rotY = keyboardSteerMogli .normalizeAngle ( self .cameras [self .camIndex ].origRotY + newRot )
222220 if self .ksmCameraIsOn then
@@ -299,7 +297,7 @@ function keyboardSteerMogli:update(dt)
299297 if self :getIsActive ()
300298 and self .steeringEnabled
301299 and self .ksmCameraIsOn
302- and keyboardSteerMogli . isValidCam ( self ) then
300+ and self : ksmIsValidCam ( ) then
303301
304302 local diff = self .cameras [self .camIndex ].rotY - self .ksmCameras [self .camIndex ].last
305303 self .ksmCameras [self .camIndex ].zero = self .ksmCameras [self .camIndex ].zero + diff
@@ -401,7 +399,7 @@ function keyboardSteerMogli:draw()
401399 g_currentMission :addHelpButtonText (keyboardSteerMogli .getText (" ksmANALOG_OFF" ), InputBinding .ksmANALOG )
402400 end
403401
404- if keyboardSteerMogli . isValidCam ( self ) then
402+ if self : ksmIsValidCam ( ) then
405403 if self .ksmCameraIsOn then
406404 g_currentMission :addHelpButtonText (keyboardSteerMogli .getText (" ksmCAMERA_ON" ), InputBinding .ksmCAMERA )
407405 else
@@ -418,15 +416,53 @@ function keyboardSteerMogli:draw()
418416 g_currentMission :addExtraPrintText ( self .ksmWarningText )
419417 end
420418end
421-
419+
420+ function keyboardSteerMogli :getDefaultRotation ( camIndex )
421+ if self .cameras == nil
422+ or self .cameras [camIndex ] == nil then
423+ keyboardSteerMogli .debugPrint ( " invalid camera" )
424+ return false
425+ elseif not ( self .cameras [camIndex ].isRotatable )
426+ or self .cameras [camIndex ].vehicle ~= self then
427+ keyboardSteerMogli .debugPrint ( " fixed camera" )
428+ return false
429+ elseif KSMGlobals .ksmCamInsideIsOn
430+ and self .cameras [camIndex ].isInside then
431+ keyboardSteerMogli .debugPrint ( " camera is inside" )
432+ return true
433+ end
434+ keyboardSteerMogli .debugPrint ( " other camera: " .. tostring (KSMGlobals .ksmCameraIsOn ) )
435+ return KSMGlobals .ksmCameraIsOn
436+ end
437+
438+ function keyboardSteerMogli :getDefaultReverse ( camIndex )
439+ if self .cameras == nil
440+ or self .cameras [camIndex ] == nil then
441+ return false
442+ elseif not ( self .cameras [camIndex ].isRotatable )
443+ or self .cameras [camIndex ].vehicle ~= self then
444+ return false
445+ elseif self .cameras [camIndex ].isInside
446+ and SpecializationUtil .hasSpecialization (Combine , self .specializations ) then
447+ return false
448+ end
449+
450+ if self .attacherJoints ~= nil then
451+ for _ ,a in pairs ( self .attacherJoints ) do
452+ if a .jointType == JOINTTYPE_SEMITRAILER then
453+ return false
454+ end
455+ end
456+ end
457+
458+ return KSMGlobals .ksmReverseIsOn
459+ end
460+
422461function keyboardSteerMogli :getSaveAttributesAndNodes (nodeIdent )
423462 local attributes = " "
424463 if self .ksmSteeringIsOn ~= nil and self .ksmSteeringIsOn ~= KSMGlobals .ksmSteeringIsOn then
425464 attributes = attributes .. " ksmSteeringIsOn=\" " .. tostring (self .ksmSteeringIsOn ) .. " \" "
426465 end
427- if self .ksmCameraDefaultOn ~= nil and self .ksmCameraDefaultOn ~= KSMGlobals .ksmCameraIsOn then
428- attributes = attributes .. " ksmCameraIsOn=\" " .. tostring (self .ksmCameraDefaultOn ) .. " \" "
429- end
430466 if self .ksmAnalogIsOn ~= nil and self .ksmAnalogIsOn ~= KSMGlobals .enableAnalogCtrl then
431467 attributes = attributes .. " ksmAnalogIsOn=\" " .. tostring (self .ksmAnalogIsOn ) .. " \" "
432468 end
@@ -435,10 +471,10 @@ function keyboardSteerMogli:getSaveAttributesAndNodes(nodeIdent)
435471 end
436472
437473 for i ,b in pairs (self .ksmCameras ) do
438- if b .rotation ~= self . ksmCameraDefaultOn then
474+ if b .rotation ~= keyboardSteerMogli . getDefaultRotation ( self , i ) then
439475 attributes = attributes .. " ksmCameraIsOn_" .. tostring (i ).. " =\" " .. tostring (b .rotation ) .. " \" "
440476 end
441- if b .rev ~= self . ksmReverseDefaultOn then
477+ if b .rev ~= keyboardSteerMogli . getDefaultReverse ( self , i ) then
442478 attributes = attributes .. " ksmReverseIsOn_" .. tostring (i ).. " =\" " .. tostring (b .rev ) .. " \" "
443479 end
444480 end
@@ -454,10 +490,6 @@ function keyboardSteerMogli:loadFromAttributesAndNodes(xmlFile, key, resetVehicl
454490 if b ~= nil then
455491 self :ksmSetState ( " ksmSteeringIsOn" , b , true )
456492 end
457- b = getXMLBool (xmlFile , key .. " #ksmCameraIsOn" )
458- if b ~= nil then
459- self .ksmCameraDefaultOn = b
460- end
461493 b = getXMLBool (xmlFile , key .. " #ksmAnalogIsOn" )
462494 if b ~= nil then
463495 self .ksmAnalogIsOn = b
@@ -472,18 +504,23 @@ function keyboardSteerMogli:loadFromAttributesAndNodes(xmlFile, key, resetVehicl
472504 end
473505
474506 for i ,c in pairs (self .cameras ) do
475- if keyboardSteerMogli .isValidCam ( self , i , true ) then
476- local b1 = Utils .getNoNil ( getXMLBool (xmlFile , key .. " #ksmCameraIsOn_" .. tostring (i ) ), self .ksmCameraDefaultOn )
477- local b2 = Utils .getNoNil ( getXMLBool (xmlFile , key .. " #ksmReverseIsOn_" .. tostring (i ) ), self .ksmReverseDefaultOn )
478- self .ksmCameras [i ].rotation = b1
479- self .ksmCameras [i ].rev = b2
507+ if self :ksmIsValidCam ( i , true ) then
508+ b = getXMLBool (xmlFile , key .. " #ksmCameraIsOn_" .. tostring (i ) )
509+ if b ~= nil then
510+ self .ksmCameras [i ].rotation = b
511+ end
512+ b = getXMLBool (xmlFile , key .. " #ksmReverseIsOn_" .. tostring (i ) )
513+ if b ~= nil then
514+ self .ksmCameras [i ].rev = b
515+ end
480516 end
481517 end
482518
483519 local i = getXMLInt (xmlFile , key .. " #ksmExponent" )
484520 if i ~= nil then
485521 self :ksmSetState ( " ksmExponent" , i , true )
486522 end
523+
487524 return BaseMission .VEHICLE_LOAD_OK ;
488525end
489526
@@ -562,11 +599,12 @@ function keyboardSteerMogli:newUpdateVehiclePhysics( superFunc, axisForward, axi
562599 end
563600
564601 self .ksmLastAxisFwd = math.min ( axisForward , self .ksmLastAxisFwd + self .ksmWandtedMovingDir * KSMGlobals .axisForwardSmooth * dt )
565- elseif self .ksmSteeringIsOn
602+ elseif KSMGlobals .axisForwardGearbox
603+ and self .ksmSteeringIsOn
566604 and ( self .ksmAnalogIsOn or not ( axisForwardIsAnalog ) )
567605 and self .mrGbMS ~= nil
568606 and self .mrGbMS .IsOn then
569-
607+
570608 if self .ksmLShiftPressed then
571609 axisForward = Utils .clamp ( axisForward , - 0.75 , 0.75 )
572610 axisForwardIsAnalog = true
@@ -593,11 +631,11 @@ end
593631function keyboardSteerMogli :ksmOnSetCamera ( old , new , noEventSend )
594632 self .ksmCameraIsOn = new
595633 if self .ksmLastCamIndex ~= nil
596- and keyboardSteerMogli . isValidCam ( self , self .ksmLastCamIndex ) then
634+ and self : ksmIsValidCam ( self .ksmLastCamIndex ) then
597635 self .ksmCameras [self .ksmLastCamIndex ].rotation = new
598636 end
599637 for i ,c in pairs (self .cameras ) do
600- if keyboardSteerMogli . isValidCam ( self , i ) then
638+ if self : ksmIsValidCam ( i ) then
601639 self .ksmCameras [i ].zero = c .rotY
602640 self .ksmCameras [i ].last = c .rotY
603641 self .ksmCameras [i ].smooth = c .rotY
608646function keyboardSteerMogli :ksmOnSetReverse ( old , new , noEventSend )
609647 self .ksmReverseIsOn = new
610648 if self .ksmLastCamIndex ~= nil
611- and keyboardSteerMogli . isValidCam ( self , self .ksmLastCamIndex ) then
649+ and self : ksmIsValidCam ( self .ksmLastCamIndex ) then
612650 self .ksmCameras [self .ksmLastCamIndex ].rev = new
613651 end
614652end
@@ -625,10 +663,10 @@ function keyboardSteerMogli:ksmSetCameraFwd( camFwd )
625663 if self .steeringEnabled
626664 and camFwd ~= nil
627665 and self .ksmLastCamIndex ~= nil
628- and keyboardSteerMogli . isValidCam ( self , self .ksmLastCamIndex ) then
666+ and self : ksmIsValidCam ( self .ksmLastCamIndex ) then
629667 local pi2 = math.pi / 2
630668 local i = self .ksmLastCamIndex
631- local rev = self . ksmReverseDefaultOn
669+ local rev = KSMGlobals . ksmReverseIsOn
632670 if self .ksmCameras [i ] ~= nil then
633671 rev = self .ksmCameras [i ].rev
634672 end
@@ -672,7 +710,7 @@ function keyboardSteerMogli:ksmOnSetCamIndex( old, new, noEventSend )
672710 self .ksmLastCamIndex = new
673711 if self .cameras ~= nil
674712 and new ~= nil
675- and keyboardSteerMogli . isValidCam ( self , new , true ) then
713+ and self : ksmIsValidCam ( new , true ) then
676714 keyboardSteerMogli .ksmSetCameraFwd ( self , self .ksmCamFwd )
677715 if self .ksmCameras [new ].rotation ~= self .ksmCameraIsOn then
678716 self :ksmSetState ( " ksmCameraIsOn" , self .ksmCameras [new ].rotation , true )
0 commit comments