--
--Wheel_Sprayer
--Class for all Wheel_Sprayers
--
--@ by Acid_Burn84
--@ date 05.08.2008

Wheel_Sprayer = {};

function Wheel_Sprayer:new(configFile, positionX, offsetY, positionZ, rotationY, customMt)

	if Wheel_Sprayer_mt == nil then
		Wheel_Sprayer_mt = Class(Wheel_Sprayer, Trailer);
	end;
	
	local mt = customMt;
	if mt == nil then
		mt = Wheel_Sprayer_mt;
	end;
	
	local instance = Trailer:new(configFile, positionX, offsetY, positionZ, rotationY, mt);

    local xmlFile = loadXMLFile("TempConfig", configFile);
	
	instance.sprayValves = {};
	
	local psFile = getXMLString(xmlFile, "vehicle.sprayParticleSystem#file");
    if psFile ~= nil then

        local i=0;
        while true do
            local baseName = string.format("vehicle.sprayValves.sprayValve(%d)", i);
            local node = getXMLString(xmlFile, baseName.. "#index");
            if node == nil then
                break;
            end;
            node = Utils.indexToObject(instance.rootNode, node);
            if node ~= nil then
                local sprayValve = {};
                sprayValve.particleSystems = {};
                local shape = loadI3DFile(psFile);
                link(node, shape);
                for i=0, getNumOfChildren(shape)-1 do
                    local child = getChildAt(shape, i);
                    if getClassName(child) == "Shape" then
                        local geometry = getGeometry(child);
                        if geometry ~= 0 then
                            if getClassName(geometry) == "ParticleSystem" then
                                table.insert(sprayValve.particleSystems, geometry);
                                setEmittingState(geometry, false);
                            end;
                        end;
                    end;
                end;
                table.insert(instance.sprayValves, sprayValve);
            end;
            i = i+1;
        end;
	end;
	
	local spraySound = getXMLString(xmlFile, "vehicle.spraySound#file");
    if spraySound ~= nil and spraySound ~= "" then
        instance.spraySound = createSample("spraySound");
        loadSample(instance.spraySound, spraySound, false);
    end;
	
	local rotationPartNode = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.rotationPart#index"));
    if rotationPartNode ~= nil then
        instance.rotationPart = {};
        instance.rotationPart.node = rotationPartNode;
       
	   local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart#minRot"));
        instance.rotationPart.minRot = {};
        instance.rotationPart.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart#maxRot"));
        instance.rotationPart.maxRot = {};
        instance.rotationPart.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        instance.rotationPart.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart#rotTime"), 2)*1000;
        instance.rotationPart.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart#touchRotLimit"), 10));
    end;
	
	local rotationPartNode2 = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.rotationPart2#index"));
    if rotationPartNode2 ~= nil then
        instance.rotationPart2 = {};
        instance.rotationPart2.node = rotationPartNode2;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart2#minRot"));
        instance.rotationPart2.minRot = {};
        instance.rotationPart2.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart2.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart2.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart2#maxRot"));
        instance.rotationPart2.maxRot = {};
        instance.rotationPart2.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart2.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart2.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        instance.rotationPart2.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart2#rotTime"), 2)*1000;
        instance.rotationPart2.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart2#touchRotLimit"), 10));
    end;
	
	 local rotationPartNode3 = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.rotationPart3#index"));
    if rotationPartNode3 ~= nil then
        instance.rotationPart3 = {};
        instance.rotationPart3.node = rotationPartNode3;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart3#minRot"));
        instance.rotationPart3.minRot = {};
        instance.rotationPart3.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart3.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart3.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart3#maxRot"));
        instance.rotationPart3.maxRot = {};
        instance.rotationPart3.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart3.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart3.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        instance.rotationPart3.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart3#rotTime"), 2)*1000;
        instance.rotationPart3.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart3#touchRotLimit"), 10));
    end;
	
	 local rotationPartNode4 = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.rotationPart4#index"));
    if rotationPartNode4 ~= nil then
        instance.rotationPart4 = {};
        instance.rotationPart4.node = rotationPartNode4;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart4#minRot"));
        instance.rotationPart4.minRot = {};
        instance.rotationPart4.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart4.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart4.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart4#maxRot"));
        instance.rotationPart4.maxRot = {};
        instance.rotationPart4.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart4.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart4.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        instance.rotationPart4.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart4#rotTime"), 2)*1000;
        instance.rotationPart4.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart4#touchRotLimit"), 10));
    end;
	
	 local rotationPartNode5 = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.rotationPart5#index"));
    if rotationPartNode5 ~= nil then
        instance.rotationPart5 = {};
        instance.rotationPart5.node = rotationPartNode5;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart5#minRot"));
        instance.rotationPart5.minRot = {};
        instance.rotationPart5.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart5.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart5.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart5#maxRot"));
        instance.rotationPart5.maxRot = {};
        instance.rotationPart5.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart5.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart5.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        instance.rotationPart5.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart5#rotTime"), 2)*1000;
        instance.rotationPart5.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart5#touchRotLimit"), 10));
    end;
	
	 local rotationPartNode6 = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.rotationPart6#index"));
    if rotationPartNode6 ~= nil then
        instance.rotationPart6 = {};
        instance.rotationPart6.node = rotationPartNode6;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart6#minRot"));
        instance.rotationPart6.minRot = {};
        instance.rotationPart6.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart6.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart6.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart6#maxRot"));
        instance.rotationPart6.maxRot = {};
        instance.rotationPart6.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart6.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart6.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        instance.rotationPart6.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart6#rotTime"), 2)*1000;
        instance.rotationPart6.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart6#touchRotLimit"), 10));
    end;
	
	 local rotationPartNode7 = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.rotationPart7#index"));
    if rotationPartNode7 ~= nil then
        instance.rotationPart7 = {};
        instance.rotationPart7.node = rotationPartNode7;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart7#minRot"));
        instance.rotationPart7.minRot = {};
        instance.rotationPart7.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart7.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart7.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart7#maxRot"));
        instance.rotationPart7.maxRot = {};
        instance.rotationPart7.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart7.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart7.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        instance.rotationPart7.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart7#rotTime"), 2)*1000;
        instance.rotationPart7.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart7#touchRotLimit"), 10));
    end;
	
	 local rotationPartNode8 = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.rotationPart8#index"));
    if rotationPartNode8 ~= nil then
        instance.rotationPart8 = {};
        instance.rotationPart8.node = rotationPartNode8;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart8#minRot"));
        instance.rotationPart8.minRot = {};
        instance.rotationPart8.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart8.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart8.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPart8#maxRot"));
        instance.rotationPart8.maxRot = {};
        instance.rotationPart8.maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        instance.rotationPart8.maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        instance.rotationPart8.maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

        instance.rotationPart8.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart8#rotTime"), 2)*1000;
        instance.rotationPart8.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotationPart8#touchRotLimit"), 10));
    end;
	
	local translationPartNode = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.translationPart#index"));
    if translationPartNode ~= nil then
        instance.translationPart = {};
        instance.translationPart.node = translationPartNode;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPart#minTrans"));
        instance.translationPart.minTrans = {};
        instance.translationPart.minTrans[1] = Utils.getNoNil(x, 0);
        instance.translationPart.minTrans[2] = Utils.getNoNil(y, 0);
        instance.translationPart.minTrans[3] = Utils.getNoNil(z, 0);
	print ("load doTranslate and transMax")
        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPart#maxTrans"));
        instance.translationPart.maxTrans = {};
        instance.translationPart.maxTrans[1] = Utils.getNoNil(x, 0);
        instance.translationPart.maxTrans[2] = Utils.getNoNil(y, 0);
        instance.translationPart.maxTrans[3] = Utils.getNoNil(z, 0);

        instance.translationPart.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPart#transTime"), 2)*1000;
        instance.translationPart.touchTransLimit = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPart#touchTransLimit"), 10);
    end;
	
	local translationPartNode2 = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.translationPart2#index"));
    if translationPartNode2 ~= nil then
        instance.translationPart2 = {};
        instance.translationPart2.node = translationPartNode2;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPart2#minTrans"));
        instance.translationPart2.minTrans = {};
        instance.translationPart2.minTrans[1] = Utils.getNoNil(x, 0);
        instance.translationPart2.minTrans[2] = Utils.getNoNil(y, 0);
        instance.translationPart2.minTrans[3] = Utils.getNoNil(z, 0);

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPart2#maxTrans"));
        instance.translationPart2.maxTrans = {};
        instance.translationPart2.maxTrans[1] = Utils.getNoNil(x, 0);
        instance.translationPart2.maxTrans[2] = Utils.getNoNil(y, 0);
        instance.translationPart2.maxTrans[3] = Utils.getNoNil(z, 0);

        instance.translationPart2.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPart2#transTime"), 2)*1000;
        instance.translationPart2.touchTransLimit = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPart2#touchTransLimit"), 10);
    end;
	
	local translationPartNode3 = Utils.indexToObject(instance.rootNode, getXMLString(xmlFile, "vehicle.translationPart3#index"));
    if translationPartNode3 ~= nil then
        instance.translationPart3 = {};
        instance.translationPart3.node = translationPartNode3;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPart3#minTrans"));
        instance.translationPart3.minTrans = {};
        instance.translationPart3.minTrans[1] = Utils.getNoNil(x, 0);
        instance.translationPart3.minTrans[2] = Utils.getNoNil(y, 0);
        instance.translationPart3.minTrans[3] = Utils.getNoNil(z, 0);

        x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translationPart3#maxTrans"));
        instance.translationPart3.maxTrans = {};
        instance.translationPart3.maxTrans[1] = Utils.getNoNil(x, 0);
        instance.translationPart3.maxTrans[2] = Utils.getNoNil(y, 0);
        instance.translationPart3.maxTrans[3] = Utils.getNoNil(z, 0);

        instance.translationPart3.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPart3#transTime"), 2)*1000;
        instance.translationPart3.touchTransLimit = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translationPart3#touchTransLimit"), 10);
    end;
	
	delete(xmlFile);
	
	 return instance;
end;

function Wheel_Sprayer:delete()
	Trailer.delete(self);
end;

function Wheel_Sprayer:mouseEvent(posX, posY, isDown, isUp, button)
    Trailer.mouseEvent(self, posX, posY, isDown, isUp, button);
end;

function Wheel_Sprayer:keyEvent(unicode, sym, modifier, isDown)
    Trailer.keyEvent(self, unicode, sym, modifier, isDown);
	
	if isDown and sym == Input.KEY_b then
		self:setActive(not self.isActive);
	end;
	
	if isDown and sym == Input.KEY_n then
		self.rotationMax = not self.rotationMax;
		self.rotationMax2 = not self.rotationMax2;
		self.rotationMax3 = not self.rotationMax3;
		self.rotationMax4 = not self.rotationMax4;
	end;
	
	if isDown and sym == Input.KEY_m then
		self.rotationMax5 = not self.rotationMax5;
		self.rotationMax6 = not self.rotationMax6;
		self.rotationMax7 = not self.rotationMax7;
		self.rotationMax8 = not self.rotationMax8;
	end;
	
	if sym == Input.KEY_j then
		self.translationMax = isDown;
		self.translationMax3 = isDown;
	end;
	if sym == Input.KEY_k then
		self.translationMin = isDown;
		self.translationMin3 = isDown;
	end;
	
end;

function Wheel_Sprayer:update(dt)
	
	self.isExpanded = false;
	if self.rotationPart ~= nil then
		local x, y, z = getRotation(self.rotationPart.node);
		local maxRot = self.rotationPart.maxRot;
		local eps = self.rotationPart.touchRotLimit
			
		if math.abs(x-maxRot[1]) < eps and math.abs(y-maxRot[2]) < eps and math.abs(z-maxRot[3]) < eps then
            self.isExpanded = true;
        end;
	end;
	
		
	if self.isActive then
		if not self.spraySoundRunning then
			playSample(self.spraySound, 0, 1.6, 0);
            self.spraySoundRunning = true;
		end;
		--if self.attacherVehicle.lastSpeed*3600 > 29 then
			--self.speedViolationTimer = self.speedViolationTimer - dt;
		--else
			--self.speedViolationTimer = self.speedViolationMaxTime;
		--end;

		--if self.speedViolationTimer > 0 then
			for i=1, table.getn(self.cuttingAreas) do
				local x,y,z = getWorldTranslation(self.cuttingAreas[i].start);
				local x1,y1,z1 = getWorldTranslation(self.cuttingAreas[i].width);
				local x2,y2,z2 = getWorldTranslation(self.cuttingAreas[i].height);
				Utils.updateSprayArea(x, z, x1, z1, x2, z2);
			end;
		--end;
	else
		stopSample(self.spraySound);
		self.spraySoundRunning = false;
	end;
		
		
		if self.rotationPart3 ~= nil then

			local x, y, z = getRotation(self.rotationPart3.node);
			local rot = {x,y,z};
			local newRot = Utils.getMovedLimitedValues(rot, self.rotationPart3.maxRot, self.rotationPart3.minRot, 3, self.rotationPart3.rotTime, dt, not self.rotationMax3);
			setRotation(self.rotationPart3.node, unpack(newRot));
		end;
		
		if self.rotationPart4 ~= nil then

			local x, y, z = getRotation(self.rotationPart4.node);
			local rot = {x,y,z};
			local newRot = Utils.getMovedLimitedValues(rot, self.rotationPart4.maxRot, self.rotationPart4.minRot, 3, self.rotationPart4.rotTime, dt, not self.rotationMax4);
			setRotation(self.rotationPart4.node, unpack(newRot));
		end;
		
		if self.rotationPart5 ~= nil then

			local x, y, z = getRotation(self.rotationPart5.node);
			local rot = {x,y,z};
			local newRot = Utils.getMovedLimitedValues(rot, self.rotationPart5.maxRot, self.rotationPart5.minRot, 3, self.rotationPart5.rotTime, dt, not self.rotationMax5);
			setRotation(self.rotationPart5.node, unpack(newRot));
		end;
		
		if self.rotationPart6 ~= nil then

			local x, y, z = getRotation(self.rotationPart6.node);
			local rot = {x,y,z};
			local newRot = Utils.getMovedLimitedValues(rot, self.rotationPart6.maxRot, self.rotationPart6.minRot, 3, self.rotationPart6.rotTime, dt, not self.rotationMax6);
			setRotation(self.rotationPart6.node, unpack(newRot));
		end;
		
		if self.rotationPart7 ~= nil then

			local x, y, z = getRotation(self.rotationPart7.node);
			local rot = {x,y,z};
			local newRot = Utils.getMovedLimitedValues(rot, self.rotationPart7.maxRot, self.rotationPart7.minRot, 3, self.rotationPart7.rotTime, dt, not self.rotationMax7);
			setRotation(self.rotationPart7.node, unpack(newRot));
		end;
		
		if self.rotationPart8 ~= nil then

			local x, y, z = getRotation(self.rotationPart8.node);
			local rot = {x,y,z};
			local newRot = Utils.getMovedLimitedValues(rot, self.rotationPart8.maxRot, self.rotationPart8.minRot, 3, self.rotationPart8.rotTime, dt, not self.rotationMax8);
			setRotation(self.rotationPart8.node, unpack(newRot));
		end;
		
		if self.translationPart2 ~= nil then

			local x, y, z = getTranslation(self.translationPart2.node);
			local trans = {x,y,z};
			local newTrans = Utils.getMovedLimitedValues(trans, self.translationPart2.maxTrans, self.translationPart2.minTrans, 3, self.translationPart2.transTime, dt, not self.translationMax2);
			setTranslation(self.translationPart2.node, unpack(newTrans));
		end;
		
		
		
	
	
	
	if self.isExpanded then
		
		local doTranslate = self.translationMax or self.translationMin
		if self.translationPart ~= nil and doTranslate then
			--translate = button { }  = isDown
			local x, y, z = getTranslation(self.translationPart.node);
			local trans = {x,y,z};
			local newTrans = Utils.getMovedLimitedValues(trans, self.translationPart.maxTrans, self.translationPart.minTrans, 3, self.translationPart.transTime, dt, not self.translationMax);
			setTranslation(self.translationPart.node, unpack(newTrans));
		end;
		if self.translationPart3 ~= nil and doTranslate then
			--translate = button { }  = isDown
			local x, y, z = getTranslation(self.translationPart3.node);
			local trans = {x,y,z};
			local newTrans = Utils.getMovedLimitedValues(trans, self.translationPart3.maxTrans, self.translationPart3.minTrans, 3, self.translationPart3.transTime, dt, not self.translationMax3);
			setTranslation(self.translationPart3.node, unpack(newTrans));
		end;
	end;
	
	
	if self.rotationPart ~= nil then
		local x, y, z = getRotation(self.rotationPart.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPart.maxRot, self.rotationPart.minRot, 3, self.rotationPart.rotTime, dt, not self.rotationMax);
		setRotation(self.rotationPart.node, unpack(newRot));
	end;
	
	if self.rotationPart2 ~= nil then
		local x, y, z = getRotation(self.rotationPart2.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPart2.maxRot, self.rotationPart2.minRot, 3, self.rotationPart2.rotTime, dt, not self.rotationMax2);
		setRotation(self.rotationPart2.node, unpack(newRot));
	end;
	
	Trailer.update(self, dt);
end;

function Wheel_Sprayer:draw()
    Trailer.draw(self);
	
	if self.isActive then
		g_currentMission:addExtraPrintText("Taste B: Spritze Abschalten");
	else
		g_currentMission:addExtraPrintText("Taste B: Spritze Anschalten");
	end;
	
	if self.rotationMax then
		g_currentMission:addExtraPrintText("Taste N: Part 1/2 Einklappen");
	else
		g_currentMission:addExtraPrintText("Taste N: Part 1/2 Ausklappen");
	end;
	
	if self.rotationMax5 then
		g_currentMission:addExtraPrintText("Taste M: Part 3/4 Einklappen");
	else
		g_currentMission:addExtraPrintText("Taste M: Part 3/4 Ausklappen");
	end;
	
	if self.isExpanded then
		g_currentMission:addExtraPrintText("Taste J/K: Hubmast Hoch/Runter");
	end;
end;

function Wheel_Sprayer:onAttach(attacherVehicle)
	Trailer.onAttach(self);
	self.translationMax2 = true;
end;

function Wheel_Sprayer:onDetach()
	Trailer.onDetach(self);
	self.translationMax2 = false;
	self.isActive = false;
	stopSample(self.spraySound);
	self.spraySoundRunning = false;
	self:setActive(false);
end;

function Wheel_Sprayer:setActive(active)
	self.isActive = active;
	for i=1, table.getn(self.sprayValves) do
        local sprayValve = self.sprayValves[i];
        for j=1, table.getn(sprayValve.particleSystems) do
            setEmittingState(sprayValve.particleSystems[j], self.isActive);
        end;
    end;
end;


	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	