--Specjalizacja dla : Ursus c360 By Marcello1942
--#Autor: marcello1942
--#data: 21/08/2012 r.
--Przy edycji nie zapomnij o oryginalnym autorze!

Ursus360NN = {};

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

function Ursus360NN:load(xmlFile)

	local klapalewa = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#lewe"));
	if klapalewa ~= nil then
		self.klapalewa = klapalewa;
	end;
		local klapaprawa = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#prawe"));
	if klapaprawa ~= nil then
		self.klapaprawa = klapaprawa;
	end;
		local zaczep = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#zaczep"));
	if zaczep ~= nil then
		self.zaczep = zaczep;
	end;
		local Maska_1a = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Maska_1a#index"));
	if Maska_1a ~= nil then
		self.Maska_1a = Maska_1a;
	end;
		local Maska_1b = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Maska_1b#index"));
	if Maska_1b ~= nil then
		self.Maska_1b = Maska_1b;
	end;
		local Maska_1c = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Maska_1c#index"));
	if Maska_1c ~= nil then
		self.Maska_1c = Maska_1c;
	end;
	    local wycieraczka_2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#wycieraczka_2"));
	if wycieraczka_2 ~= nil then
		self.wycieraczka_2 = wycieraczka_2;
	end;
		local pompka = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#pompka"));
	if pompka ~= nil then
		self.pompka = pompka;
	end;
		local gabka = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lok#gabka"));
	if gabka ~= nil then
		self.gabka = gabka;
	end;
	
	self.klapkaoff = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.klapkaoff#index"));
	self.klapkaon = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.klapkaon#index"));
	self.bolec1 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.bolec1#index"),"0 1 0");
	self.bolec2 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.bolec2#index"), 1);
	setVisibility((self.klapkaoff), true);
	setVisibility((self.klapkaon), false);

  	local hydraulicsCount = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.hydraulics#count"), 0);
	self.hydraulics = {};
	for i=1, hydraulicsCount do
		local hydraulicName = string.format("vehicle.hydraulics.hydraulic%d", i);
		self.hydraulics[i] = {};
		self.hydraulics[i].node = Utils.indexToObject(self.components, getXMLString(xmlFile, hydraulicName .. "#index"));
		self.hydraulics[i].punch = Utils.indexToObject(self.components, getXMLString(xmlFile, hydraulicName .. "#punch"));
		self.hydraulics[i].translationPunch = Utils.indexToObject(self.components, getXMLString(xmlFile, hydraulicName .. "#punchFixpoint"));
		self.hydraulics[i].fixPoint = Utils.indexToObject(self.components, getXMLString(xmlFile, hydraulicName .. "#fixpoint"));
		local xUp, yUp, zUp = Utils.getVectorFromString(Utils.getNoNil(getXMLString(xmlFile, hydraulicName .. "#upVectors"),"0 1 0"));
		self.hydraulics[i].upVectors = {xUp, yUp, zUp};

		local ax, ay, az;
		if self.hydraulics[i].punch ~= nil then
			ax, ay, az = getWorldTranslation(self.hydraulics[i].punch);
		else
			ax, ay, az = getWorldTranslation(self.hydraulics[i].node);
		end;
		if self.hydraulics[i].translationPunch ~= nil then
			local bx, by, bz = getWorldTranslation(self.hydraulics[i].translationPunch);
			self.hydraulics[i].punchDistance = Utils.vector3Length(ax-bx, ay-by, az-bz);
		end;
	end;
	self.setHydraulicTime = 30;
    self.setHydraulicDirection = SpecializationUtil.callSpecializationsFunction("setHydraulicDirection");
     self.otworz = false
	self.zamknij = false
	
	bieg1SoundFile = Utils.getFilename("bieg.wav", self.baseDirectory);
    self.bieg1SoundId = createSample("LizardHor12nSound");
    loadSample(self.bieg1SoundId, bieg1SoundFile, false);
    self.bieg1Playing = false;
	
	bieg2SoundFile = Utils.getFilename("bieg.wav", self.baseDirectory);
    self.bieg2SoundId = createSample("LizardHor12nSound");
    loadSample(self.bieg2SoundId, bieg2SoundFile, false);
    self.bieg2Playing = false;
	
	bieg3SoundFile = Utils.getFilename("bieg.wav", self.baseDirectory);
    self.bieg3SoundId = createSample("LizardHor12nSound");
    loadSample(self.bieg3SoundId, bieg3SoundFile, false);
    self.bieg3Playing = false;
	
	bieg4SoundFile = Utils.getFilename("bieg.wav", self.baseDirectory);
    self.bieg4SoundId = createSample("LizardHor12nSound");
    loadSample(self.bieg4SoundId, bieg4SoundFile, false);
    self.bieg4Playing = false;
	
	biegRSoundFile = Utils.getFilename("bieg1.wav", self.baseDirectory);
    self.biegRSoundId = createSample("LizardHor12nSound");
    loadSample(self.biegRSoundId, biegRSoundFile, false);
    self.biegRPlaying = false;
	
	maska_upSoundFile = Utils.getFilename("maska_up.wav", self.baseDirectory);
    self.maska_upSoundId = createSample("LizardHor12nSound");
    loadSample(self.maska_upSoundId, maska_upSoundFile, false);
    self.maska_upPlaying = false;
	
	maska_downSoundFile = Utils.getFilename("maska_down.wav", self.baseDirectory);
    self.maska_downSoundId = createSample("LizardHor12nSound");
    loadSample(self.maska_downSoundId, maska_downSoundFile, false);
    self.maska_downPlaying = false;
	
	podnosnikSoundFile = Utils.getFilename("podnosnik.wav", self.baseDirectory);
    self.podnosnikSoundId = createSample("LizardHor12nSound");
    loadSample(self.podnosnikSoundId, podnosnikSoundFile, false);
    self.podnosnikPlaying = false;
	
	wycieraczkaSoundFile = Utils.getFilename("wycieraczka.wav", self.baseDirectory);
    self.wycieraczkaSoundId = createSample("LizardHor12nSound");
    loadSample(self.wycieraczkaSoundId, wycieraczkaSoundFile, false);
    self.wycieraczkaPlaying = false;
	
	pstrykSoundFile = Utils.getFilename("pstryk.wav", self.baseDirectory);
    self.pstrykSoundId = createSample("LizardHor12nSound");
    loadSample(self.pstrykSoundId, pstrykSoundFile, false);
    self.pstrykPlaying = false;
	
	pstryk1SoundFile = Utils.getFilename("pstryk.wav", self.baseDirectory);
    self.pstryk1SoundId = createSample("LizardHor12nSound");
    loadSample(self.pstryk1SoundId, pstryk1SoundFile, false);
    self.pstryk1Playing = false;
	
	otworzdrzwiSoundFile = Utils.getFilename("otworzdrzwi.wav", self.baseDirectory);
    self.otworzdrzwiSoundId = createSample("LizardHor12nSound");
    loadSample(self.otworzdrzwiSoundId, otworzdrzwiSoundFile, false);
    self.otworzdrzwiPlaying = false;
	
	zamknijdrzwiSoundFile = Utils.getFilename("zamknijdrzwi.wav", self.baseDirectory);
    self.zamknijdrzwiSoundId = createSample("LizardHor12nSound");
    loadSample(self.zamknijdrzwiSoundId, zamknijdrzwiSoundFile, false);
    self.zamknijdrzwiPlaying = false;
	
	otworzdrzwi1SoundFile = Utils.getFilename("otworzdrzwi.wav", self.baseDirectory);
    self.otworzdrzwi1SoundId = createSample("LizardHor12nSound");
    loadSample(self.otworzdrzwi1SoundId, otworzdrzwi1SoundFile, false);
    self.otworzdrzwi1Playing = false;
	
	zamknijdrzwi1SoundFile = Utils.getFilename("zamknijdrzwi.wav", self.baseDirectory);
    self.zamknijdrzwi1SoundId = createSample("LizardHor12nSound");
    loadSample(self.zamknijdrzwi1SoundId, zamknijdrzwi1SoundFile, false);
    self.zamknijdrzwi1Playing = false;
	
	dach_upSoundFile = Utils.getFilename("dach_up.wav", self.baseDirectory);
    self.dach_upSoundId = createSample("LizardHor12nSound");
    loadSample(self.dach_upSoundId, dach_upSoundFile, false);
    self.dach_upPlaying = false;
	
	dach_downSoundFile = Utils.getFilename("dach_down.wav", self.baseDirectory);
    self.dach_downSoundId = createSample("LizardHor12nSound");
    loadSample(self.dach_downSoundId, dach_downSoundFile, false);
    self.dach_downPlaying = false;

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

   if isDown and sym == Input.KEY_0 then
		self.pomoc = not self.pomoc;
	end;
	
	if isDown and sym == Input.KEY_l then
		self.wycieraczka = not self.wycieraczka;
	end;
	
	if isDown and sym == Input.KEY_b then
		self.Przekaznik = not self.Przekaznik;
	end;
	
	if isDown and sym == Input.KEY_l then
		self.wlacznik = not self.wlacznik;
	end;
	
	if isDown and sym == Input.KEY_b then
		self.wajcha = not self.wajcha;
	end;
  
end;


function Ursus360NN:update(dt)

        local nearestDistance = 1.5;
		local vx, vy, vz = getWorldTranslation(g_currentMission.player.rootNode);
	
		
		local px, py, pz = getWorldTranslation(self.klapalewa); 
		local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);	
		if distance < nearestDistance then
			self.przyklapiel = true; 
		else
			self.przyklapiel = false; 
		end;
		
		local rx, ry, rz = getWorldTranslation(self.klapaprawa); 
		local distance = Utils.vector3Length(rx-vx, ry-vy, rz-vz);	
		if distance < nearestDistance then
			self.przyklapiep = true; 
		else
			self.przyklapiep = false; 
		end; 
		
		local sx, sy, sz = getWorldTranslation(self.zaczep); 
		local distance = Utils.vector3Length(sx-vx, sy-vy, sz-vz);	
		if distance < nearestDistance then
			self.przyzaczepie = true; 
		else
			self.przyzaczepie = false; 
		end; 

		local tx, ty, tz = getWorldTranslation(self.Maska_1a); 
		local distance = Utils.vector3Length(tx-vx, ty-vy, tz-vz);	
		if distance < nearestDistance then
			self.przyMaska_1a = true; 
		else
			self.przyMaska_1a = false; 
		end; 
		
		
		local ux, uy, uz = getWorldTranslation(self.pompka); 
		local distance = Utils.vector3Length(ux-vx, uy-vy, uz-vz);	
		if distance < nearestDistance then
			self.przypompka = true; 
		else
			self.przypompka = false; 
		end; 
		
		local wx, wy, wz = getWorldTranslation(self.bolec1); 
		local distance = Utils.vector3Length(wx-vx, wy-vy, wz-vz);	
		if distance < nearestDistance then
			self.przybolec1 = true; 
		else
			self.przybolec1 = false; 
		end; 
		
		local ax, ay, az = getWorldTranslation(self.bolec2); 
		local distance = Utils.vector3Length(ax-vx, ay-vy, az-vz);	
		if distance < nearestDistance then
			self.przybolec2 = true; 
		else
			self.przybolec2 = false; 
		end; 
	
		
		
--------drzwi----------------
	if self.przyklapiep or self.isEntered then
	if InputBinding.hasEvent(InputBinding.PRAWE) then
			if self.animationParts[1].clipEndTime then
				self:setAnimationTime(1, self.animationParts[1].offSet);
				self.sound11 = true;
				self.sound12 = false;
			elseif self.animationParts[1].clipStartTime then
				self:setAnimationTime(1, self.animationParts[1].animDuration);
				self.sound12 = true;
				self.sound11 = false;
			end;
		end;
	end;
	
	if self.przyklapiel or self.isEntered then
	if InputBinding.hasEvent(InputBinding.LEWE) then
			if self.animationParts[2].clipEndTime then
				self:setAnimationTime(2, self.animationParts[2].offSet);
				self.sound13 = true;
				self.sound14 = false;
			elseif self.animationParts[2].clipStartTime then
				self:setAnimationTime(2, self.animationParts[2].animDuration);
				self.sound14 = true;
				self.sound13 = false;
			end;
		end;
	end;
	
	--Maska--
	if self.przyMaska_1a then
		if InputBinding.hasEvent(InputBinding.Maska_1a) then
			if self.animationParts[8].clipEndTime then
				self:setAnimationTime(8, self.animationParts[8].offSet);
			elseif self.animationParts[8].clipStartTime then
				self:setAnimationTime(8, self.animationParts[8].animDuration);
			end;
		end;
	end;
	--Klapka1--
	if self.isEntered then
		if InputBinding.hasEvent(InputBinding.Maska_1b) then
			if self.animationParts[9].clipEndTime then
				self:setAnimationTime(9, self.animationParts[9].offSet);
			elseif self.animationParts[9].clipStartTime then
				self:setAnimationTime(9, self.animationParts[9].animDuration);
			end;
		end;
	end;
	--klapka2--
	if self.przyMaska_1c then
		if InputBinding.hasEvent(InputBinding.Maska_1c) then
			if self.animationParts[10].clipEndTime then
				self:setAnimationTime(10, self.animationParts[10].offSet);
			elseif self.animationParts[10].clipStartTime then
				self:setAnimationTime(10, self.animationParts[10].animDuration);
			end;
		end;
	end;
	--dach-	
	if self.isEntered then				
		if InputBinding.hasEvent(InputBinding.DACH) then
			if self.animationParts[4].clipEndTime then
				self:setAnimationTime(4, self.animationParts[4].offSet);
				self.sound15 = true;
				self.sound16 = false;
			elseif self.animationParts[4].clipStartTime then
				self:setAnimationTime(4, self.animationParts[4].animDuration);
				self.sound16 = true;
				self.sound15 = false;
			end;
		end;
	--szyba--
		if InputBinding.hasEvent(InputBinding.SZYBA) then
			if self.animationParts[3].clipEndTime then
				self:setAnimationTime(3, self.animationParts[3].offSet);
			elseif self.animationParts[3].clipStartTime then
				self:setAnimationTime(3, self.animationParts[3].animDuration);
			end;
		end;
	--podnosnik
		if InputBinding.isPressed(InputBinding.PODW) then
               self:setAnimationTime(6, self.animationParts[6].currentPosition+(self.animationParts[6].offSet+dt), false);
           elseif InputBinding.isPressed(InputBinding.PODN) then
               self:setAnimationTime(6, self.animationParts[6].currentPosition-(self.animationParts[6].offSet+dt), false);
        end;
       end;
	--zaczep--
	if self.przyzaczepie then
	 	if InputBinding.isPressed(InputBinding.zaczepP) then
               self:setAnimationTime(5, self.animationParts[5].currentPosition+(self.animationParts[5].offSet+dt), false);
           elseif InputBinding.isPressed(InputBinding.zaczepL) then
               self:setAnimationTime(5, self.animationParts[5].currentPosition-(self.animationParts[5].offSet+dt), false);
        end;
        end;
	--wycieraczkatyl--	
	if self.isEntered then
	 	if InputBinding.isPressed(InputBinding.wycieraczka_2L) then
               self:setAnimationTime(13, self.animationParts[13].currentPosition+(self.animationParts[13].offSet+dt), false);
           elseif InputBinding.isPressed(InputBinding.wycieraczka_2P) then
               self:setAnimationTime(13, self.animationParts[13].currentPosition-(self.animationParts[13].offSet+dt), false);
        end;
        end;
		--pompka--
	if self.przypompka then
	 	if InputBinding.isPressed(InputBinding.pompkaup) then
               self:setAnimationTime(32, self.animationParts[32].currentPosition+(self.animationParts[32].offSet+dt), false);
           elseif InputBinding.isPressed(InputBinding.pompkadown) then
               self:setAnimationTime(32, self.animationParts[32].currentPosition-(self.animationParts[32].offSet+dt), false);
        end;
        end;
			--gabka--
	if self.isEntered then
	 	if InputBinding.isPressed(InputBinding.gabkaup) then
               self:setAnimationTime(33, self.animationParts[33].currentPosition+(self.animationParts[33].offSet+dt), false);
           elseif InputBinding.isPressed(InputBinding.gabkadown) then
               self:setAnimationTime(33, self.animationParts[33].currentPosition-(self.animationParts[33].offSet+dt), false);
        end;
        end;
	
		
	if self.setAnimationTime ~= nil then
		if self.isMotorStarted then
			self:setAnimationTime(7, 1);
		else
			self:setAnimationTime(7, 0);
		end;
		end;
		if self.setAnimationTime ~= nil then
		if self.isMotorStarted then
			self:setAnimationTime(11, 1);
		else
			self:setAnimationTime(11, 0);
		end;
		if self.isMotorStarted then
			self:setAnimationTime(12, 1);
		else
			self:setAnimationTime(12, 0);
		end;
		if self.wycieraczka then
           self:setAnimationTime(14, 1);
		   self.sound8 = true;
        else
           self:setAnimationTime(14, 0);
		   self.sound8 = false;
        end;
		if self.Przekaznik then
           self:setAnimationTime(15, 1);
        else
           self:setAnimationTime(15, 0);
        end;
		end;
		if self.setAnimationTime ~= nil then
	    if self.isMotorStarted then
			self:setAnimationTime(17,self.animationParts[17].animDuration);
		else
			self:setAnimationTime(17,self.animationParts[17].offSet);
		end;
		 if self.lastSpeed*3600 > 3 then
			self:setAnimationTime(18,self.animationParts[18].animDuration);
		else
			self:setAnimationTime(18,self.animationParts[18].offSet);
		end;
		 if self.lastSpeed*3600 > 6 then
			self:setAnimationTime(19,self.animationParts[19].animDuration);
		else
			self:setAnimationTime(19,self.animationParts[19].offSet);
		end;
		 if self.lastSpeed*3600 > 9 then
			self:setAnimationTime(20,self.animationParts[20].animDuration);
		else
			self:setAnimationTime(20,self.animationParts[20].offSet);
		end;
		 if self.lastSpeed*3600 > 12 then
			self:setAnimationTime(21,self.animationParts[21].animDuration);
		else
			self:setAnimationTime(21,self.animationParts[21].offSet);
		end;
		if self.lastSpeed*3600 > 15 then
			self:setAnimationTime(22,self.animationParts[22].animDuration);
		else
			self:setAnimationTime(22,self.animationParts[22].offSet);
		end;
		 if self.lastSpeed*3600 > 18 then
			self:setAnimationTime(23,self.animationParts[23].animDuration);
		else
			self:setAnimationTime(23,self.animationParts[23].offSet);
		end;
		if self.lastSpeed*3600 > 21 then
			self:setAnimationTime(24,self.animationParts[24].animDuration);
		else
			self:setAnimationTime(24,self.animationParts[24].offSet);
		end;
		 if self.lastSpeed*3600 > 24 then
			self:setAnimationTime(25,self.animationParts[25].animDuration);
		else
			self:setAnimationTime(25,self.animationParts[25].offSet);
		end;
		if self.lastSpeed*3600 > 27 then
			self:setAnimationTime(26,self.animationParts[26].animDuration);
		else
			self:setAnimationTime(26,self.animationParts[26].offSet);
		end;
		 if self.lastSpeed*3600 > 30 then
			self:setAnimationTime(27,self.animationParts[27].animDuration);
		else
			self:setAnimationTime(27,self.animationParts[27].offSet);
		end;
		if self.lastSpeed*3600 > 25 then
			self:setAnimationTime(28,self.animationParts[28].animDuration);
		else
			self:setAnimationTime(28,self.animationParts[28].offSet);
		end;
		if self.isMotorStarted then
			self:setAnimationTime(29,self.animationParts[29].animDuration);
		else
			self:setAnimationTime(29,self.animationParts[29].offSet);
		end;
		if self.hamuj then
			self:setAnimationTime(30,self.animationParts[30].animDuration);
		else
			self:setAnimationTime(30,self.animationParts[30].offSet);
		end;
		if self.isEntered then
		if self.wlacznik then
			self:setAnimationTime(31,self.animationParts[31].animDuration);
			self.sound9 = true;
			self.sound10 = false;
		else
			self:setAnimationTime(31,self.animationParts[31].offSet);
			self.sound9 = false;
			self.sound10 = true;
		end;
		end;
		if self.wajcha then
			self:setAnimationTime(16,self.animationParts[16].animDuration);
		else
			self:setAnimationTime(16,self.animationParts[16].offSet);
		end;
	end;
	
	
	                         --- gearBox marcello1942---		
		
		if self.motor.speedLevel == 4 then
			self:setAnimationTime(38,self.animationParts[38].animDuration);
			self.two = false;
			self.three = false;
			self.one = false;
			self.rear = false;
			self.sound4 = true;
		else
			self:setAnimationTime(38,self.animationParts[38].offSet);
			self.sound4 = false;
		end;
		if self.isEntered then
		if self.motor.speedLevel == 3 or Input.isKeyPressed(Input.KEY_w) then
			self:setAnimationTime(37,self.animationParts[37].animDuration);
			self.two = false;
			self.one = false;
			self.four = false;
			self.rear = false;
			self.sound3 = true;
		else
			self:setAnimationTime(37,self.animationParts[37].offSet);
			self.sound3 = false;
		end;
		end;
		if self.motor.speedLevel == 2 then
			self:setAnimationTime(36,self.animationParts[36].animDuration);
			self.one = false;
			self.three = false;
			self.four = false;
			self.rear = false;
			self.sound2 = true;
		else
			self:setAnimationTime(36,self.animationParts[36].offSet);
			self.sound2 = false;
		end;
		if self.isEntered then
		if self.motor.speedLevel == 1 then
			self:setAnimationTime(35,self.animationParts[35].animDuration);
			self.two = false;
			self.three = false;
			self.four = false;
			self.rear = false;
			self.sound1 = true;
		else
			self:setAnimationTime(35,self.animationParts[35].offSet);
			self.sound1 = false;
		end;
		end;
		
		if self.isMotorStarted then
		if self.isEntered then
		if Input.isKeyPressed(Input.KEY_s) then
		   self:setAnimationTime(39,self.animationParts[39].animDuration);
		   self.two = false;
		   self.three = false;
		   self.four = false;
		   self.one = false;
		   self.sound7 = true;
		else 
		   self:setAnimationTime(39,self.animationParts[39].offSet);
		   self.sound7 = false;
		end;
		end;
		end;
		
				
        if self.front then
			self.two = false;
			self.one = false;
			self.four = false;
		end;
		
		if self.backward then
		    self.one = false;
			self.two = false;
			self.four = false;
			self.three = false;
		end;
		
		if Input.isKeyPressed(Input.KEY_1) or Input.isKeyPressed(Input.KEY_2) or Input.isKeyPressed(Input.KEY_3) or Input.isKeyPressed(Input.KEY_4) then
		   self:setAnimationTime(40,self.animationParts[40].animDuration);
		else 
		   self:setAnimationTime(40,self.animationParts[40].offSet); 
		end;
		if self.isEntered then
		if Input.isKeyPressed(Input.KEY_w) or Input.isKeyPressed(Input.KEY_s) then
		   self:setAnimationTime(41,self.animationParts[41].animDuration);
		else 
		   self:setAnimationTime(41,self.animationParts[41].offSet); 
		end;
		end;
		
	  --klapka--
	  
	  if self.isMotorStarted then
		 setVisibility((self.klapkaoff), false);
		 setVisibility((self.klapkaon), true);
		 else
		 setVisibility((self.klapkaoff), true);
		 setVisibility((self.klapkaon), false);
	  end;
	  
	  ---bolce---
	  
	  if self.przybolec1 then
	  if Input.isKeyPressed(Input.KEY_q) then
	     setVisibility((self.bolec1), false);
		 else
		 setVisibility((self.bolec1), true);
	  end;
	  end;
	  
	  if self.przybolec2 then
	  if Input.isKeyPressed(Input.KEY_q) then
	     setVisibility((self.bolec2), false);
	     else
		 setVisibility((self.bolec2), true);
	  end;
	  end;
	  
	  
	  --napisy
		if self.przyzaczepie then
			g_currentMission:addExtraPrintText(string.format("%s: zaczep prawo", InputBinding.getKeyNamesOfDigitalAction(InputBinding.zaczepP)));
			g_currentMission:addExtraPrintText(string.format("%s: zaczep lewo", InputBinding.getKeyNamesOfDigitalAction(InputBinding.zaczepL)));
		end;
		if self.przyklapiel then
	    if self.animationParts[2].clipStartTime then
			g_currentMission:addExtraPrintText(string.format("%s: otworz Drzwi", InputBinding.getKeyNamesOfDigitalAction(InputBinding.LEWE)));
		else
			g_currentMission:addExtraPrintText(string.format("%s: zamknij Drzwi", InputBinding.getKeyNamesOfDigitalAction(InputBinding.LEWE)));
		end;
		end;
		if self.przyklapiep then
	    if self.animationParts[1].clipStartTime then
			g_currentMission:addExtraPrintText(string.format("%s: otworz Drzwi", InputBinding.getKeyNamesOfDigitalAction(InputBinding.PRAWE)));
		else
			g_currentMission:addExtraPrintText(string.format("%s: zamknij Drzwi", InputBinding.getKeyNamesOfDigitalAction(InputBinding.PRAWE)));
		end;
		end
		if self.przyMaska_1a then
	    if self.animationParts[8].clipStartTime then
			g_currentMission:addExtraPrintText(string.format("%s: otworz Maske", InputBinding.getKeyNamesOfDigitalAction(InputBinding.Maska_1a)));
		else
			g_currentMission:addExtraPrintText(string.format("%s: zamknij Maske", InputBinding.getKeyNamesOfDigitalAction(InputBinding.Maska_1a)));
		end;
		end
		if self.przypompka then
			g_currentMission:addExtraPrintText(string.format("%s: pompka up", InputBinding.getKeyNamesOfDigitalAction(InputBinding.pompkaup)));
			g_currentMission:addExtraPrintText(string.format("%s: pompka down", InputBinding.getKeyNamesOfDigitalAction(InputBinding.pompkadown)));
		end;
	  
	  

			if self:getIsActive() then
		self.setHydraulicTime = 30;
	end;


	if self.setHydraulicTime > 0 then
		for k,v in pairs(self.hydraulics) do
			self:setHydraulicDirection(k);
		end;
		self.setHydraulicTime = self.setHydraulicTime - 1;
	end;
	
	
	
		if self.sound1 then
       if not self.bieg1Playing then
            playSample(self.bieg1SoundId, 1, 3, 3);
            self.bieg1Playing = true;
        end;
       
    else
        if self.bieg1Playing then
            stopSample(self.bieg1SoundId);
            self.bieg1Playing = false;
        end;
         
    end;
	
	if self.sound2 then
       if not self.bieg2Playing then
            playSample(self.bieg2SoundId, 1, 3, 3);
            self.bieg2Playing = true;
        end;
       
    else
        if self.bieg2Playing then
            stopSample(self.bieg2SoundId);
            self.bieg2Playing = false;
        end;
         
    end;
	
	if self.sound3 then
       if not self.bieg3Playing then
            playSample(self.bieg3SoundId, 1, 3, 3);
            self.bieg3Playing = true;
        end;
       
    else
        if self.bieg3Playing then
            stopSample(self.bieg3SoundId);
            self.bieg3Playing = false;
        end;
         
    end;
	
	if self.sound4 then
       if not self.bieg4Playing then
            playSample(self.bieg4SoundId, 1, 3, 3);
            self.bieg4Playing = true;
        end;
       
    else
        if self.bieg4Playing then
            stopSample(self.bieg4SoundId);
            self.bieg4Playing = false;
        end;
         
    end;
	
	if self.sound5 then
       if not self.maska_upPlaying then
            playSample(self.maska_upSoundId, 1, 3, 3);
            self.maska_upPlaying = true;
        end;
       
    else
        if self.maska_upPlaying then
            stopSample(self.maska_upSoundId);
            self.maska_upPlaying = false;
        end;
         
    end;
	
	if self.sound6 then
       if not self.maska_downPlaying then
            playSample(self.maska_downSoundId, 1, 3, 3);
            self.maska_downPlaying = true;
        end;
       
    else
        if self.maska_downPlaying then
            stopSample(self.maska_downSoundId);
            self.maska_downPlaying = false;
        end;
         
    end;
	
	if self.isEntered then					   
	   if Input.isKeyPressed(Input.KEY_pageup) or Input.isKeyPressed(Input.KEY_pagedown) then
       if not self.podnosnikPlaying then
            playSample(self.podnosnikSoundId, 0, 1, 0);
            self.podnosnikPlaying = true;
        end;
       
    else
        if self.podnosnikPlaying then
            stopSample(self.podnosnikSoundId);
            self.podnosnikPlaying = false;
        end;
         
    end;
	end;
	
	if self.sound7 then
       if not self.biegRPlaying then
            playSample(self.biegRSoundId, 1, 3, 3);
            self.biegRPlaying = true;
        end;
       
    else
        if self.biegRPlaying then
            stopSample(self.biegRSoundId);
            self.biegRPlaying = false;
        end;
         
    end;
	
	if self.sound8 then
       if not self.wycieraczkaPlaying then
            playSample(self.wycieraczkaSoundId, 0, 1, 0);
            self.wycieraczkaPlaying = true;
        end;
       
    else
        if self.wycieraczkaPlaying then
            stopSample(self.wycieraczkaSoundId);
            self.wycieraczkaPlaying = false;
        end;
         
    end;
	
	if self.sound9 then
       if not self.pstrykPlaying then
            playSample(self.pstrykSoundId, 1, 3, 3);
            self.pstrykPlaying = true;
        end;
       
    else
        if self.pstrykPlaying then
            stopSample(self.pstrykSoundId);
            self.pstrykPlaying = false;
        end;
         
    end;
	
	if self.sound10 then
       if not self.pstryk1Playing then
            playSample(self.pstryk1SoundId, 1, 3, 3);
            self.pstryk1Playing = true;
        end;
       
    else
        if self.pstryk1Playing then
            stopSample(self.pstryk1SoundId);
            self.pstryk1Playing = false;
        end;
         
    end;
	
	if self.sound11 then
       if not self.otworzdrzwiPlaying then
            playSample(self.otworzdrzwiSoundId, 1, 3, 3);
            self.otworzdrzwiPlaying = true;
        end;
       
    else
        if self.otworzdrzwiPlaying then
            stopSample(self.otworzdrzwiSoundId);
            self.otworzdrzwiPlaying = false;
        end;
         
    end;
	
	if self.sound12 then
       if not self.zamknijdrzwiPlaying then
            playSample(self.zamknijdrzwiSoundId, 1, 3, 3);
            self.zamknijdrzwiPlaying = true;
        end;
       
    else
        if self.zamknijdrzwiPlaying then
            stopSample(self.zamknijdrzwiSoundId);
            self.zamknijdrzwiPlaying = false;
        end;
         
    end;
	
	if self.sound13 then
       if not self.otworzdrzwi1Playing then
            playSample(self.otworzdrzwi1SoundId, 1, 3, 3);
            self.otworzdrzwi1Playing = true;
        end;
       
    else
        if self.otworzdrzwi1Playing then
            stopSample(self.otworzdrzwi1SoundId);
            self.otworzdrzwi1Playing = false;
        end;
         
    end;
	
	if self.sound14 then
       if not self.zamknijdrzwi1Playing then
            playSample(self.zamknijdrzwi1SoundId, 1, 3, 3);
            self.zamknijdrzwi1Playing = true;
        end;
       
    else
        if self.zamknijdrzwi1Playing then
            stopSample(self.zamknijdrzwi1SoundId);
            self.zamknijdrzwi1Playing = false;
        end;
         
    end;
	
	if self.sound15 then
       if not self.dach_upPlaying then
            playSample(self.dach_upSoundId, 1, 3, 3);
            self.dach_upPlaying = true;
        end;
       
    else
        if self.dach_upPlaying then
            stopSample(self.dach_upSoundId);
            self.dach_upPlaying = false;
        end;
         
    end;
	
	if self.sound16 then
       if not self.dach_downPlaying then
            playSample(self.dach_downSoundId, 1, 3, 3);
            self.dach_downPlaying = true;
        end;
       
    else
        if self.dach_downPlaying then
            stopSample(self.dach_downSoundId);
            self.dach_downPlaying = false;
        end;
         
    end;
	
end;


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

function Ursus360NN:validateAttacherJoint(implement, jointDesc, dt)
    return true;
end;
function Ursus360NN:setHydraulicDirection(index)
	local hydraulic = self.hydraulics[index];

	if hydraulic.fixPoint ~= nil then
		local ax, ay, az = getWorldTranslation(hydraulic.node);
		local bx, by, bz = getWorldTranslation(hydraulic.fixPoint);
		local x, y, z = worldDirectionToLocal(getParent(hydraulic.node), bx-ax, by-ay, bz-az);
		local xUp, yUp, zUp = unpack(hydraulic.upVectors);
		setDirection(hydraulic.node, x, y, z, xUp, yUp, zUp);
		if hydraulic.punch ~= nil then
			local distance = Utils.vector3Length(ax-bx, ay-by, az-bz);
			setTranslation(hydraulic.punch, 0, 0, distance-hydraulic.punchDistance);
		end;
	end;
end;
function Ursus360NN:draw()

    if self.isEntered then
		if not self.pomoc then
			renderText(0.833, 0.175, 0.02, "Wcisnij 0: Pokaz pomoc");
		else
			renderText(0.833, 0.175, 0.02, "Wcisnij 0: Schowaj pomoc");
		end;
		if self.pomoc then
			renderText(0.72, 0.85, 0.025, "----->Ursus c 360<-----");
			if not self.isMotorStarted then
			renderText(0.72, 0.825, 0.02, " Z: odpal 60-ke");
			else
			renderText(0.72, 0.825, 0.02, " Z: zgas 60-ke");
			end;
	
	
		    renderText(0.72, 0.8, 0.02, "drzwi lewe: N ");
	
		
			renderText(0.72, 0.775, 0.02, "drzwi prawe: M ");
	
		
			renderText(0.72, 0.75, 0.02, "dach: T ");
         
           
			renderText(0.72, 0.725, 0.02, "Kierunkowskazy: Num 1/2/3 ");
	
		
			renderText(0.72, 0.7, 0.02, "Tylny podnosnik up: PgDown ");
			
		
			renderText(0.72, 0.675, 0.02, "Tylny podnosnik down: PgDown ");
			
			
			renderText(0.72, 0.650, 0.02, "halogeny: 7,8,9 ");
			
			
			renderText(0.72, 0.625, 0.02, "zaczep  prawo: X, lewo: Z ");
			
			
			renderText(0.72, 0.600, 0.02, "pompka  up: Z,  down: X ");
			
		if not self.wycieraczka then
			renderText(0.72, 0.575, 0.02, "wycieraczka ON : L ");
			else
			renderText(0.72, 0.575, 0.02, "wycieraczka OFF : L ");
			end;
			
			
			renderText(0.72, 0.550, 0.02, "wycieraczka tyl:  prawo: K, lewo: J ");
			
			
			renderText(0.72, 0.525, 0.02, "gabka  up: U,  down: Y ");
			
			
			renderText(0.72, 0.500, 0.02, "maska: J ");
			
			
			renderText(0.72, 0.475, 0.02, "dodaj, zmniejsz gaz: Num_plus, Num_minus ");
			
			
			renderText(0.72, 0.450, 0.02, "zaloz belke: X ");
			
			
			renderText(0.72, 0.425, 0.022, "----->MARCELLO 1942<-----");
		end;
	end;	
end;