--unisound
--by ? / Blackdragon223 / Hummel


unisound = {};

function unisound.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;

function unisound:load(xmlFile)

    self.pipeLight = nil
    if self.pipeLight ~= nil then
	setVisibility(self.pipeLight, false);
    end;
    self.pipeLightActive = false;
    self.balcamera = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.balcamera#index"));
    self.jobbcamera = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.jobbcamera#index"));
    end;	

function unisound:delete()

end;

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

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

function unisound:update(dt)

	if self.isEntered then

		if self.camIndex == 2 then

    			if self.motorSound ~= nil then
				setSampleVolume(self.motorSound, self.motorSoundVolume/2.5);
   			end;
    			if self.motorSoundRun ~= nil then
				setSampleVolume(self.motorSoundRun, self.motorSoundRunVolume/2.5);
    			end;
    			if self.motorStartSound ~= nil then
				setSampleVolume(self.motorStartSound, self.motorStartSoundVolume/2.5);
    			end;
    			if self.motorStopSound ~= nil then
				setSampleVolume(self.motorStopSound, self.motorStopSoundVolume/2.5);
    			end;
    			if self.reverseDriveSound ~= nil then
				setSampleVolume(self.reverseDriveSound, self.reverseDriveSoundVolume/2.5);
    			end;
    			if self.compressedAirSound ~= nil then
				setSampleVolume(self.compressedAirSound, self.compressedAirSoundVolume/2.5);
    			end;
    			if self.compressionSound ~= nil then
				setSampleVolume(self.compressionSound, self.compressionSoundVolume/2.5);
    			end;
    			if self.aiMotorSound ~= nil then
				setSampleVolume(self.aiMotorSound, self.aiMotorSoundVolume/2.5);
    			end;
    			if self.aiThreshingSound ~= nil then
				setSampleVolume(self.aiThreshingSound, self.aiThreshingSoundVolume/2.5);
    			end;
    			if self.pipeSound ~= nil then
				setSampleVolume(self.pipeSound, 0.5);
    			end;
    			if self.threshingStartSound ~= nil then
				setSampleVolume(self.threshingStartSound, 0.5);
    			end;
    			if self.threshingSound ~= nil then
				setSampleVolume(self.threshingSound, 0.5);
    			end;
    			if self.cutterthreshingSound ~= nil then
				setSampleVolume(self.cutterthreshingSound, self.cutterthreshingSoundVolume/2);
    			end;
    			if self.threshingStopSound ~= nil then
				setSampleVolume(self.threshingStopSound, 0.5);
    			end;
    			if self.attachSound ~= nil then
				setSampleVolume(self.attachSound, 0.5);
    			end;
    			if self.honkSound ~= nil then
				setSampleVolume(self.honkSound, self.honkSoundVolume/2.5);
   			end;
		else
    			if self.motorSound ~= nil then
				setSampleVolume(self.motorSound, self.motorSoundVolume);
   			end;
    			if self.motorSoundRun ~= nil then
				setSampleVolume(self.motorSoundRun, self.motorSoundRunVolume);
    			end;
    			if self.motorStartSound ~= nil then
				setSampleVolume(self.motorStartSound, self.motorStartSoundVolume);
    			end;
    			if self.motorStopSound ~= nil then
				setSampleVolume(self.motorStopSound, self.motorStopSoundVolume);
    			end;
    			if self.reverseDriveSound ~= nil then
				setSampleVolume(self.reverseDriveSound, self.reverseDriveSoundVolume);
    			end;
    			if self.compressedAirSound ~= nil then
				setSampleVolume(self.compressedAirSound, self.compressedAirSoundVolume);
    			end;
    			if self.compressionSound ~= nil then
				setSampleVolume(self.compressionSound, self.compressionSoundVolume);
    			end;
    			if self.aiMotorSound ~= nil then
				setSampleVolume(self.aiMotorSound, self.aiMotorSoundVolume);
    			end;
    			if self.aiThreshingSound ~= nil then
				setSampleVolume(self.aiThreshingSound, self.aiThreshingSoundVolume);
    			end;
    			if self.pipeSound ~= nil then
				setSampleVolume(self.pipeSound, 1);
    			end;
    			if self.threshingStartSound ~= nil then
				setSampleVolume(self.threshingStartSound, 1);
    			end;
    			if self.threshingSound ~= nil then
				setSampleVolume(self.threshingSound, 1);
    			end;
    			if self.cutterthreshingSound ~= nil then
				setSampleVolume(self.cutterthreshingSound, self.cutterthreshingSoundVolume);
    			end;
    			if self.threshingStopSound ~= nil then
				setSampleVolume(self.threshingStopSound, 1);
    			end;
    			if self.attachSound ~= nil then
				setSampleVolume(self.attachSound, 1);
    			end;
    			if self.honkSound ~= nil then
				setSampleVolume(self.honkSound, self.honkSoundVolume);
   			end;
		end;
	
        	if Input.isKeyPressed(Input.KEY_shift) and self.camIndex == 2 then
                	setCamera(self.balcamera);
       		end;
        	if Input.isKeyPressed(60) and self.camIndex == 2 then
                	setCamera(self.jobbcamera);
       		end;
        	if self.pipeLight ~= nil then
            		if self.pipeLightActive then
            			setVisibility(self.pipeLight, self.pipeLightActive);
	    		else
            			setVisibility(self.pipeLight, self.pipeLightActive);
	    		end;
        	end;
		if self.numAttachedCutters == 0 then
			self.lepcsoMax = true;
		else
    			self.lepcsoMax = false;
		end;

	end;	

end;

function unisound:draw()  
end;

function unisound:onEnter()

    self.lepcsoMax = true;

end;

function unisound:onLeave()

    if self.pipeLight ~= nil then
    	setVisibility(self.pipeLight, false);
    end;
	
end;
