-- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
-- If a copy of the bCDDL was not distributed with this
-- file, You can obtain one at http://beamng.com/bCDDL-1.1.txt
local M = {}


local ASGtimer = 0
local sirenState = 0
local Siren1 = nil
local Siren2 = nil
local Siren3 = nil
local savestate = 0
local function onInit()
  Siren1 = Siren1 or sounds.createSoundscapeSound("Siren1")
  Siren2 = Siren2 or sounds.createSoundscapeSound("Siren2")
  Siren3 = Siren3 or sounds.createSoundscapeSound("Siren3")
  Hell = Hell or sounds.createSoundscapeSound("Hell")
  Hell2 = Hell2 or sounds.createSoundscapeSound("Hell")
  Hellmuffled = Hellmuffled or sounds.createSoundscapeSound("Hellmuffled")
end
	

local function reset()
sirenState = 0
end
local function toggleSound(val, snd)
  if not snd then
    return
  end
  if val then
    obj:setVolume(snd, 1)
    obj:cutSFX(snd)
    obj:playSFX(snd)
  else
    obj:stopSFX(snd)
  end
end



local function updateGFX(dt)
 obj:queueGameEngineLua("be:getPlayerVehicle(0):queueLuaCommand('cameraMode = (\"'..core_camera.getActiveCamName(0)..'\")')")
	camMode = tostring(cameraMode)
-- print(cameraMode)
		if Hell == nil then
		else
		obj:playSFX(Hellmuffled)
		obj:playSFX(Hell)
		--obj:playSFX(Hell2)
		if camMode == "hood" or camMode == "driver" then

		obj:setVolume(Hellmuffled, 0)
		obj:setVolume(Hell, 15)
		--obj:setVolume(Hell2, 15)
		else
			obj:setVolume(Hell, 0)
			--obj:setVolume(Hell2, 0)
			obj:setVolume(Hellmuffled, 3)
	end
	end

 
	if electrics.values.sirentoggle == 1 then
	sirenState = sirenState + 1
	electrics.values.sirentoggle = 0
	end
	
	if electrics.values.sirentoggle == -1 then
	sirenState = sirenState - 1
	electrics.values.sirentoggle = 0
	end
	
	if sirenState > 3 then
	sirenState = 0
	end

	if sirenState < 0 then
	sirenState = 3
	end
	
	
if Siren1 == nil then
else
	if sirenState == 1 then
		obj:setVolume(Siren1, 5)
		obj:playSFX(Siren1)
	else
		obj:setVolume(Siren1, 0)
		obj:stopSFX(Siren1)
	end
end
if Siren2 == nil then
else

	if sirenState == 2 then
		obj:setVolume(Siren2, 5)
		obj:playSFX(Siren2)
	else
		obj:setVolume(Siren2, 0)
		obj:stopSFX(Siren2)
	end
end
if Siren3 == nil then
else
	if sirenState == 3 then
		obj:setVolume(Siren3, 5)
		obj:playSFX(Siren3)
	else
		obj:setVolume(Siren3, 0)
		obj:stopSFX(Siren3)
	end

end
	
end








		
	

-- public interface
M.onInit    = onInit
M.onReset   = reset
M.updateGFX = updateGFX

return M