

Z056 = {};

function Z056.prerequisitesPresent(specializations)
    Vehicle.registerJointType("cutter");
    Vehicle.registerJointType("trailerCombine");
    return SpecializationUtil.hasSpecialization(Steerable, specializations);
end;

function Z056:load(xmlFile)

    self.plandeka = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.plandeka#index"));
	self.plandekaActive = true;
	
	local rotationNodegardziel = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.gardziel#index"));
    if rotationNodegardziel ~= nil then
        self.gardziel = {};
        self.gardziel.node = rotationNodegardziel;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.gardziel#minRot"));
        self.gardziel.minRot = {};
        self.gardziel.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.gardziel.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.gardziel.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

        self.gardziel.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.gardziel#rotTime"), 2)*1000;
        self.gardziel.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.gardziel#touchRotLimit"), 10));
    end;

--------------------------------SIECZKARNIA-----------------------------------------
local rotationPartNodesieczkarnia = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.sieczkarnia#index"));
    if rotationPartNodesieczkarnia ~= nil then
        self.rotationPartsieczkarnia = {};
        self.rotationPartsieczkarnia.node = rotationPartNodesieczkarnia;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.sieczkarnia#minRot"));
        self.rotationPartsieczkarnia.minRot = {};
        self.rotationPartsieczkarnia.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartsieczkarnia.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartsieczkarnia.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

        self.rotationPartsieczkarnia.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.sieczkarnia#rotTime"), 2)*1000;
        self.rotationPartsieczkarnia.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.sieczkarnia#touchRotLimit"), 10));
    end

--------------------------------SIECZKARNIA-----------------------------------------
-----------------------------------END-----------------------------------------

-----------------------ZAPLON-----------------------------------
	    -- Booleans
    self.ignitionKey = false;
	self.allowedIgnition = false;                                                  
	
	-- Backup Stop Sound volume
    self.motorStopSoundVolume2 = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.motorStopSound#volume"), 1.0);	
-----------------------ZAPLON-----------------------------------	
---------------------------END------------------------------------
-------------------------------LEWE DRZWI--------------------------------	
	local lewedrzwiNode = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lewe_drzwi#index"));
		if lewedrzwiNode ~= nil then
        self.lewedrzwi = {};
        self.lewedrzwi.node = lewedrzwiNode;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.lewe_drzwi#minRot"));
        self.lewedrzwi.minRot = {};
        self.lewedrzwi.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.lewedrzwi.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.lewedrzwi.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

        self.lewedrzwi.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.lewe_drzwi#rotTime"), 2)*1000;
        self.lewedrzwi.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.lewe_drzwi#touchRotLimit"), 10));
    end;
-------------------------------LEWE DRZWI--------------------------------
---------------------------------END--------------------------------
----------------------------------------KLAPA--------------------------------------
	local rotationPartNodeklapa = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.klapa#index"));
    if rotationPartNodeklapa ~= nil then
        self.rotationPartklapa = {};
        self.rotationPartklapa.node = rotationPartNodeklapa;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotationPartklapa#minRot"));
        self.rotationPartklapa.minRot = {};
        self.rotationPartklapa.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartklapa.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartklapa.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

        self.rotationPartklapa.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.klapa#rotTime"), 2)*1000;
        self.rotationPartklapa.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.klapa#touchRotLimit"), 10));
    end;
	
----------------------------------------KLAPA--------------------------------------	
----------------------------------------END--------------------------------------	
 --------------------------------------KOGUT-----------------------------

 self.kogutAnz = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.kogut#count"),0);
    self.kogutKey = getXMLString(xmlFile, "vehicle.kogut#key");
    self.kogutAn = false;
    self.kogut = {};
    for i=1, self.kogutAnz do
        local objname = string.format("vehicle.kogut.light" .. "%d",i);
        self.kogut[i] = {};
        self.kogut[i].rotNode = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, objname .. "#rotNode"));
        self.kogut[i].light = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, objname .. "#light"));
        self.kogut[i].source = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, objname .. "#lightsource"));
        self.kogut[i].speed = Utils.getNoNil(getXMLInt(xmlFile,  objname .. "#rotSpeed"), 1)/1000;
        self.kogut[i].emit = Utils.getNoNil(getXMLBool(xmlFile, objname .. "#emitLight"), true);
        if not self.kogut[i].emit and self.kogut[i].source ~= nil then
           setVisibility(self.kogut[i].source, false);
        end;
    end;
--------------------------------------KOGUT-----------------------------
----------------------------------------END--------------------------------------



self.naginacz = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.naginacz#index"));
	
    self.halogeny = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.halogeny#przednie"));

	self.kierunek = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.kierunek_lewy#index"));	
	self.kierunekActive = false;
	
    self.kierunek2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.kierunek_prawy#index"));	
	self.kierunek2Active = false;
	
	turn1SoundFile = Utils.getFilename("turn1.wav", self.baseDirectory);
    self.turn1 = createSample("turn1");
    loadSample(self.turn1, turn1SoundFile, false);
	
	turn2SoundFile = Utils.getFilename("turn2.wav", self.baseDirectory);
    self.turn2 = createSample("turn2");
    loadSample(self.turn2, turn2SoundFile, false);
		
		
	 	self.numbrakelights = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.brakelights#count"), 0);
    self.brakelights = {};
    for i=1, self.numbrakelights do
        local brakelightnamei = string.format("vehicle.brakelights.brakelight" .. "%d", i);
        self.brakelights[i] = Utils.indexToObject(self.rootNode, getXMLInt(xmlFile, brakelightnamei .. "#index"));
        setVisibility(self.brakelights[i], false);
    end;
	self.brakelightsActive = false;
    self.braking = false;
	
		----------------------------OBROTY-------------------------------
    local motorMaxRpmStr = getXMLString(xmlFile, "vehicle.motor#maxRpm");
    local motorMaxRpm1, motorMaxRpm2, motorMaxRpm3 = Utils.getVectorFromString(motorMaxRpmStr);
    motorMaxRpm1 = Utils.getNoNil(motorMaxRpm1, 650);
    motorMaxRpm2 = Utils.getNoNil(motorMaxRpm2, 1000);
    motorMaxRpm3 = Utils.getNoNil(motorMaxRpm3, 1800);
    local motorMaxRpm = {motorMaxRpm1, motorMaxRpm2, motorMaxRpm3};
    self.motorMaxRpmLimit = motorMaxRpm;
	
		local rotationPartNodepedalhamulca = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.pedal_hamulca#index"));
    if rotationPartNodepedalhamulca ~= nil then
        self.rotationPartpedalhamulca = {};
        self.rotationPartpedalhamulca.node = rotationPartNodepedalhamulca;

        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.pedal_hamulca#minRot"));
        self.rotationPartpedalhamulca.minRot = {};
        self.rotationPartpedalhamulca.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotationPartpedalhamulca.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotationPartpedalhamulca.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

        self.rotationPartpedalhamulca.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.pedal_hamulca#rotTime"), 2)*1000;
        self.rotationPartpedalhamulca.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.pedal_hamulca#touchRotLimit"), 10));
    end;

self.rotationMaxpedalhamulca = false;	
self.halogenyActive = false
self.strawActive = true;

end;

function Z056:delete()

end;

function Z056:keyEvent(unicode, sym, modifier, isDown)

		if isDown and sym == Input.KEY_z then
		    self.slomaActive = not self.slomaActive;
			self.rotationMaxsieczkarnia = not self.rotationMaxsieczkarnia;
		end;
		if isDown and sym == Input.KEY_x then
		self.plandekaActive = not self.plandekaActive;
    	end;
    	if sym == Input.KEY_pageup then
		self.gardzielMax = isDown;
	end;
	if sym == Input.KEY_pagedown then
		self.gardzielMin = isDown;
	end;
	
	if sym == Input.KEY_5 then
		self.lewedrzwiMax = isDown;
	end;
	if sym == Input.KEY_6 then
		self.lewedrzwiMin = isDown;
	end;
	--------KOGUT---------------
    if self.isEntered then
      if self.kogutKey ~= nil then
         if isDown and sym == Input[self.kogutKey] then
           self.kogutAn = not self.kogutAn;
           for i=1, self.kogutAnz do
             setVisibility(self.kogut[i].light, self.kogutAn);
           end;
         end;
      end;
    end;
	   if isDown and sym == Input.KEY_0 then
		self.bcActive = not self.bcActive;
	end;
 if isDown and sym == Input.KEY_7 then
		self.rotationMaxklapa = not self.rotationMaxklapa;
	end;
	if isDown and sym == Input.KEY_8 then
		self.halogenyActive = not self.halogenyActive;
	end;
	
	---------------------------------KIERUNKI-----------------------	
	if isDown and sym == Input.KEY_KP_1 then
		self.flashLeft = not self.flashLeft;
		self.delayOnLeft = 10;
		self.flashRight = false;
		self.flash = false;
		self.flashlightsRightActive = false;
		self.flashlightsWarnerActive = false;
		self.flashlightsRight2Active = false;
		self.kierunek2Active = false;
		self.flashWarner = false;
	end;
	
	if isDown and sym == Input.KEY_KP_2 then
		self.flash = not self.flash;
		self.flashRight = false;
		self.flashLeft = false;
		self.delayOn = 20;
		self.flashlightsRightActive = false;
		self.flashlightsLeftActive = false;
		self.flashWarner = not self.flashWarner;
	end;
	
	if isDown and sym == Input.KEY_KP_3 then
		self.flashRight = not self.flashRight;
		self.delayOnRight = 10;
		self.flashLeft = false;
		self.flash = false;
		self.flashlightsLeftActive = false;
		self.flashlightsWarnerActive = false;
		self.flashlightsLeft2Active = false;
		self.kierunekActive = false;
		self.flashWarner = false;
	end;
end;

function Z056:update(dt)

	local doRotate = self.gardzielMax or self.gardzielMin 
	if self.gardziel ~= nil and doRotate then
        local x, y, z = getRotation(self.gardziel.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.gardziel.maxRot, self.gardziel.minRot, 3, self.gardziel.rotTime, dt, not self.gardzielMax);
        setRotation(self.gardziel.node, unpack(newRot));
    end;
self.isExpanded = false;
	setVisibility(self.plandeka, self.plandekaActive);
	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:getIsActive() then


        if self.chopperEnableTime ~= nil and self.chopperEnableTime <= self.time then
            if self.currentChopperParticleSystem ~= nil then
                Utils.setEmittingState(self.currentChopperParticleSystem, false);
            end;
            self.currentChopperParticleSystem = self.chopperParticleSystems[self.currentGrainTankFruitType];
            if self.currentChopperParticleSystem == nil then
                self.currentChopperParticleSystem = self.defaultChopperParticleSystem;
            end;
            Utils.setEmittingState(self.currentChopperParticleSystem, true);
            self.chopperEnableTime = nil;
        end;
        if self.strawEnableTime ~= nil and self.strawEnableTime <= self.time then
            if self.currentStrawParticleSystem ~= nil then
                Utils.setEmittingState(self.currentStrawParticleSystem, false);
            end;
            self.currentStrawParticleSystem = self.strawParticleSystems[self.currentGrainTankFruitType];
            if self.currentStrawParticleSystem == nil then
                self.currentStrawParticleSystem = self.defaultStrawParticleSystem;
            end;
			Utils.setEmittingState(self.currentStrawParticleSystem, true);
            self.strawEnableTime = nil;
            self.strawEmitState = true;
        end;
        if self.strawEmitState then
            for k, strawArea in pairs(self.strawAreas) do
                local x,y,z = getWorldTranslation(strawArea.start);
                local x1,y1,z1 = getWorldTranslation(strawArea.width);
                local x2,y2,z2 = getWorldTranslation(strawArea.height);
                local old, total = Utils.getFruitWindrowArea(self.currentGrainTankFruitType, x, z, x1, z1, x2, z2);
                local value = 1+math.floor(old / total + 0.7); -- round, biased to the bigger value
                value = math.min(value, g_currentMission.maxWindrowValue);
                Utils.updateFruitWindrowArea(self.currentGrainTankFruitType, x, z, x1, z1, x2, z2, value, true);
            end;
        end;

    end;

    if self.chopperDisableTime ~= nil and self.chopperDisableTime <= self.time then
        if self.currentChopperParticleSystem ~= nil then
            Utils.setEmittingState(self.currentChopperParticleSystem, false);
        end;
        self.currentChopperParticleSystem = self.chopperParticleSystems[self.currentGrainTankFruitType];
        if self.currentChopperParticleSystem == nil then
            self.currentChopperParticleSystem = self.defaultChopperParticleSystem;
        end;
        Utils.setEmittingState(self.currentChopperParticleSystem, false);
        self.chopperDisableTime = nil;
    end;
    if self.strawDisableTime ~= nil and self.strawDisableTime <= self.time then
        if self.currentStrawParticleSystem ~= nil then
            Utils.setEmittingState(self.currentStrawParticleSystem, false);
        end;
        self.currentStrawParticleSystem = self.strawParticleSystems[self.currentGrainTankFruitType];
        if self.currentStrawParticleSystem == nil then
            self.currentStrawParticleSystem = self.defaultStrawParticleSystem;
        end;
        Utils.setEmittingState(self.currentStrawParticleSystem, false);
        self.strawDisableTime = nil;
        self.strawEmitState = false;
    end;

------------------------------SIECZKARNIA------------------------------------
 
	if self:getIsActive() then
		if not self.slomaActive then
		    self.strawEmitState = false;
			self.strawEnableTime = nil;
			self.chopperActivated = true;
		if self.lastArea > 0 then
		    if self.chopperActivated then
                if self.chopperEnableTime == nil then
                       self.chopperEnableTime = self.time + self.chopperToggleTime;
                  else
                    self.chopperDisableTime = nil;
				end;
                  self.disableChopperEmit = false;
			    end;
				if self.chopperEnableTime ~= nil and self.chopperEnableTime <= self.time then
					self.currentChopperParticleSystem = self.chopperParticleSystems[self.currentGrainTankFruitType];
					if self.currentChopperParticleSystem == nil then
						self.currentChopperParticleSystem = self.defaultChopperParticleSystem;
					end;
				end;
			end;	
	  		if not self.isThreshing then
				Utils.setEmittingState(self.currentChopperParticleSystem, false);
			end;
		end;
    end;


	------------------------------SIECZKARNIA------------------------------------
	-------------------------------OBRACANIE----------------------------------
	if self.rotationPartsieczkarnia ~= nil then
		local x, y, z = getRotation(self.rotationPartsieczkarnia.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartsieczkarnia.maxRot, self.rotationPartsieczkarnia.minRot, 3, self.rotationPartsieczkarnia.rotTime, dt, not self.rotationMaxsieczkarnia);
		setRotation(self.rotationPartsieczkarnia.node, unpack(newRot));
	end;
----------------------------------END------------------------------------
---------------Lewe Drzwi------------------
local doRotate = self.lewedrzwiMax or self.lewedrzwiMin 
	if self.lewedrzwi ~= nil and doRotate then
        	local x, y, z = getRotation(self.lewedrzwi.node);
        	local rot = {x,y,z};
        	local newRot = Utils.getMovedLimitedValues(rot, self.lewedrzwi.maxRot, self.lewedrzwi.minRot, 3, self.lewedrzwi.rotTime, dt, not self.lewedrzwiMax);
        	setRotation(self.lewedrzwi.node, unpack(newRot));
	end;
---------------Lewe Drzwi------------------
--------------------END----------------------

    if self.kogutAnz > 0 then
      if self.kogutAn then
        for i=1, self.kogutAnz do
          rotate(self.kogut[i].rotNode, 0, dt*self.kogut[i].speed, 0);
        end;
      end;
    end;

	if self.isThreshing then
		rotate(self.naginacz, dt*0.2, 0, 0);
	end;


	setVisibility(self.lusterka, self.lusterkaActive);
	setVisibility(self.halogeny, self.halogenyActive);
	

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

	if self.flash then
		if self.delayOn >= 0 then
			self.delayOn = self.delayOn -dt;
		end;
		if not self.flashlightsRightActive then
			if self.delayOn < 0 then
				self.delayOff = 500;
				self.flashlightsRightActive = true;
				self.flashlightsLeftActive = true;
				self.flashlightsWarnerActive = true;
				self.kierunek2Active = true;
				self.kierunekActive = true;
				playSample(self.turn1, 1, 0.7, 0);
			end;
		end;
		if self.delayOff >= 0 then
			self.delayOff = self.delayOff -dt;
		end;
		if self.flashlightsRightActive then
			if self.delayOff < 0 then
				self.delayOn = 500;
				self.flashlightsLeftActive = false;
				self.flashlightsRightActive = false;
				self.flashlightsWarnerActive = false;
				self.kierunek2Active = false;
				self.kierunekActive = false;
				playSample(self.turn2, 1, 0.7, 0);
			end;
		end;
	end;
	
	if self.flashRight then
		if self.delayOnRight >= 0 then
			self.delayOnRight = self.delayOnRight -dt;
		end;
		if not self.flashlightsRightActive then
			if self.delayOnRight < 0 then
				self.delayOffRight = 500;
				self.flashlightsRightActive = true;
				self.kierunek2Active = true;
				playSample(self.turn1,1,0.7,0);
			end;
		end;
		if self.delayOffRight >= 0 then
			self.delayOffRight = self.delayOffRight -dt;
		end;
		if self.flashlightsRightActive then
			if self.delayOffRight < 0 then
				self.delayOnRight = 500;
				self.flashlightsRightActive = false;
				self.kierunek2Active = false;
				playSample(self.turn2,1,0.7,0);
			end;
		end;
	else
		if not self.flashWarner then
			self.kierunek2Active = false;
		end;
	end;
	
	
		if self.flashLeft then
			if self.delayOnLeft >= -1 then
				self.delayOnLeft = self.delayOnLeft -dt;
			end;
			if not self.flashlightsLeftActive then
				if self.delayOnLeft < 0 then
					self.delayOffLeft = 500;
					self.flashlightsLeftActive = true;
					self.kierunekActive = true;
					playSample(self.turn1,1,0.7,0);
				end;
			end;
			if self.delayOffLeft >= 0 then
				self.delayOffLeft = self.delayOffLeft -dt;
			end;
			if self.flashlightsLeftActive then
				if self.delayOffLeft < 0 then
					self.delayOnLeft = 500;
					self.flashlightsLeftActive = false;
					self.kierunekActive = false;
					playSample(self.turn2,1,0.7,0);
				end;
			end;
		else
			if not self.flashWarner then
				self.kierunekActive = false;
			end;
		end;

setVisibility(self.kierunek, self.kierunekActive);
setVisibility(self.kierunek2, self.kierunek2Active); 
          inputAxisY = InputBinding.getAnalogInputAxis(InputBinding.AXIS_FORWARD);

        if InputBinding.isAxisZero(inputAxisY) then
        inputAxisY = InputBinding.getDigitalInputAxis(InputBinding.AXIS_FORWARD);
        end;
   		
	if self.isEntered ~= nil then
		if self.brakelightsActive then
			for i=1, self.numbrakelights do
				local brakelight = self.brakelights[i];
				setVisibility(brakelight, self.brakelightsActive);
			end;
		else
			for i=1, self.numbrakelights do
				local brakelight = self.brakelights[i];
				setVisibility(brakelight, self.brakelightsActive, false);
			end;
		end;
		if (self.movingDirection*self.lastSpeed*(-inputAxisY)) < -0.001 then		
			self.brakelightsActive = true;
			self.braking = true;
			self.rotationMaxpedalhamulca = true;
		else
			self.brakelightsActive = false;
			self.braking = false;
			self.rotationMaxpedalhamulca = false;
		end;
    end;
 
 	----------------------------OBROTY-------------------------------		
	if self.isMotorStarted and self:getIsActiveForInput() and self.isEntered then
	
	    if self.motor.speedLevel ~= 0 then
			
            if InputBinding.isPressed(InputBinding.ACCELERATE) then
		        if self.motor.maxRpm[self.motor.speedLevel] <= (self.motorMaxRpmLimit[3] - 10) then
		            self.motor.maxRpm[self.motor.speedLevel] = self.motor.maxRpm[self.motor.speedLevel] + 10;
			    end;
		    elseif InputBinding.isPressed(InputBinding.DECELERATE) then
		        if self.motor.maxRpm[self.motor.speedLevel] >= 10 then
			        self.motor.maxRpm[self.motor.speedLevel] = self.motor.maxRpm[self.motor.speedLevel] - 10;
			    end;
	    	end;
				
		else
			
            if InputBinding.isPressed(InputBinding.ACCELERATE) then
		        if self.motor.maxRpm[3] <= (self.motorMaxRpmLimit[3] - 10) then
		            self.motor.maxRpm[3] = self.motor.maxRpm[3] + 10;
			    end;
		    elseif InputBinding.isPressed(InputBinding.DECELERATE) then
		        if self.motor.maxRpm[3] >= 10 then
			            self.motor.maxRpm[3] = self.motor.maxRpm[3] - 10;
			    end;
	    	end;
			
	    end;
		
	end;
 	if self.rotationPartpedalhamulca ~= nil then
		local x, y, z = getRotation(self.rotationPartpedalhamulca.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartpedalhamulca.maxRot, self.rotationPartpedalhamulca.minRot, 3, self.rotationPartpedalhamulca.rotTime, dt, not self.rotationMaxpedalhamulca);
		setRotation(self.rotationPartpedalhamulca.node, unpack(newRot));
	end;
   
end;	


function Z056:draw()
   	if self.bshudOverlay ~= nil then
			if self.bcActive then
			self.bshudOverlay:render();
			end;
		end;
   if self.bcActive then
		setTextColor(1,1,1,1);
		renderText(0.8335, 0.15, 0.02, "NUM 0: Wylacz Pomoc");
	else
		setTextColor(1,1,1,1);
		renderText(0.8335, 0.15, 0.02, "NUM 0: Wlacz Pomoc");
	end;

	
	
	if self.bcActive then
		renderText(0.055, 0.49, 0.027, "--->BIZON Z056<---");
	
	if self.slomaActive then
		renderText(0.0515, 0.46, 0.020, "Wlacz sieczkarnie: z");
	else
		renderText(0.0515, 0.46, 0.020, "Wylacz sieczkarnie: z");
	end;
	if self.kogutAn  then
		renderText(0.0515, 0.44, 0.020, "Wylacz kogut: Home");
	else
		renderText(0.0515, 0.44, 0.020, "Wlacz kogut: Home");
	end;

	renderText(0.0515, 0.42, 0.020, "Drzwi otworz/zamknij: 5/6");
	if self.rotationMaxklapa then
		renderText(0.0515, 0.40, 0.020, "Zamknij klape: 7");
	else
		renderText(0.0515, 0.40, 0.020, "Otworz klape: 7");
	end
	if self.halogenyActive  then
		renderText(0.0515, 0.38, 0.020, "Wylacz halogeny przednie: 8");
	else
		renderText(0.0515, 0.38, 0.020, "Wlacz halogeny przednie: 8");
	end;
	if self.flashLeft  then
		renderText(0.0515, 0.36, 0.020, "Wylacz kierunek lewy: NUM 1");
	else
		renderText(0.0515, 0.36, 0.020, "Wlacz kierunek lewy: NUM 1");
	end;
	if self.flash  then
		renderText(0.0515, 0.34, 0.020, "Wylacz awaryjne: NUM 2");
	else
		renderText(0.0515, 0.34, 0.020, "Wlacz awaryjne: NUM 2");
	end;
	if self.flashRight  then
		renderText(0.0515, 0.32, 0.020, "Wylacz kierunek prawy: NUM 3");
	else
		renderText(0.0515, 0.32, 0.020, "Wlacz kierunek prawy: NUM 3");
	end;
		if self.flashRight  then
		renderText(0.0515, 0.30, 0.020, "Zdejmij plandeke: X");
	else
		renderText(0.0515, 0.30, 0.020, "Zaloz plandeke: X");
	end;
		if self.flashRight  then
		renderText(0.0515, 0.28, 0.020, "Opusc gardziel: Pg UP");
	else
		renderText(0.0515, 0.28, 0.020, "Podnies gardziel: Pg Down");
	end;
end;

end;
function Z056:validateAttacherJoint(implement, jointDesc, dt)
   return true;
end;







