--Specjalizacja--
--For--
--Massey Ferguson 255--
--by--
--siudix29&Nunek--


MF255 = {};


function MF255.prerequisitesPresent(specializations)
   return true;
end;

function MF255:load(xmlFile)
	---------------------Drzwi_P---------------------------------------
	local Drzwi_P = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Drzwi_P#index"));
	if Drzwi_P ~= nil then
		self.Drzwi_P = Drzwi_P;
	end;
	---------------------Drzwi_L------------------------------------------
	local Drzwi_L = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Drzwi_L#index"));
	if Drzwi_L ~= nil then
		self.Drzwi_L = Drzwi_L;
	end;
	---------------------Szyba------------------------------------------
	local Szyba = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Szyba#index"));
	if Szyba ~= nil then
		self.Szyba = Szyba;
	end;
	---------------------ciegno------------------------------------------
	local ciegno = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.ciegno#index"));
	if ciegno ~= nil then
		self.ciegno = ciegno;
	end;
	---------------------TUZ------------------------------------------
	local TUZ = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.TUZ#index"));
	if TUZ ~= nil then
		self.TUZ = TUZ;
	end;
		---------------------bieg1------------------------------------------
	local bieg1 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.bieg1#index"));
	if bieg1 ~= nil then
		self.bieg1 = bieg1;
	end;
		---------------------bieg2------------------------------------------
	local bieg2 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.bieg2#index"));
	if bieg2 ~= nil then
		self.bieg2 = bieg2;
	end;
		---------------------bieg3------------------------------------------
	local bieg3 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.bieg3#index"));
	if bieg3 ~= nil then
		self.bieg3 = bieg3;
	end;
		---------------------bieg4------------------------------------------
	local bieg4 = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.bieg4#index"));
	if bieg4 ~= nil then
		self.bieg4 = bieg4;
	end;
			---------------------wajchawalek------------------------------------------
	local wajchawalek = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.wajchawalek#index"));
	if wajchawalek ~= nil then
		self.wajchawalek = wajchawalek;
	end;
		---------------------hamulec------------------------------------------
	local hamulec = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.hamulec#index"));
	if hamulec ~= nil then
		self.hamulec = hamulec;
	end;
		---------------------dach------------------------------------------
	local dach = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.dach#index"));
	if dach ~= nil then
		self.dach = dach;
	end;
	---------------------lewy------------------------------------------
	local lewy = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.lewy#index"));
	if lewy ~= nil then
		self.lewy = lewy;
	end;
	---------------------prawy------------------------------------------
	local prawy = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.prawy#index"));
	if prawy ~= nil then
		self.prawy = prawy;
	end;
end;

 function MF255:delete()
end;

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

function MF255:update(dt)
		
	---------------------Drzwi_P---------------------------------------
	local nearestDistance = 2;
	local vx, vy, vz = getWorldTranslation(g_currentMission.player.rootNode);
    local px, py, pz = getWorldTranslation(self.Drzwi_P); ---Drzwi_P---
    local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);
	if distance < nearestDistance then
		self.przyDrzwi_P = true; 
	else
		self.przyDrzwi_P = false; 
	end;
 	
	if self.przyDrzwi_P or self.isEntered then
		if InputBinding.hasEvent(InputBinding.Drzwi_P) then
			if self.animationParts[1].clipEndTime then
				self:setAnimationTime(1, self.animationParts[1].offSet);
			elseif self.animationParts[1].clipStartTime then
				self:setAnimationTime(1, self.animationParts[1].animDuration);
			end;
		end;
	end;
	-----------------------Drzwi_L---------------------------------------------------------
	local nearestDistance = 2;
	local vx, vy, vz = getWorldTranslation(g_currentMission.player.rootNode);
	local px, py, pz = getWorldTranslation(self.Drzwi_L); 	---Drzwi_L---
	local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);
	if distance < nearestDistance then
		self.przyDrzwi_L= true; 
	else
		self.przyDrzwi_L = false; 
	end;
 
	if self.przyDrzwi_L or self.isEntered then
		if InputBinding.hasEvent(InputBinding.Drzwi_L) then
			if self.animationParts[2].clipEndTime then
				self:setAnimationTime(2, self.animationParts[2].offSet);
			elseif self.animationParts[2].clipStartTime then
				self:setAnimationTime(2, self.animationParts[2].animDuration);
			end;
		end;
	end;
		---------------------ciegno---------------------------------------
	local nearestDistance = 2;
	local vx, vy, vz = getWorldTranslation(g_currentMission.player.rootNode);
    local sx, sy, sz = getWorldTranslation(self.ciegno); ---ciegno---
    local distance = Utils.vector3Length(sx-vx, sy-vy, sz-vz);
	if distance < nearestDistance then
		self.przyciegno = true; 
	else
		self.przyciegno = false; 
	end;
 	
	if self.przyciegno then
		if InputBinding.hasEvent(InputBinding.ciegno) then
			if self.animationParts[15].clipEndTime then
				self:setAnimationTime(15, self.animationParts[15].offSet);
			elseif self.animationParts[15].clipStartTime then
				self:setAnimationTime(15, self.animationParts[15].animDuration);
			end;
		end;
	end;
	-----------------------Szyba---------------------------------------------------------
	if self.isEntered then
		if InputBinding.isPressed(InputBinding.szybaG) then
			self:setAnimationTime(4, self.animationParts[4].currentPosition+(self.animationParts[3].offSet+dt), false);
		elseif InputBinding.isPressed(InputBinding.szybaD) then
			self:setAnimationTime(4, self.animationParts[4].currentPosition-(self.animationParts[3].offSet+dt), false);
		end;
    end;
	-----------------------TUZ--------------------------------------------------------- 
	if self.isEntered then
		if InputBinding.hasEvent(InputBinding.LOWER_IMPLEMENT) then
			if self.animationParts[5].clipEndTime then
				self:setAnimationTime(5, self.animationParts[5].offSet);
			elseif self.animationParts[5].clipStartTime then
				self:setAnimationTime(5, self.animationParts[5].animDuration);
			end;
		end;
	end;
	-----------------------Biegi---------------------------------------------------------
	if self.isEntered then	
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL1) then
			if self.animationParts[6].clipEndTime then
				self:setAnimationTime(6, self.animationParts[6].offSet);
			elseif self.animationParts[6].clipStartTime then
				self:setAnimationTime(6, self.animationParts[6].animDuration);
			end;
		end;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL1) then
			if self.animationParts[7].clipEndTime then
				self:setAnimationTime(7, self.animationParts[7].offSet);
		    elseif	self.animationParts[6].clipStartTime then
				self:setAnimationTime(6, self.animationParts[6].animDuration);
	        end;
	    end;
	    if InputBinding.hasEvent(InputBinding.SPEED_LEVEL1) then
			if self.animationParts[8].clipEndTime then
				self:setAnimationTime(8, self.animationParts[8].offSet);
		    elseif	self.animationParts[6].clipStartTime then
				self:setAnimationTime(6, self.animationParts[6].animDuration);
	        end;
	    end;
	    if InputBinding.hasEvent(InputBinding.SPEED_LEVEL1) then
			if self.animationParts[9].clipEndTime then
				self:setAnimationTime(9, self.animationParts[9].offSet);
		    elseif	self.animationParts[6].clipStartTime then
				self:setAnimationTime(6, self.animationParts[6].animDuration);
	        end;
	    end;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL2) then
			if self.animationParts[7].clipEndTime then
				self:setAnimationTime(7, self.animationParts[7].offSet);
			elseif self.animationParts[7].clipStartTime then
				self:setAnimationTime(7, self.animationParts[7].animDuration);
			end;
		end;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL2) then
			if self.animationParts[6].clipEndTime then
				self:setAnimationTime(6, self.animationParts[6].offSet);
			elseif self.animationParts[7].clipStartTime then
				self:setAnimationTime(7, self.animationParts[7].animDuration);
	        end;
	    end;
	    if InputBinding.hasEvent(InputBinding.SPEED_LEVEL2) then
			if self.animationParts[9].clipEndTime then
				self:setAnimationTime(9, self.animationParts[9].offSet);
		    elseif	self.animationParts[7].clipStartTime then
				self:setAnimationTime(7, self.animationParts[7].animDuration);
	        end;
	    end;
	     if InputBinding.hasEvent(InputBinding.SPEED_LEVEL2) then
			if self.animationParts[8].clipEndTime then
				self:setAnimationTime(8, self.animationParts[8].offSet);
		    elseif	self.animationParts[7].clipStartTime then
				self:setAnimationTime(7, self.animationParts[7].animDuration);
	        end;
	    end;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL3) then
			if self.animationParts[6].clipEndTime then
				self:setAnimationTime(6, self.animationParts[6].offSet);
			elseif self.animationParts[8].clipStartTime then
				self:setAnimationTime(8, self.animationParts[8].animDuration);
			end;
		end;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL3) then
			if self.animationParts[7].clipEndTime then
				self:setAnimationTime(7, self.animationParts[7].offSet);
			elseif self.animationParts[8].clipStartTime then
				self:setAnimationTime(8, self.animationParts[8].animDuration);
			end;
		end;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL3) 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;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL3) then
			if self.animationParts[9].clipEndTime then
				self:setAnimationTime(9, self.animationParts[9].offSet);
		    elseif	self.animationParts[8].clipStartTime then
				self:setAnimationTime(8, self.animationParts[8].animDuration);
	        end;
	    end;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL4) 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;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL4) then
			if self.animationParts[6].clipEndTime then
				self:setAnimationTime(6, self.animationParts[6].offSet);
			elseif self.animationParts[9].clipStartTime then
				self:setAnimationTime(9, self.animationParts[9].animDuration);
			end;
		end;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL4) then
			if self.animationParts[7].clipEndTime then
				self:setAnimationTime(7, self.animationParts[7].offSet);
			elseif self.animationParts[9].clipStartTime then
				self:setAnimationTime(9, self.animationParts[9].animDuration);
			end;
		end;
		if InputBinding.hasEvent(InputBinding.SPEED_LEVEL4) then
			if self.animationParts[8].clipEndTime then
				self:setAnimationTime(8, self.animationParts[8].offSet);
			elseif self.animationParts[9].clipStartTime then
				self:setAnimationTime(9, self.animationParts[9].animDuration);
			end;
		end;
	end;
	       -----------------------hamulec---------------------------------------------------------
	if self.isEntered then	
		if InputBinding.hasEvent(InputBinding.hamulec) 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;
			if self.animationParts[6].clipEndTime then
				self:setAnimationTime(6, self.animationParts[6].offSet);
			elseif self.animationParts[10].clipStartTime then
				self:setAnimationTime(10, self.animationParts[10].animDuration);
	        end;
			if self.animationParts[7].clipEndTime then
				self:setAnimationTime(7, self.animationParts[7].offSet);
			elseif self.animationParts[10].clipStartTime then
				self:setAnimationTime(10, self.animationParts[10].animDuration);
			end;
			if self.animationParts[8].clipEndTime then
				self:setAnimationTime(8, self.animationParts[8].offSet);
			elseif self.animationParts[10].clipStartTime then
				self:setAnimationTime(10, self.animationParts[10].animDuration);
			end;
			if self.animationParts[9].clipEndTime then
				self:setAnimationTime(9, self.animationParts[9].offSet);
			elseif self.animationParts[10].clipStartTime then
				self:setAnimationTime(10, self.animationParts[10].animDuration);
	        end;
	    end;
	end;
	-----------------------gaz---------------------------------------------------------
	if self.isEntered then	
		if InputBinding.hasEvent(InputBinding.gaz) 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;
			if self.animationParts[6].clipEndTime then
				self:setAnimationTime(6, self.animationParts[6].offSet);
			elseif self.animationParts[10].clipStartTime then
				self:setAnimationTime(10, self.animationParts[10].animDuration);
	        end;
			if self.animationParts[7].clipEndTime then
				self:setAnimationTime(7, self.animationParts[7].offSet);
			elseif self.animationParts[10].clipStartTime then
				self:setAnimationTime(10, self.animationParts[10].animDuration);
			end;
			if self.animationParts[8].clipEndTime then
				self:setAnimationTime(8, self.animationParts[8].offSet);
			elseif self.animationParts[10].clipStartTime then
				self:setAnimationTime(10, self.animationParts[10].animDuration);
			end;
			if self.animationParts[9].clipEndTime then
				self:setAnimationTime(9, self.animationParts[9].offSet);
			elseif self.animationParts[10].clipStartTime then
				self:setAnimationTime(10, self.animationParts[10].animDuration);
	        end;
	    end;
	end;
			-----------------------wajchawalek---------------------------------------------------------
	if self.isEntered then
		if InputBinding.hasEvent(InputBinding.ACTIVATE_THRESHING) then
			if self.animationParts[11].clipEndTime then
				self:setAnimationTime(11, self.animationParts[11].offSet);
			elseif self.animationParts[11].clipStartTime then
				self:setAnimationTime(11, self.animationParts[11].animDuration);
			end;
		end;
	end;	
				-----------------------dach---------------------------------------------------------
	if self.isEntered then
		if InputBinding.isPressed(InputBinding.dachG) then
			self:setAnimationTime(12, self.animationParts[12].currentPosition+(self.animationParts[3].offSet+dt), false);
		elseif InputBinding.isPressed(InputBinding.dachD) then
			self:setAnimationTime(12, self.animationParts[12].currentPosition-(self.animationParts[3].offSet+dt), false);
		end;
    end;
		-----------------------lewy---------------------------------------------------------
	if self.isEntered then
		if InputBinding.hasEvent(InputBinding.lewy) then
			if self.animationParts[13].clipEndTime then
				self:setAnimationTime(13, self.animationParts[13].offSet);
			elseif self.animationParts[13].clipStartTime then
				self:setAnimationTime(13, self.animationParts[13].animDuration);
			end;
		end;
	end;
	if self.isEntered then
		if InputBinding.hasEvent(InputBinding.lewy) then
			if self.animationParts[14].clipEndTime then
				self:setAnimationTime(14, self.animationParts[14].offSet);
			elseif self.animationParts[13].clipStartTime then
				self:setAnimationTime(13, self.animationParts[13].animDuration);
			end;
		end;
	end;
		-----------------------prawy---------------------------------------------------------
	if self.isEntered then
		if InputBinding.hasEvent(InputBinding.prawy) then
			if self.animationParts[14].clipEndTime then
				self:setAnimationTime(14, self.animationParts[14].offSet);
			elseif self.animationParts[14].clipStartTime then
				self:setAnimationTime(14, self.animationParts[14].animDuration);
			end;
		end;
	end;
	if self.isEntered then
		if InputBinding.hasEvent(InputBinding.prawy) then
			if self.animationParts[13].clipEndTime then
				self:setAnimationTime(13, self.animationParts[13].offSet);
			elseif self.animationParts[14].clipStartTime then
				self:setAnimationTime(14, self.animationParts[14].animDuration);
			end;
		end;
	end;
    ---------------------Drzwi_P---------------------------------------	
	if self.przyDrzwi_P then
		if self.animationParts[1].clipStartTime then
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Otrowrz Drzwi")), InputBinding.Drzwi_P);
		else
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Zamknij Drzwi")), InputBinding.Drzwi_P);
		end;
	end;
	-----------------------Drzwi_L---------------------------------------------------------
	if self.przyDrzwi_L then
		if self.animationParts[2].clipStartTime then
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Otrowrz Drzwi")), InputBinding.Drzwi_L);
		else
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Zamknij Drzwi")), InputBinding.Drzwi_L);
		end;
	end;
	-----------------------ciegno---------------------------------------------------------
	if self.przyciegno then
		if self.animationParts[15].clipStartTime then
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Zdejmij ciegno")), InputBinding.ciegno);
		else
			g_currentMission:addHelpButtonText(string.format(g_i18n:getText("Zaloz ciegno")), InputBinding.ciegno);
		end;
	end;
end;

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

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

function MF255:draw()
end;