

E512 = {};

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

function E512:load(xmlFile)

function E512:mouseEvent(posX, posY, isDown, isUp, button)
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.sieczkarnia2#rotTime"), 2)*1000;
        self.rotationPartsieczkarnia.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.sieczkarnia2#touchRotLimit"), 10));
    end
local rotationPartNodesieczkarnia2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.sieczkarnia2#index"));
    if rotationPartNodesieczkarnia2 ~= nil then
        self.rotationPartsieczkarnia2 = {};
        self.rotationPartsieczkarnia2.node = rotationPartNodesieczkarnia2;

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

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

        self.rotationPartsieczkarnia2.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.sieczkarnia2#rotTime"), 2)*1000;
        self.rotationPartsieczkarnia2.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.sieczkarnia2#touchRotLimit"), 10));
    end
--------------------------------SIECZKARNIA-----------------------------------------
-----------------------------------END-----------------------------------------
self.wentylator = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.wentylator#index"));
-----------------------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 translationPartNode = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.lewe_drzwi#index"));
    if translationPartNode ~= nil then
        self.translationPart = {};
        self.translationPart.node = translationPartNode;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.lewe_drzwi#minTrans"));
        self.translationPart.minTrans = {};
        self.translationPart.minTrans[1] = Utils.getNoNil(x, 0);
        self.translationPart.minTrans[2] = Utils.getNoNil(y, 0);
        self.translationPart.minTrans[3] = Utils.getNoNil(z, 0);

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

        self.translationPart.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.lewe_drzwi#transTime"), 2)*1000;
        self.translationPart.touchTransLimit = Utils.getNoNil(getXMLString(xmlFile, "vehicle.lewe_drzwi#touchTransLimit"), 10);
    end;	
-------------------------------LEWE DRZWI--------------------------------
---------------------------------END--------------------------------
----------------------------------------KLAPY--------------------------------------
	local rotationPartNodeklapa2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.klapa2#index"));
    if rotationPartNodeklapa2 ~= nil then
        self.rotationPartklapa2 = {};
        self.rotationPartklapa2.node = rotationPartNodeklapa2;

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

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

        self.rotationPartklapa2.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.klapa2#rotTime"), 2)*1000;
        self.rotationPartklapa2.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.klapa2#touchRotLimit"), 10));
    end;
		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;
	
----------------------------------------KLAPY--------------------------------------	
----------------------------------------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.slimak = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.slimak#index"));
	
    self.lusterka = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lusterka#index"));
	self.halogeny = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.halogeny#przednie"));
	self.halogen = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.halogeny#boczny"));
	
	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, 2900);
    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.halogenActive = false
self.lusterkaActive = false;
self.strawActive = true;

end;

function E512:delete()

end;

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

		if isDown and sym == Input.KEY_z then
		    self.slomaActive = not self.slomaActive;
			self.rotationMaxsieczkarnia2 = not self.rotationMaxsieczkarnia2;
			self.rotationMaxsieczkarnia = not self.rotationMaxsieczkarnia;
		end;
	
	if sym == Input.KEY_6 then
		self.translationMax = isDown;
	end;
	if sym == Input.KEY_5 then
		self.translationMin = 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;
		self.rotationMaxklapa2 = not self.rotationMaxklapa2;
	end;
	if isDown and sym == Input.KEY_8 then
		self.halogenyActive = not self.halogenyActive;
	end;
	if isDown and sym == Input.KEY_x then
		self.halogenActive = not self.halogenActive;
	end;
	---------------------------------KIERUNKI-----------------------	
	if isDown and sym == Input.KEY_n 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_k 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_m 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 E512:update(dt)


	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;
	if self.rotationPartsieczkarnia2 ~= nil then
		local x, y, z = getRotation(self.rotationPartsieczkarnia2.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartsieczkarnia2.maxRot, self.rotationPartsieczkarnia2.minRot, 3, self.rotationPartsieczkarnia2.rotTime, dt, not self.rotationMaxsieczkarnia2);
		setRotation(self.rotationPartsieczkarnia2.node, unpack(newRot));
	end;
----------------------------------END------------------------------------
	if self.isMotorStarted and self.wentylator ~= nil then
		rotate(self.wentylator, dt*0.2, 0, 0);
	end;
---------------Lewe Drzwi------------------
local doTranslate = self.translationMax or self.translationMin
		if self.translationPart ~= nil and doTranslate then
			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;
---------------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);
		rotate(self.slimak, 0, dt*0.2, 0);
	end;


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

	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;	
	if self.rotationPartklapa2 ~= nil then
		local x, y, z = getRotation(self.rotationPartklapa2.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartklapa2.maxRot, self.rotationPartklapa2.minRot, 3, self.rotationPartklapa2.rotTime, dt, not self.rotationMaxklapa2);
		setRotation(self.rotationPartklapa2.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 E512: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, "--->FORTSCHRITT E512<---");
	
	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: r");
	else
		renderText(0.0515, 0.44, 0.020, "Wlacz kogut: r");
	end;

	renderText(0.0515, 0.42, 0.020, "Drzwi otworz/zamknij: 5/6");
	if self.rotationMaxklapa2 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.halogenActive  then
		renderText(0.0515, 0.36, 0.020, "Wylacz halogen boczny: 9");
	else
		renderText(0.0515, 0.36, 0.020, "Wlacz halogen boczny: 9");
	end;
	if self.flashLeft  then
		renderText(0.0515, 0.34, 0.020, "Wylacz kierunek lewy: n");
	else
		renderText(0.0515, 0.34, 0.020, "Wlacz kierunek lewy: n");
	end;
	if self.flash  then
		renderText(0.0515, 0.32, 0.020, "Wylacz awaryjne: k");
	else
		renderText(0.0515, 0.32, 0.020, "Wlacz awaryjne: k");
	end;
	if self.flashRight  then
		renderText(0.0515, 0.30, 0.020, "Wylacz kierunek prawy: m");
	else
		renderText(0.0515, 0.30, 0.020, "Wlacz kierunek prawy: m");
	end;
end;

end;







