------------------------------------------------------------ -- Simulation file for the JF ------------------------------------------------------------ ------------------------------------------------------------ -- Setup ------------------------------------------------------------ -- Called when the engine script is initialised ------------------------------------------------------------ function Setup () SG_STATE_STOPPED = 0 SG_STATE_FORWARD = 1 SG_STATE_BACKWARD = 2 mStopGoState = SG_STATE_STOPPED gPrevFireBoxDoorValue = -1 -- Forces 1st frame update gPrevReverserValue = 0 gPrevRegulatorValue = 0 gPrevHornValue = 0 end ------------------------------------------------------------ -- Update ------------------------------------------------------------ -- Called every frame to update the simulation ------------------------------------------------------------ -- Parameters: -- interval = time since last update ------------------------------------------------------------ function Update (interval) local fbValue = 0; local sgValue = 0; local zero = 0 if Call( "*:ControlExists", "Firebox door", 0 ) ~= zero then fbValue = Call( "*:GetControlValue", "Firebox door", 0 ); Call( "*:SetEmitterColour", fbValue, fbValue, fbValue ); if fbValue ~= gPrevFireBoxDoorValue then Call( "ControlSound:SetParameter", "FireBoxDoorValue", fbValue ) gPrevFireBoxDoorValue = fbValue end end -- Stop go controls... if Call( "*:ControlExists", "StopGoForward", 0 ) ~= zero then sgValue = Call( "*:GetControlValue", "StopGoForward", 0 ); if sgValue > zero then mStopGoState = SG_STATE_FORWARD elseif sgValue < zero then mStopGoState = SG_STATE_BACKWARD end end if Call( "*:ControlExists", "StopGoStop", 0 ) ~= zero then sgValue = Call( "*:GetControlValue", "StopGoStop", 0 ); if sgValue ~= zero then Call( "*:SetControlValue", "StopGoForward", zero, zero ); mStopGoState = SG_STATE_STOP end end Call("SetFailureValue", "ElectricSim", "ForceMultiplierDueToFailure", 0.5) local controlValue = 0; -- Reverser if Call( "*:ControlExists", "Reverser", 0 ) ~= zero then controlValue = Call( "*:GetControlValue", "Reverser", 0 ) if controlValue ~= gPrevReverserValue then Call( "*:SetEngineValue", "Reverser", controlValue ) gPrevReverserValue = controlValue; end end -- Regulator if Call( "*:ControlExists", "Regulator", 0 ) ~= zero then controlValue = Call( "*:GetControlValue", "Regulator", 0 ) if controlValue ~= gPrevRegulatorValue then Call( "*:SetEngineValue", "Regulator", controlValue ) gPrevRegulatorValue = controlValue end end -- Horn if Call( "*:ControlExists", "Horn", 0 ) ~= zero then controlValue = Call( "*:GetControlValue", "Horn", 0 ) if controlValue ~= gPrevHornValue then --Call( "*:SetEngineValue", "Horn", controlValue ) Call( "ControlSound:SetParameter", "HornValue", controlValue ) gPrevHornValue = controlValue end end end function GetStopGoState() return mStopGoState end