--
-- MotorSound.lua
--
-- @author  MRA-Modding(Alex2009)
-- @website www.alex2009.de, www.mra-modding.de
-- @date    30.11.2011
--
--Modifikation erst nach rücksprache mit dem Autor(Alex2009) erlaubt.
--Modification allowed only after consultation with the author(Alex2009).

MotorSound = {};

function MotorSound.prerequisitesPresent(specializations)
    return true;
end;

function MotorSound:load(xmlFile)
end;

function MotorSound:delete()
end;

function MotorSound:mouseEvent(posX, posY, isDown, isUp, button)
end;

function MotorSound:keyEvent(unicode, sym, modifier, isDown)
end;

function MotorSound:update(dt)
    if self.isMotorStarted and self:getIsActiveForSound() then
        if (self.camIndex == 2) then
            if self.interactiveObjects[1].isOpen then
                if getSampleVolume(self.motorSound) ~= 0.15 then
                    setSampleVolume(self.motorSound,0.15);
                end;
                if getSampleVolume(self.motorSoundRun) ~= 0.15 then
                    setSampleVolume(self.motorSoundRun,0.15);
                end;
                if getSampleVolume(self.threshingStartSound) ~= 0.15 then
                    setSampleVolume(self.threshingStartSound,0.15);
                end;
                if getSampleVolume(self.threshingSound) ~= 0.15 then                
                    setSampleVolume(self.threshingSound,0.15);
                end;
                if getSampleVolume(self.threshingStopSound) ~= 0.15 then
                    setSampleVolume(self.threshingStopSound,0.15);
                end;
                if getSampleVolume(self.pipeSound ) ~= 0.15 then
                    setSampleVolume(self.pipeSound ,0.15);
                end;
                if getSampleVolume(self.attachSound ) ~= 0.15 then
                    setSampleVolume(self.attachSound ,0.15);
                end;
                if getSampleVolume(self.motorStartSound) ~= 0.15 then
                    setSampleVolume(self.motorStartSound,0.15);
                end;
                if getSampleVolume(self.motorStopSound) ~= 0.15 then
                    setSampleVolume(self.motorStopSound,0.15);
                end;
                if getSampleVolume(self.reverseDriveSound) ~= 0.15 then
                    setSampleVolume(self.reverseDriveSound,0.15);
                end;
                if getSampleVolume(self.compressedAirSound) ~= 0.15 then
                    setSampleVolume(self.compressedAirSound,0.15);
                end;
                if getSampleVolume(self.compressionSound) ~= 0.15 then
                    setSampleVolume(self.compressionSound,0.15);
                end;
            elseif (self.motorSoundVolume ~= 0.5 or self.motorSoundRunVolume ~= 0.5) and not self.interactiveObjects[1].isOpen then
                if getSampleVolume(self.motorSound) ~= 0.5 then
                    setSampleVolume(self.motorSound,0.5);
                end;
                if getSampleVolume(self.motorSoundRun) ~= 0.5 then
                    setSampleVolume(self.motorSoundRun,0.5);
                end;
                if getSampleVolume(self.threshingStartSound) ~= 0.5 then
                    setSampleVolume(self.threshingStartSound,0.5);
                end;
                if getSampleVolume(self.threshingSound) ~= 0.5 then                
                    setSampleVolume(self.threshingSound,0.5);
                end;
                if getSampleVolume(self.threshingStopSound) ~= 0.5 then
                    setSampleVolume(self.threshingStopSound,0.5);
                end;
                if getSampleVolume(self.pipeSound) ~= 0.5 then
                    setSampleVolume(self.pipeSound,0.5);
                end;
                if getSampleVolume(self.attachSound) ~= 0.5 then
                    setSampleVolume(self.attachSound,0.5);
                end;
                if getSampleVolume(self.motorStartSound) ~= 0.5 then
                    setSampleVolume(self.motorStartSound,0.5);
                end;
                if getSampleVolume(self.motorStopSound) ~= 0.5 then
                    setSampleVolume(self.motorStopSound,0.5);
                end;
                if getSampleVolume(self.reverseDriveSound) ~= 0.25 then
                    setSampleVolume(self.reverseDriveSound,0.25);
                end;
                if getSampleVolume(self.compressedAirSound) ~= 0.5 then
                    setSampleVolume(self.compressedAirSound,0.5);
                end;
                if getSampleVolume(self.compressionSound) ~= 0.75 then
                    setSampleVolume(self.compressionSound,0.75);
                end;
            end;
        else
            if getSampleVolume(self.motorSound) ~= 1.0 then
                setSampleVolume(self.motorSound,1.0);
            end;
            if getSampleVolume(self.motorSoundRun) ~= 1.0 then
                setSampleVolume(self.motorSoundRun,1.0);
            end;
            if getSampleVolume(self.threshingStartSound) ~= 1.0 then
                setSampleVolume(self.threshingStartSound,1.0);
            end;
            if getSampleVolume(self.threshingSound) ~= 1.0 then                
                setSampleVolume(self.threshingSound,1.0);
            end;
            if getSampleVolume(self.threshingStopSound) ~= 1.0 then
                setSampleVolume(self.threshingStopSound,1.0);
            end;
            if getSampleVolume(self.pipeSound) ~= 1.0 then
                setSampleVolume(self.pipeSound,1.0);
            end;
            if getSampleVolume(self.attachSound) ~= 1.0 then
                setSampleVolume(self.attachSound,1.0);
            end;
            if getSampleVolume(self.motorStartSound) ~= 1.0 then
                setSampleVolume(self.motorStartSound,1.0);
            end;
            if getSampleVolume(self.motorStopSound) ~= 1.0 then
                setSampleVolume(self.motorStopSound,1.0);
            end;
            if getSampleVolume(self.reverseDriveSound) ~= 0.5 then
                setSampleVolume(self.reverseDriveSound,0.5);
            end;
            if getSampleVolume(self.compressedAirSound) ~= 1.0 then
                setSampleVolume(self.compressedAirSound,1.0);
            end;
            if getSampleVolume(self.compressionSound) ~= 1.4 then
                setSampleVolume(self.compressionSound,1.5);
            end;
        end;
    end;
end;

function MotorSound:updateTick(dt)
end;

function Combine:onLeave()
    if getSampleVolume(self.motorSound) ~= 1.0 then
        setSampleVolume(self.motorSound,1.0);
    end;
    if getSampleVolume(self.motorSoundRun) ~= 1.0 then
        setSampleVolume(self.motorSoundRun,1.0);
    end;
    if getSampleVolume(self.threshingStartSound) ~= 1.0 then
        setSampleVolume(self.threshingStartSound,1.0);
    end;
    if getSampleVolume(self.threshingSound) ~= 1.0 then                
        setSampleVolume(self.threshingSound,1.0);
    end;
    if getSampleVolume(self.threshingStopSound) ~= 1.0 then
        setSampleVolume(self.threshingStopSound,1.0);
    end;
    if getSampleVolume(self.pipeSound ) ~= 1.0 then
        setSampleVolume(self.pipeSound ,1.0);
    end;
    if getSampleVolume(self.attachSound ) ~= 1.0 then
        setSampleVolume(self.attachSound ,1.0);
    end;
    if getSampleVolume(self.motorStartSound) ~= 1.0 then
        setSampleVolume(self.motorStartSound,1.0);
    end;
    if getSampleVolume(self.motorStopSound) ~= 1.0 then
        setSampleVolume(self.motorStopSound,1.0);
    end;
    if getSampleVolume(self.reverseDriveSound) ~= 0.5 then
        setSampleVolume(self.reverseDriveSound,0.5);
    end;
    if getSampleVolume(self.compressedAirSound) ~= 1.0 then
        setSampleVolume(self.compressedAirSound,1.0);
    end;
    if getSampleVolume(self.compressionSound) ~= 1.5 then
        setSampleVolume(self.compressionSound,1.5);
    end;
    if self.pipeSound ~= nil and self.pipeSoundEnabled then
        stopSample(self.pipeSound);
        self.pipeSoundEnabled = false;
    end;
    if self.threshingSoundActive then
        stopSample(self.threshingSound);
        self.threshingSoundActive = false;
    end;
end;

function MotorSound:draw()
end;