-- xyzspain

Kinze3800 = {};

function Kinze3800.prerequisitesPresent(specializations)
 -- return SpecializationUtil.hasSpecialization(Trailer, specializations) ;
	--- return SpecializationUtil.hasSpecialization(Fillable, specializations);
	return true;
end;

function Kinze3800:load(xmlFile)

 print("lua loaded Kinze3800" );
	---libertad bloques
	self.setJointRotLimit = SpecializationUtil.callSpecializationsFunction("setJointRotLimit");
	self.firstDo = {};
	self.arm = {};
	
	------------------------------
		--- ajuste orientacion attach
		self.doJointOrientation = false;
		self.attacherJointCopy = nil;
		self.updateJoint = false;

----------------------------------
	-- desplazamiento de conjuntos
	self.setHydraulicDirection = SpecializationUtil.callSpecializationsFunction("setHydraulicDirection");
	
	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 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;
		local bx, by, bz = getWorldTranslation(self.hydraulics[i].translationPunch);		
		self.hydraulics[i].punchDistance = Utils.vector3Length(ax-bx, ay-by, az-bz);
		self.hydraulics[i].doScale = Utils.getNoNil(getXMLBool(xmlFile, hydraulicName .. "#doScale"), false);
	end;
	-------------------
	local count = getXMLInt(xmlFile, "vehicle.rotationParts#count");
	if count ~= nil then
		self.rotationParts = {}
		local rotationPart = self.rotationParts;
		for i=1, count do
			local varName = string.format("rotationPart" .. "%d", i);
			rotationPart[varName] = {};
			local rotationPartname = string.format("vehicle.rotationParts.rotationPart" .. "%d", i);
			rotationPart[varName].index = Utils.indexToObject(self.components, getXMLString(xmlFile, rotationPartname .. "#index"));
			local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, rotationPartname .. "#minRot"));
			rotationPart[varName].minRot = {};
			rotationPart[varName].minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
			rotationPart[varName].minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
			rotationPart[varName].minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
			local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, rotationPartname .. "#maxRot"));
			rotationPart[varName].maxRot = {};
			rotationPart[varName].maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
			rotationPart[varName].maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
			rotationPart[varName].maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

			rotationPart[varName].rotTime = Utils.getNoNil(getXMLInt(xmlFile, rotationPartname .. "#rotTime"), 2)*1000;	
			rotationPart[varName].touchRotLimit = Utils.getNoNil(getXMLInt(xmlFile, rotationPartname .. "#touchRotLimit"), 1)/1000;	
		end;
	end;
 
		--------------------------
		local rotationNode1 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation1#index"));
    if rotationNode1 ~= nil then
        self.rotation1 = {};
        self.rotation1.node = rotationNode1;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation1#minRot"));
        self.rotation1.minRot = {};
        self.rotation1.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation1.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation1.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

        self.rotation1.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation1#rotTime"), 2)*1000;
     
    end;
		local rotationNode100 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation100#index"));
    if rotationNode100 ~= nil then
        self.rotation100 = {};
        self.rotation100.node = rotationNode100;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation100#minRot"));
        self.rotation100.minRot = {};
        self.rotation100.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation100.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation100.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

        self.rotation100.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation100#rotTime"), 2)*1000;
     
    end;
	 local rotationNode2 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation2#index"));
    if rotationNode2 ~= nil then
        self.rotation2 = {};
        self.rotation2.node = rotationNode2;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation2#minRot"));
        self.rotation2.minRot = {};
        self.rotation2.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation2.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation2.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation2.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation2#rotTime"), 2)*1000;
      
    end;
		 local rotationNode3 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation3#index"));
    if rotationNode3 ~= nil then
        self.rotation3 = {};
        self.rotation3.node = rotationNode3;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation3#minRot"));
        self.rotation3.minRot = {};
        self.rotation3.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation3.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation3.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation3.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation3#rotTime"), 2)*1000;
      
    end;
			 local rotationNode4 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation4#index"));
    if rotationNode4 ~= nil then
        self.rotation4 = {};
        self.rotation4.node = rotationNode4;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation4#minRot"));
        self.rotation4.minRot = {};
        self.rotation4.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation4.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation4.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation4.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation4#rotTime"), 2)*1000;
      
    end;
		 local rotationNode5 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation5#index"));
    if rotationNode5 ~= nil then
        self.rotation5 = {};
        self.rotation5.node = rotationNode5;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation5#minRot"));
        self.rotation5.minRot = {};
        self.rotation5.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation5.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation5.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation5.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation5#rotTime"), 2)*1000;
      
    end;
		 local rotationNode6 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation6#index"));
    if rotationNode6 ~= nil then
        self.rotation6 = {};
        self.rotation6.node = rotationNode6;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation6#minRot"));
        self.rotation6.minRot = {};
        self.rotation6.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation6.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation6.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation6.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation6#rotTime"), 2)*1000;
      
    end;
	
	 local rotationNode7 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation7#index"));
    if rotationNode7 ~= nil then
        self.rotation7 = {};
        self.rotation7.node = rotationNode7;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation7#minRot"));
        self.rotation7.minRot = {};
        self.rotation7.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation7.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation7.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation7.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation7#rotTime"), 2)*1000;
      
    end;
	 local rotationNode8 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation8#index"));
    if rotationNode8 ~= nil then
        self.rotation8 = {};
        self.rotation8.node = rotationNode8;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation8#minRot"));
        self.rotation8.minRot = {};
        self.rotation8.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation8.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation8.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation8.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation8#rotTime"), 2)*1000;
      
    end;
		 local rotationNode9 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation9#index"));
    if rotationNode9 ~= nil then
        self.rotation9 = {};
        self.rotation9.node = rotationNode9;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation9#minRot"));
        self.rotation9.minRot = {};
        self.rotation9.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation9.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation9.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation9.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation9#rotTime"), 2)*1000;
      
    end;
		 local rotationNode10 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation10#index"));
    if rotationNode10 ~= nil then
        self.rotation10 = {};
        self.rotation10.node = rotationNode10;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation10#minRot"));
        self.rotation10.minRot = {};
        self.rotation10.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation10.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation10.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation10.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation10#rotTime"), 2)*1000;
      
    end;
		 local rotationNode11 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation11#index"));
    if rotationNode11 ~= nil then
        self.rotation11 = {};
        self.rotation11.node = rotationNode11;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation11#minRot"));
        self.rotation11.minRot = {};
        self.rotation11.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation11.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation11.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation11.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation11#rotTime"), 2)*1000;
      
    end;
		 local rotationNode12 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation12#index"));
    if rotationNode12 ~= nil then
        self.rotation12 = {};
        self.rotation12.node = rotationNode12;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation12#minRot"));
        self.rotation12.minRot = {};
        self.rotation12.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation12.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation12.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation12.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation12#rotTime"), 2)*1000;
      
    end;
	local translationNode1 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.translation1#index"));
    if translationNode1 ~= nil then
        self.translation1 = {};
        self.translation1.node = translationNode1;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translation1#minTrans"));
        self.translation1.minTrans = {};
        self.translation1.minTrans[1] = Utils.getNoNil(x, 0);
        self.translation1.minTrans[2] = Utils.getNoNil(y, 0);
        self.translation1.minTrans[3] = Utils.getNoNil(z, 0);

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

	    self.translation1.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translation1#transTime"), 2)*1000;
      
    end;
	local translationNode2 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.translation2#index"));
    if translationNode2 ~= nil then
        self.translation2 = {};
        self.translation2.node = translationNode2;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translation2#minTrans"));
        self.translation2.minTrans = {};
        self.translation2.minTrans[1] = Utils.getNoNil(x, 0);
        self.translation2.minTrans[2] = Utils.getNoNil(y, 0);
        self.translation2.minTrans[3] = Utils.getNoNil(z, 0);

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

	    self.translation2.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translation2#transTime"), 2)*1000;
      
    end;
	local translationNode3 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.translation3#index"));
    if translationNode3 ~= nil then
        self.translation3 = {};
        self.translation3.node = translationNode3;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translation3#minTrans"));
        self.translation3.minTrans = {};
        self.translation3.minTrans[1] = Utils.getNoNil(x, 0);
        self.translation3.minTrans[2] = Utils.getNoNil(y, 0);
        self.translation3.minTrans[3] = Utils.getNoNil(z, 0);

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

	    self.translation3.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translation3#transTime"), 2)*1000;
      
    end;
	local translationNode4 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.translation4#index"));
    if translationNode4 ~= nil then
        self.translation4 = {};
        self.translation4.node = translationNode4;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translation4#minTrans"));
        self.translation4.minTrans = {};
        self.translation4.minTrans[1] = Utils.getNoNil(x, 0);
        self.translation4.minTrans[2] = Utils.getNoNil(y, 0);
        self.translation4.minTrans[3] = Utils.getNoNil(z, 0);

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

	    self.translation4.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translation4#transTime"), 2)*1000;
      
    end;
	local translationNode5 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.translation5#index"));
    if translationNode5 ~= nil then
        self.translation5 = {};
        self.translation5.node = translationNode5;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translation5#minTrans"));
        self.translation5.minTrans = {};
        self.translation5.minTrans[1] = Utils.getNoNil(x, 0);
        self.translation5.minTrans[2] = Utils.getNoNil(y, 0);
        self.translation5.minTrans[3] = Utils.getNoNil(z, 0);

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

	    self.translation5.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translation5#transTime"), 2)*1000;
      
    end;
	
	
	
	local numRotParts1 = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.RotParts1#count"), 0);
    self.RotParts1 = {};
    for i=1, numRotParts1 do
      local partnamei = string.format("vehicle.RotParts1.part" .. "%d", i);
      self.RotParts1[i] = {};
      self.RotParts1[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei .. "#index"));
      local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#minRot"));
      self.RotParts1[i].minRot = {};
      self.RotParts1[i].minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts1[i].minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts1[i].minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#maxRot"));
      self.RotParts1[i].maxRot = {};
      self.RotParts1[i].maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts1[i].maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts1[i].maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      self.RotParts1[i].rotTime = Utils.getNoNil(getXMLString(xmlFile,  partnamei .. "#rotSpeed"), 2)*1000;
    end;
	local numRotParts2 = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.RotParts2#count"), 0);
    self.RotParts2 = {};
    for i=1, numRotParts2 do
      local partnamei = string.format("vehicle.RotParts2.part" .. "%d", i);
      self.RotParts2[i] = {};
      self.RotParts2[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei .. "#index"));
      local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#minRot"));
      self.RotParts2[i].minRot = {};
      self.RotParts2[i].minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts2[i].minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts2[i].minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#maxRot"));
      self.RotParts2[i].maxRot = {};
      self.RotParts2[i].maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts2[i].maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts2[i].maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      self.RotParts2[i].rotTime = Utils.getNoNil(getXMLString(xmlFile,  partnamei .. "#rotSpeed"), 2)*1000;
    end;
	local numRotParts3 = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.RotParts3#count"), 0);
    self.RotParts3 = {};
    for i=1, numRotParts3 do
      local partnamei = string.format("vehicle.RotParts3.part" .. "%d", i);
      self.RotParts3[i] = {};
      self.RotParts3[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei .. "#index"));
      local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#minRot"));
      self.RotParts3[i].minRot = {};
      self.RotParts3[i].minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts3[i].minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts3[i].minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#maxRot"));
      self.RotParts3[i].maxRot = {};
      self.RotParts3[i].maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts3[i].maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts3[i].maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      self.RotParts3[i].rotTime = Utils.getNoNil(getXMLString(xmlFile,  partnamei .. "#rotSpeed"), 2)*1000;
    end;
	local numRotParts4 = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.RotParts4#count"), 0);
    self.RotParts4 = {};
    for i=1, numRotParts4 do
      local partnamei = string.format("vehicle.RotParts4.part" .. "%d", i);
      self.RotParts4[i] = {};
      self.RotParts4[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei .. "#index"));
      local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#minRot"));
      self.RotParts4[i].minRot = {};
      self.RotParts4[i].minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts4[i].minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts4[i].minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#maxRot"));
      self.RotParts4[i].maxRot = {};
      self.RotParts4[i].maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts4[i].maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts4[i].maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      self.RotParts4[i].rotTime = Utils.getNoNil(getXMLString(xmlFile,  partnamei .. "#rotSpeed"), 2)*1000;
    end;
	 self.keys = {};
    local i=0;
    while true do
        local baseName = string.format("vehicle.keys.input(%d)", i);
        local inputName = getXMLString(xmlFile, baseName.. "#name");
        if inputName == nil then
            break;
        end;
        local inputKey = getXMLString(xmlFile, baseName.. "#key");
        if Input[inputKey] == nil then
            print("Error: invalid key '" .. inputKey .. "'  for input event '" .. inputName .. "'");
            break;
        end;
        self.keys[inputName] = Input[inputKey];
        i = i+1;
    end;
	
			-------------------------
		---------flashlights
	self.FlashLightLeft = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.indexl#index"));
    self.FlashLightRight = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.indexr#index"));	 
	self.FlashLightLeft1 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.indexl1#index"));
     self.FlashLightRight1 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.indexr1#index"));	 
	
	
	
    self.flashLightLeftActive = false;
    self.flashLightRightActive = false;
    self.flash = false;
    self.flashRight = false;
    self.flashLeft = false;
    self.delayOnLeft = 0;
    self.delayOffLeft = 0;
    self.delayOnRight = 0;
    self.delayOffRight = 0;
    self.delayOn = 0;
    self.delayOff = 0;
   
    turnSoundFile = Utils.getFilename("turn.wav", self.baseDirectory);
    self.turnSoundId = createSample("turnSound");
    loadSample(self.turnSoundId, turnSoundFile, false);
	-------------------
	---brake light and sound
	self.lightsbrake = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.brake#index"));

	self.braking = false;
	local brakeSound = getXMLString(xmlFile, "vehicle.brakeSound#file");
    if brakeSound ~= nil and brakeSound ~= "" then
	brakeSound = Utils.getFilename(brakeSound, self.baseDirectory);
        self.brakeSound = createSample("brakeSound");
        loadSample(self.brakeSound, brakeSound, false);
    end;
	
	---emision de particulas ruedas

self.wheelParticleSystems = {};
    local psFile = getXMLString(xmlFile, "vehicle.wheelParticleSystems#file");
    if psFile ~= nil then
        local i=0;
        while true do
            local baseName = string.format("vehicle.wheelParticleSystems.wheelParticleSystem(%d)", i);
            local node = getXMLString(xmlFile, baseName.. "#node");
            if node == nil then
                break;
            end;
            node = Utils.indexToObject(self.components, node);
			self.wheelParticleSystems.node = node;
            if node ~= nil then
                local wheelParticleSystem = {};
                wheelParticleSystem.particleSystems = {};
                Utils.loadParticleSystem(xmlFile, wheelParticleSystem.particleSystems, "vehicle.wheelParticleSystems", node, false, nil, self.baseDirectory);
                table.insert(self.wheelParticleSystems, wheelParticleSystem);
            end;
            i = i+1;
        end;
    end;
	
	-------------	ruedas que copian rotacion de otras en funcion del contacto o no de estas con el suelo
	self.numWheelCenter = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.wheelCenter#count"), 0); 
	self.wheelCenter = {}; 
 for i=1, self.numWheelCenter do 
     local partnamei = string.format("vehicle.wheelCenter.part" .. "%d", i); 
     self.wheelCenter[i] = {}; 
     self.wheelCenter[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei.."#index")); 
   
 end;
	
	self.numWheelRight = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.wheelRight#count"), 0); 
	self.wheelRight = {}; 
	 for i=1, self.numWheelRight do 
		 local partnamei = string.format("vehicle.wheelRight.part" .. "%d", i); 
		 self.wheelRight[i] = {}; 
		 self.wheelRight[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei.."#index")); 
	   
	 end;	
	 self.numWheelRightInverse = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.wheelRightInverse#count"), 0); 
	self.wheelRightInverse = {}; 
	 for i=1, self.numWheelRightInverse do 
		 local partnamei = string.format("vehicle.wheelRightInverse.part" .. "%d", i); 
		 self.wheelRightInverse[i] = {}; 
		 self.wheelRightInverse[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei.."#index")); 
	   
	 end;	
	self.numWheelLeft = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.wheelLeft#count"), 0); 
	self.wheelLeft = {}; 
	 for i=1, self.numWheelLeft do 
		 local partnamei = string.format("vehicle.wheelLeft.part" .. "%d", i); 
		 self.wheelLeft[i] = {}; 
		 self.wheelLeft[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei.."#index")); 
	   
	 end;
	self.numWheelLeftInverse = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.wheelLeftInverse#count"), 0); 
	self.wheelLeftInverse = {}; 
	 for i=1, self.numWheelLeftInverse do 
		 local partnamei = string.format("vehicle.wheelLeftInverse.part" .. "%d", i); 
		 self.wheelLeftInverse[i] = {}; 
		 self.wheelLeftInverse[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei.."#index")); 
	   
	 end;


  
	local workSound = getXMLString(xmlFile, "vehicle.workSound#file");
    if workSound ~= nil and workSound ~= "" then
        workSound = Utils.getFilename(workSound, self.baseDirectory);
        self.workSound = createSample("workSound");
        loadSample(self.workSound, workSound, false);
        self.workSoundPitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.workSound#pitchOffset"), 0); 
        self.workSoundEnabled = false;       
    end;
self.controlpath = Utils.getFilename("menu.png", self.baseDirectory);
   
    
    self.hudKinze3800Width = 0.700;
    self.hudKinze3800Height = 0.320;
    self.hudKinze3800PoxX = 0;
    self.hudKinze3800PoxY = 0;
    self.hudKinze3800Overlay = Overlay:new("hudKinze3800", self.controlpath, self.hudKinze3800PoxX, self.hudKinze3800PoxY, self.hudKinze3800Width, self.hudKinze3800Height);
     self.bcActive = false;
	
	-------------------
	self.currentFillType = FruitUtil.FRUITTYPE_UNKNOWN;
	self.fillLevel = 0;
    self.allowFillType = Kinze3800.allowFillType;
	
	

	
	
	---------------------------
	local hydraulicSound = getXMLString(xmlFile, "vehicle.hydraulicSound#file");
    if hydraulicSound ~= nil and hydraulicSound ~= "" then
        hydraulicSound = Utils.getFilename(hydraulicSound, self.baseDirectory);
        self.hydraulicSound = createSample("hydraulicSound");
        loadSample(self.hydraulicSound, hydraulicSound, false);
        self.hydraulicSoundPitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.hydraulicSound#pitchOffset"), 0); 
        self.hydraulicSoundEnabled = false; 
		self.sound1=false;
		self.sound2=false;
		self.sound3=false;
		self.sound4=false;
		self.sound5=false;
		self.sound6=false;
    end;
	
	
	
	
	
	
	local augerSound = getXMLString(xmlFile, "vehicle.augerSound#file");
    if augerSound ~= nil and augerSound ~= "" then
        augerSound = Utils.getFilename(augerSound, self.baseDirectory);
        self.augerSound = createSample("augerSound");
        loadSample(self.augerSound, augerSound, false);
        self.augerSoundPitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.augerSound#pitchOffset"), 0); 
        self.augerSoundEnabled = false;       
    end;
    
	
	self.numMarkerAreas = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.markerAreas#count"), 0);
    self.markerAreas = {}
    for i=1, self.numMarkerAreas do
        self.markerAreas[i] = {};
        local areanamei = string.format("vehicle.markerAreas.markerArea%d", i);
        self.markerAreas[i].start = Utils.indexToObject(self.components, getXMLString(xmlFile, areanamei .. "#startIndex"));
        self.markerAreas[i].width = Utils.indexToObject(self.components, getXMLString(xmlFile, areanamei .. "#widthIndex"));
        self.markerAreas[i].height = Utils.indexToObject(self.components, getXMLString(xmlFile, areanamei .. "#heightIndex"));
    end;
	
	self.numCultivatorAreas = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.cultivatorAreas#count"), 0);
    self.cultivatorAreas = {}
    for i=1, self.numCultivatorAreas do
        self.cultivatorAreas[i] = {};
        local areanamei = string.format("vehicle.cultivatorAreas.cultivatorArea%d", i);
        self.cultivatorAreas[i].start = Utils.indexToObject(self.components, getXMLString(xmlFile, areanamei .. "#startIndex"));
        self.cultivatorAreas[i].width = Utils.indexToObject(self.components, getXMLString(xmlFile, areanamei .. "#widthIndex"));
        self.cultivatorAreas[i].height = Utils.indexToObject(self.components, getXMLString(xmlFile, areanamei .. "#heightIndex"));
    end;
	-- Particles
	self.particleSystems1 = {};
    local psName1 = "vehicle.particleSystem1";
    Utils.loadParticleSystem(xmlFile, self.particleSystems1, psName1, self.components, false);
	
	self.particleSystems2 = {};
    local psName2 = "vehicle.particleSystem2";
    Utils.loadParticleSystem(xmlFile, self.particleSystems2, psName2, self.components, false);
	
	self.particleSystems3 = {};
    local psName3 = "vehicle.particleSystem3";
    Utils.loadParticleSystem(xmlFile, self.particleSystems3, psName3, self.components, false);
	
	self.particleSystems4 = {};
    local psName4 = "vehicle.particleSystem4";
    Utils.loadParticleSystem(xmlFile, self.particleSystems4, psName4, self.components, false);

	self.particleSystems5 = {};
    local psName5 = "vehicle.particleSystem5";
    Utils.loadParticleSystem(xmlFile, self.particleSystems5, psName5, self.components, false);
	
	self.particleSystems6 = {};
    local psName6 = "vehicle.particleSystem6";
    Utils.loadParticleSystem(xmlFile, self.particleSystems6, psName6, self.components, false);
	
	
	
	
	
	
	
	 self.aiTerrainDetailChannel1 = g_currentMission.cultivatorChannel;
    self.aiTerrainDetailChannel2 = g_currentMission.ploughChannel;
	
	
	
	
	self.vehicleType = getXMLString(xmlFile, "vehicle#type");
	
	self.rotParts1 = false;
	self.rotParts2 = false;
	self.rotParts3 = false;
	self.rotParts4 = true;
	self.lock=true;
	self.openFinished=false;
	 self.translation1max=false;
	 self.rotation1max=false;
	self.rotation4max=false;
	self.rotation5max=false;
	self.rotation6max=false;
	self.rotation7max=false;
	 self.driveMarkLeft =false  
	 self.driveMarkRight =false  
	self.AIon=false;
	self.free=false;
	self.augerAutoOn=true;
end;
function Kinze3800:delete()
    
	 if self.workSoundEnabled then
		stopSample(self.workSound);
		self.workSoundEnabled = false;
	end;
		
 	if self.augersoundplayed  then
	stopSample(self.augerSoundId);
	self.augersoundplayed = false;
	end;
if self.hydraulicSoundplayed  then
	stopSample(self.hydraulicSoundId);
	self.hydraulicSoundplayed = false;
	end;
	
end;
function Kinze3800:mouseEvent(posX, posY, isDown, isUp, button)
end;

function Kinze3800:keyEvent(unicode, sym, modifier, isDown)
 
		self.on=true;
---flashlights
	
	if isDown and sym == Input.KEY_KP_1 then
		self.flashLeft = not self.flashLeft;
		self.delayOnLeft = 10;
		self.flashRight = false;
		self.flash = false;
		self.flashLightRightActive = false;
	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.flashLightLeftActive = 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.flashLightRightActive = false;
		self.flashLightLeftActive = false;
	end;
	
	
end;

function Kinze3800:update(dt)
self.time = self.time + dt;
		

		if self.doJointOrientation and self.attacherVehicle ~= nil then
		for k,v in pairs(self.attacherVehicle.attachedImplements) do
			if v.object == self then
				local joint = self.attacherVehicle.attacherJoints[v.jointDescIndex];
				self.attacherJointCopy = {};
				self.attacherJointCopy.joint = joint;	
				self.attacherJointCopy.minRotCopy = joint.minRot;
				self.attacherJointCopy.maxRotCopy = joint.maxRot;
				joint.minRot = joint.maxRot;
			end;
		end;
		self.doJointOrientation = false;
	end;

	
	
if self:getIsActive() then 
	
		
	
if self.attacherVehicle then	
	
	
	--- flashLights
	if self.FlashLightLeft ~= nil then
            if self.flashLightLeftActive then
            	setVisibility(self.FlashLightLeft, self.flashLightLeftActive);
			 setVisibility(self.FlashLightLeft1, self.flashLightLeftActive);
	    else
            	setVisibility(self.FlashLightLeft, self.flashLightLeftActive);
				 setVisibility(self.FlashLightLeft1, self.flashLightLeftActive);
	    end;
        end;

	if self.FlashLightRight ~= nil then
            if self.FlashLightRightActive then
            	setVisibility(self.FlashLightRight, self.flashLightRightActive);
				setVisibility(self.FlashLightRight1, self.flashLightRightActive);
	    else
            	setVisibility(self.FlashLightRight, self.flashLightRightActive);
				 setVisibility(self.FlashLightRight1, self.flashLightRightActive);
	    end;
        end;

	if self.flashLeft then
		if self.delayOnLeft >= -1 then
			self.delayOnLeft = self.delayOnLeft -dt;
		end;
		if not self.flashLightLeftActive then
			if self.delayOnLeft < 0 then
				self.delayOffLeft = 200;
				self.flashLightLeftActive = true;
				playSample(self.turnSoundId, 1, 0.7, 0);
			end;
		end;
		if self.delayOffLeft >= 0 then
			self.delayOffLeft = self.delayOffLeft -dt;
		end;
		if self.flashLightLeftActive then
			if self.delayOffLeft < 0 then
				self.delayOnLeft = 200;
				self.flashLightLeftActive = false;
			end;
		end;
	end;

	if self.flashRight then
		if self.delayOnRight >= 0 then
			self.delayOnRight = self.delayOnRight -dt;
		end;
		if not self.flashLightRightActive then
			if self.delayOnRight < 0 then
				self.delayOffRight = 200;
				self.flashLightRightActive = true;
				playSample(self.turnSoundId, 1, 0.7, 0);
			end;
		end;
		if self.delayOffRight >= 0 then
			self.delayOffRight = self.delayOffRight -dt;
		end;
		if self.flashLightRightActive then
			if self.delayOffRight < 0 then
				self.delayOnRight = 200;
				self.flashLightRightActive = false;
			end;
		end;
	end;

	if self.flash then
		if self.delayOn >= 0 then
			self.delayOn = self.delayOn -dt;
		end;
		if not self.flashLightRightActive then
			if self.delayOn < 0 then
				self.delayOff = 200;
				self.flashLightRightActive = true;
				self.flashLightLeftActive = true;
				playSample(self.turnSoundId, 1, 0.7, 0);
			end;
		end;
		if self.delayOff >= 0 then
			self.delayOff = self.delayOff -dt;
		end;
		if self.flashLightRightActive then
			if self.delayOff < 0 then
				self.delayOn = 200;
				self.flashLightLeftActive = false;
				self.flashLightRightActive = false;
			end;
		end;
	end;

	if not self.flashLeft and not self.flashRight then
		if not self.flash then
			self.flashLightRightActive = false;
			self.flashLightLeftActive = false;
		end;
	end;
		
	if not self.flash and not self.flashLeft then
		if not self.flashRight then
			self.flashLightRightActive = false;
		end;
	end;

	if not self.flash and not self.flashRight then
		if not self.flashLeft then
			self.flashLightLeftActive = false;
		end;
	end;
	
	
	--------------------brake------------------------
   inputAxis_2 = InputBinding.getAnalogInputAxis(InputBinding.AXIS_MOVE_FORWARD_VEHICLE);

        if InputBinding.isAxisZero(inputAxisY) then
        inputAxis_2 = InputBinding.getDigitalInputAxis(InputBinding.AXIS_MOVE_FORWARD_VEHICLE);
        end;
	
		if (self.movingDirection*self.lastSpeed*(-inputAxis_2)) < -0.001 then
			setVisibility(self.lightsbrake, true);
			
			-- if not self.brakeSoundRunning then
					-- playSample(self.brakeSound, 1, 1, 0);
					-- self.brakeSoundRunning = true;
					
				-- end;
			self.braking = true;
			
		else
		     setVisibility(self.lightsbrake, false);
			
			self.braking = false;
			self.brakeSoundRunning = false;	
		
		end;
-----
		self.isModifierActive = false;
		local hydraulicMovingDirection = 0;
	
		   if InputBinding.hasEvent (InputBinding.SWITCH_IMPLEMENT) then 
			self.on=not self.on;
			end;
		if self.on then
			
		---- ajuste attach
			
				if InputBinding.isPressed(InputBinding.LOWER_HYDRAULIC) then
					hydraulicMovingDirection = -1;
				elseif InputBinding.isPressed(InputBinding.LIFT_HYDRAULIC) then
					hydraulicMovingDirection = 1;
				end;
			
	
			local jointDesc = self.attacherJointCopy.joint;
			setJointRotationLimit(jointDesc.jointIndex, 2, true, math.rad(0), math.rad(0));
			jointDesc.moveDown = false;
			self.movingDirection = 1;
			if hydraulicMovingDirection ~= 0 then				
				if jointDesc.rotationNode ~= nil then
					local x, y, z = getRotation(jointDesc.rotationNode);
					local rot = {x,y,z};
					local newRot = Utils.getMovedLimitedValues(rot, self.attacherJointCopy.maxRotCopy, self.attacherJointCopy.minRotCopy, 3, jointDesc.moveTime, dt, hydraulicMovingDirection == 1);
					setRotation(jointDesc.rotationNode, unpack(newRot));
					jointDesc.maxRot = newRot;
					jointDesc.minRot = newRot;
					setJointFrame(jointDesc.jointIndex, 0, jointDesc.jointTransform);
				end;
			end;
			
			
			
			if InputBinding.hasEvent (InputBinding.INFOHUD) then
				self.bcActive = not self.bcActive;
			end;
			if InputBinding.hasEvent (InputBinding.OPEN_TANK) then
				self.rotation1max = not self.rotation1max;
			end;
			
			
			if InputBinding.hasEvent (InputBinding.AUGER) then
			self.augerAutoOn = not	self.augerAutoOn;
			end;
			
			local x, y, z = getRotation(self.rotation1.node);
				
				
				if  self.rotation1max then
					if x> Utils.degToRad(120)  then
						 self.rotation100max =true;
					end;
				else 
					if x< Utils.degToRad(1)  then
						self.rotation100max =false; 
					end;
				end;
			
			
			
			
			
			
			
			if InputBinding.hasEvent (InputBinding.TURN_UP) then
				self.down=not self.down;
				self.sound1=not self.sound1;
			
			end;
			if InputBinding.hasEvent (InputBinding.TURN_DOWN) then
				self.up=not self.up;
				self.sound2=not self.sound2;
			
			end;
			
	
			
		if InputBinding.hasEvent(InputBinding.FOLD) then
				if not self.lock then
					 self.translation1max  = not self.translation1max ;
					 self.rotation9max = not self.rotation9max; 
					  self.rotation10max = not self.rotation10max;
					  self.rotation11max = not self.rotation11max; 
					  self.rotation12max = not self.rotation12max;
					  self.sound3=true;
				end; 
		end;		
		if InputBinding.hasEvent(InputBinding.TRANS) then
					 self.translation2max  = not self.translation2max ;
					self.sound4=true;
		
		end;
		
		local x, y, z = getTranslation(self.translation1.node);
			if z ==0.8 then
			self.translation3max=true;
			elseif z~=0.8 then
			self.translation3max=false;
				
			end;
			if z == 6  then
			self.openFinished=false;
			end;
			if  self.translation1max then
					if z< 1 then 
					self.sound3=false;
					self.openFinished=true;
					--renderText(0.3, 0.50, 0.03,"openFinished ");
					end;
			else
				if z> 5.7 then 
					self.sound3=false;		
				end;					
			end;
			
		local x, y, z = getTranslation(self.translation2.node);
			
		if  self.translation2max then
					if z>0.8 then 
					self.sound4=false;
					end;
		else
				if z< 0.2 then 
					self.sound4=false;		
				end;					
		end;	
			
			
			
			
			
			
			
			
			if InputBinding.hasEvent(InputBinding.AUX) then
				self.rotParts4=not self.rotParts4;
			end;
			if InputBinding.hasEvent(InputBinding.IMPLEMENT_EXTRA) then
				self.rotParts4=not self.rotParts4;
			end;		
			if InputBinding.hasEvent(InputBinding.LOCK) then
				self.lock=not self.lock;
			end;
		
				if InputBinding.hasEvent(InputBinding.LEFT_MARKER) then
						 self.rotation4max = not self.rotation4max;
						 self.rotation5max = not self.rotation5max;
						self.sound5=true;
				end;
				if InputBinding.hasEvent(InputBinding.RIGHT_MARKER) then
						 self.rotation7max = not self.rotation7max;
						 self.rotation6max = not self.rotation6max;
						self.sound6=true;
				end;
		
			
			if InputBinding.hasEvent(InputBinding.REAR_ATTACH) then
					 self.translation4max  = not self.translation4max ;
					  self.translation5max  = not self.translation5max
			end;
			if InputBinding.hasEvent(InputBinding.LADDER) then
					 self.rotation2max  = not self.rotation2max ;
			end;
end; ---on
	--- markers
		local x, y, z = getRotation(self.rotation4.node);
				
				if x> Utils.degToRad(80)  then
					 self.driveMarkLeft =true  
				else 
					 self.driveMarkLeft =false  
				end;
	
				if  self.rotation4max then
					if x> Utils.degToRad(88)  then
						 self.sound5=false;  
					end;
				else 
					if x< Utils.degToRad(1)  then
						 self.sound5=false;  
					end;
				end;
				
				local x, y, z = getRotation(self.rotation7.node);
				
				if x> Utils.degToRad(80)  then
					 self.driveMarkRight =true  
				else 
					 self.driveMarkRight =false  
				end;
				if  self.rotation7max then
					if x> Utils.degToRad(88)  then
						 self.sound6=false;  
					end;
				else 
					if x< Utils.degToRad(1)  then
						 self.sound6=false;  
					end;
				end;
			
		if self.sound1 or self.sound2 or self.sound3 or self.sound4 or self.sound5	or self.sound6 then
			--renderText(0.3, 0.10, 0.03,"hydraulic on  ");
			if	not self.hydraulicSoundEnabled then
					playSample(self.hydraulicSound, 0, 1, 0);
					setSamplePitch(self.hydraulicSound, self.hydraulicSoundPitchOffset);
					self.hydraulicSoundEnabled = true;
				end;
		elseif  not self.sound1 or  not self.sound2 or not self.sound3 or not self.sound4 or not self.sound5 or not self.sound6 then	
			--renderText(0.3, 0.10, 0.05,"hydraulic off  ");
				if self.hydraulicSoundEnabled then
					stopSample(self.hydraulicSound);
					self.hydraulicSoundEnabled = false;
					end;
		end;
		
		---particulas ruedas

	local dens = 0; local dens1; local dens2; local dens3;
	 local x,y,z = getWorldTranslation(self.wheels[3].repr);
	 local x1,y1,z1 = getWorldTranslation(self.wheels[4].repr);
	 local x2,y2,z2 = getWorldTranslation(self.wheels[5].repr);
	local id = g_currentMission.terrainDetailId;
	local xx, zz, widthX, widthZ, heightX, heightZ = Utils.getXZWidthAndHeight(id, x, z, x1, z1, x2, z2);
	dens1 = getDensityParallelogram(id, xx, zz, widthX, widthZ, heightX, heightZ, g_currentMission.cultivatorChannel, 1);
	dens2 = getDensityParallelogram(id, xx, zz, widthX, widthZ, heightX, heightZ, g_currentMission.sowingChannel, 1);
	dens3 = getDensityParallelogram(id, xx, zz, widthX, widthZ, heightX, heightZ, g_currentMission.ploughChannel, 1);
	if g_currentMission.environment.lastRainScale <= 0.1 and g_currentMission.environment.timeSinceLastRain > 30 then
		dens = dens1+dens2+dens3;
	end;
	if  self.lastSpeed*self.speedDisplayScale*3600 > 4 and not self.lock then
		if dens > 0 then
				for k=1,  table.getn(self.wheelParticleSystems) do
				Utils.setEmittingState(self.wheelParticleSystems[k].particleSystems, self.wheels[k].hasGroundContact);
			end;
		elseif dens <=0 then
			for i=1, table.getn(self.wheelParticleSystems) do
				Utils.setEmittingState(self.wheelParticleSystems[i].particleSystems, false);
			end;
		
		end;
	else
		for i=1, table.getn(self.wheelParticleSystems) do
				Utils.setEmittingState(self.wheelParticleSystems[i].particleSystems, false);
			end;
	end;	
		
		-----------------------------	
		
			
		
		if self.wheels[81].hasGroundContact then
				self.rotParts1=true;
				local x1,y1,z1 = getRotation(self.wheels[4].repr);
				for i=1, self.numWheelCenter do 
				 setRotation(self.wheelCenter[i].index,x1, y1, z1);
				end; 
		else
			self.rotParts1=false;
			
		end;	
		if self.wheels[53].hasGroundContact then
				self.rotParts2=true;
				local x2,y2,z2 = getRotation(self.wheels[8].repr);
				for i=1, self.numWheelLeft do 
				 setRotation(self.wheelLeft[i].index,x2, y2, z2);
				end;  
				for i=1, self.numWheelLeftInverse do 
				 setRotation(self.wheelLeftInverse[i].index,x2*-1, y2, z2);
				end;  
		else
			self.rotParts2=false;
			
		end;			
		if self.wheels[71].hasGroundContact then
				self.rotParts3=true;
				local x3,y3,z3 = getRotation(self.wheels[11].repr);
				for i=1, self.numWheelRight do 
				 setRotation(self.wheelRight[i].index,x3, y3, z3);
				end;
				for i=1, self.numWheelRightInverse do 
				 setRotation(self.wheelRightInverse[i].index,x3*-1, y3, z3);
				end;  
		else
			self.rotParts3=false;
			
		end;
		
	if self.wheels[15].hasGroundContact and self.driveMarkLeft then
			if self.markerAreas[1] ~= nil then
				local x,y,z = getWorldTranslation(self.markerAreas[1].start);
				local x1,y1,z1 = getWorldTranslation(self.markerAreas[1].width);
				local x2,y2,z2 = getWorldTranslation(self.markerAreas[1].height);
					Utils.updatePloughArea(x, z, x1, z1, x2, z2);
			end;
	end;
	if self.wheels[16].hasGroundContact and self.driveMarkRight then
				if self.markerAreas[2] ~= nil then
				local x,y,z = getWorldTranslation(self.markerAreas[2].start);
				local x1,y1,z1 = getWorldTranslation(self.markerAreas[2].width);
				local x2,y2,z2 = getWorldTranslation(self.markerAreas[2].height);
					Utils.updatePloughArea(x, z, x1, z1, x2, z2);
				end;
	end;
		
	if not self.rotParts4 and self.openFinished  then
				self.augerAutoOn=true;
				if self.cultivatorAreas[1] ~= nil then
					local x,y,z = getWorldTranslation(self.cultivatorAreas[1].start);
					local x1,y1,z1 = getWorldTranslation(self.cultivatorAreas[1].width);
					local x2,y2,z2 = getWorldTranslation(self.cultivatorAreas[1].height);
											
							Utils.updateCultivatorArea(x, z, x1, z1, x2, z2);				                                 		
				end;
				
			if self.attacherVehicle.lastSpeed*3600 > 2 and not self.AIon then
				Utils.setEmittingState(self.particleSystems1, true);
				Utils.setEmittingState(self.particleSystems2, true);
				Utils.setEmittingState(self.particleSystems3, true);
				Utils.setEmittingState(self.particleSystems4, true);
				Utils.setEmittingState(self.particleSystems5, true);
				Utils.setEmittingState(self.particleSystems6, true);
				if	not self.workSoundEnabled then
					playSample(self.workSound, 0, 1, 0);
					setSamplePitch(self.workSound, self.workSoundPitchOffset);
					self.workSoundEnabled = true;
				end;
			elseif self.attacherVehicle.lastSpeed*3600 < 2 or self.AIon then
				Utils.setEmittingState(self.particleSystems1, false);
				Utils.setEmittingState(self.particleSystems2, false);
				Utils.setEmittingState(self.particleSystems3, false);
				Utils.setEmittingState(self.particleSystems4, false);
				Utils.setEmittingState(self.particleSystems5, false);
				Utils.setEmittingState(self.particleSystems6, false);
					if self.workSoundEnabled then
					stopSample(self.workSound);
					self.workSoundEnabled = false;
					end;
			end;

	
		
	
elseif self.rotParts4 and self.openFinished  then
			
				if self.workSoundEnabled then
				stopSample(self.workSound);
				self.workSoundEnabled = false;
				end;
				Utils.setEmittingState(self.particleSystems1, false);
				Utils.setEmittingState(self.particleSystems2, false);
				Utils.setEmittingState(self.particleSystems3, false);
				Utils.setEmittingState(self.particleSystems4, false);
				Utils.setEmittingState(self.particleSystems5, false);
				Utils.setEmittingState(self.particleSystems6, false);
			
			
				
end;
			
	if self.attacherVehicle.isAITractorActivated then
		self.AIon=true;
	
	else
		self.AIon=false;
	end;	
	if self.openFinished  and self.augerAutoOn then
		if self.fillLevel >  0  then	
		
				if  not self.AIon then
					--renderText(0.6, 0.10, 0.03," AI false ");
					if	not self.augerSoundEnabled then
						playSample(self.augerSound, 0, 1, 0);
						setSamplePitch(self.augerSound, self.augerSoundPitchOffset);
						self.augerSoundEnabled = true;
					end;
				elseif self.AIon then
					--renderText(0.6, 0.10, 0.03," AI true ");
						if self.augerSoundEnabled then
						stopSample(self.augerSound);
						self.augerSoundEnabled = false;
						end;
				end;
		elseif  self.fillLevel <=  0 and self.AIon or self.fillLevel <= 0 and not self.AIon  then
			if self.augerSoundEnabled then
			stopSample(self.augerSound);
			self.augerSoundEnabled = false;
			end;
		end;		
	end;
		if   not self.augerAutoOn	then
			if self.augerSoundEnabled then
			stopSample(self.augerSound);
			self.augerSoundEnabled = false;
			end;
			
		end;	


	
		if   not self.translation1max	then
			if self.augerSoundEnabled then
			stopSample(self.augerSound);
			self.augerSoundEnabled = false;
			end;
			
		end;	
			
			
			
			
			
			
			
end; ----active
end; ---attach
----rotaciones y translaciones
 if self.down then
			local rotationPart = self.rotationParts.rotationPart1;
			local rot = {getRotation(rotationPart.index)};
			local newRot = Utils.getMovedLimitedValues(rot, rotationPart.maxRot, rotationPart.minRot, 3, rotationPart.rotTime, dt, true);
			setRotation(rotationPart.index, unpack(newRot));
			local rotationPart = self.rotationParts.rotationPart2;
			local rot = {getRotation(rotationPart.index)};
			local newRot = Utils.getMovedLimitedValues(rot, rotationPart.maxRot, rotationPart.minRot, 3, rotationPart.rotTime, dt, true);
			setRotation(rotationPart.index, unpack(newRot));
			local rotationPart = self.rotationParts.rotationPart3;
			local rot = {getRotation(rotationPart.index)};
			local newRot = Utils.getMovedLimitedValues(rot, rotationPart.maxRot, rotationPart.minRot, 3, rotationPart.rotTime, dt, true);
			setRotation(rotationPart.index, unpack(newRot));
	    end;		
		if self.up then
			local rotationPart = self.rotationParts.rotationPart1;
			local rot = {getRotation(rotationPart.index)};
			local newRot = Utils.getMovedLimitedValues(rot, rotationPart.maxRot, rotationPart.minRot, 3, rotationPart.rotTime, dt, false);
			setRotation(rotationPart.index, unpack(newRot));
			local rotationPart = self.rotationParts.rotationPart2;
			local rot = {getRotation(rotationPart.index)};
			local newRot = Utils.getMovedLimitedValues(rot, rotationPart.maxRot, rotationPart.minRot, 3, rotationPart.rotTime, dt, false);
			setRotation(rotationPart.index, unpack(newRot));
			local rotationPart = self.rotationParts.rotationPart3;
			local rot = {getRotation(rotationPart.index)};
			local newRot = Utils.getMovedLimitedValues(rot, rotationPart.maxRot, rotationPart.minRot, 3, rotationPart.rotTime, dt, false);
			setRotation(rotationPart.index, unpack(newRot));
	    end;  			

		if self.rotParts1 ~= nil   then
			for i=1, table.getn(self.RotParts1) do
					local rot = {getRotation(self.RotParts1[i].index)};
					local newRot = Utils.getMovedLimitedValues(rot, self.RotParts1[i].maxRot, self.RotParts1[i].minRot, 3, self.RotParts1[i].rotTime, dt, not self.rotParts1);
					setRotation(self.RotParts1[i].index, unpack(newRot));
			end; 
		end;
		if self.rotParts2 ~= nil   then
			for i=1, table.getn(self.RotParts2) do
					local rot = {getRotation(self.RotParts2[i].index)};
					local newRot = Utils.getMovedLimitedValues(rot, self.RotParts2[i].maxRot, self.RotParts2[i].minRot, 3, self.RotParts2[i].rotTime, dt, not self.rotParts2);
					setRotation(self.RotParts2[i].index, unpack(newRot));
			end; 
		end;
		if self.rotParts3 ~= nil   then
			for i=1, table.getn(self.RotParts3) do
					local rot = {getRotation(self.RotParts3[i].index)};
					local newRot = Utils.getMovedLimitedValues(rot, self.RotParts3[i].maxRot, self.RotParts3[i].minRot, 3, self.RotParts3[i].rotTime, dt, not self.rotParts3);
					setRotation(self.RotParts3[i].index, unpack(newRot));
			end; 
		end;
			if self.rotParts4 ~= nil   then
			for i=1, table.getn(self.RotParts4) do
					local rot = {getRotation(self.RotParts4[i].index)};
					local newRot = Utils.getMovedLimitedValues(rot, self.RotParts4[i].maxRot, self.RotParts4[i].minRot, 3, self.RotParts4[i].rotTime, dt, not self.rotParts4);
					setRotation(self.RotParts4[i].index, unpack(newRot));
			end; 
		end;
	if self.rotation1max ~= nil then
        local x, y, z = getRotation(self.rotation1.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation1.maxRot, self.rotation1.minRot, 3, self.rotation1.rotTime, dt, not self.rotation1max);
        setRotation(self.rotation1.node, unpack(newRot));
    end;
	if self.rotation100max ~= nil then
        local x, y, z = getRotation(self.rotation100.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation100.maxRot, self.rotation100.minRot, 3, self.rotation100.rotTime, dt, not self.rotation100max);
        setRotation(self.rotation100.node, unpack(newRot));
    end;
	if self.rotation2max ~= nil then
        local x, y, z = getRotation(self.rotation2.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation2.maxRot, self.rotation2.minRot, 3, self.rotation2.rotTime, dt, not self.rotation2max);
        setRotation(self.rotation2.node, unpack(newRot));
    end;
		

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

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

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

	if self.rotation7 ~= nil then
        local x, y, z = getRotation(self.rotation7.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation7.maxRot, self.rotation7.minRot, 3, self.rotation7.rotTime, dt, not self.rotation7max);
        setRotation(self.rotation7.node, unpack(newRot));
    end;
if self.rotation8 ~= nil then
        local x, y, z = getRotation(self.rotation8.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation8.maxRot, self.rotation8.minRot, 3, self.rotation8.rotTime, dt, not self.rotation8max);
        setRotation(self.rotation8.node, unpack(newRot));
    end;
	if self.rotation9 ~= nil then
        local x, y, z = getRotation(self.rotation9.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation9.maxRot, self.rotation9.minRot, 3, self.rotation9.rotTime, dt, not self.rotation9max);
        setRotation(self.rotation9.node, unpack(newRot));
    end;
	if self.rotation10 ~= nil then
        local x, y, z = getRotation(self.rotation10.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation10.maxRot, self.rotation10.minRot, 3, self.rotation10.rotTime, dt, not self.rotation10max);
        setRotation(self.rotation10.node, unpack(newRot));
    end;
	if self.rotation11 ~= nil then
        local x, y, z = getRotation(self.rotation11.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation11.maxRot, self.rotation11.minRot, 3, self.rotation11.rotTime, dt, not self.rotation11max);
        setRotation(self.rotation11.node, unpack(newRot));
    end;
	if self.rotation12 ~= nil then
        local x, y, z = getRotation(self.rotation12.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation12.maxRot, self.rotation12.minRot, 3, self.rotation12.rotTime, dt, not self.rotation12max);
        setRotation(self.rotation12.node, unpack(newRot));
    end;
	
	
	if self.translation1 ~= nil  then 
		local x, y, z = getTranslation(self.translation1.node); 
		local trans = {x,y,z}; 
		local newTrans = Utils.getMovedLimitedValues(trans, self.translation1.maxTrans, self.translation1.minTrans, 3, self.translation1.transTime, dt, not self.translation1max); 
		setTranslation(self.translation1.node, unpack(newTrans)); 
	end;
	

	if self.translation2 ~= nil then 
		local x, y, z = getTranslation(self.translation2.node); 
		local trans = {x,y,z}; 
		local newTrans = Utils.getMovedLimitedValues(trans, self.translation2.maxTrans, self.translation2.minTrans, 3, self.translation2.transTime, dt, not self.translation2max); 
		setTranslation(self.translation2.node, unpack(newTrans)); 
	end;

	if self.translation3 ~= nil  then 
		local x, y, z = getTranslation(self.translation3.node); 
		local trans = {x,y,z}; 
		local newTrans = Utils.getMovedLimitedValues(trans, self.translation3.maxTrans, self.translation3.minTrans, 3, self.translation3.transTime, dt, not self.translation3max); 
		setTranslation(self.translation3.node, unpack(newTrans)); 
	end;
	if self.translation4 ~= nil  then 
		local x, y, z = getTranslation(self.translation4.node); 
		local trans = {x,y,z}; 
		local newTrans = Utils.getMovedLimitedValues(trans, self.translation4.maxTrans, self.translation4.minTrans, 3, self.translation4.transTime, dt, not self.translation4max); 
		setTranslation(self.translation4.node, unpack(newTrans)); 
	end;
if self.translation5 ~= nil  then 
		local x, y, z = getTranslation(self.translation5.node); 
		local trans = {x,y,z}; 
		local newTrans = Utils.getMovedLimitedValues(trans, self.translation5.maxTrans, self.translation5.minTrans, 3, self.translation5.transTime, dt, not self.translation5max); 
		setTranslation(self.translation5.node, unpack(newTrans)); 
	end;
		--- asignacion de libertad ejes de rotacion segun condiciones de emsamblage  0 x, 2 z ,1 y
		
		
	  self:setJointRotLimit(self.componentJoints[1],100,0, 500,self.rotation2max == true , 0,dt);	
	
		  self:setJointRotLimit(self.componentJoints[41],30, 0, 1300,self.rotation4max == true , 0,dt);	
	  self:setJointRotLimit(self.componentJoints[42],220, 0, 1300,self.rotation4max == true , 0,dt);	
	  self:setJointRotLimit(self.componentJoints[43],130, 0, 1300,self.rotation4max == true , 0,dt);	
	  self:setJointRotLimit(self.componentJoints[44],90, 0, 1300,self.rotation4max == true , 0,dt);	
	
	
	    self:setJointRotLimit(self.componentJoints[47],30, 0, 1300,self.rotation7max == true , 0,dt);	
	  self:setJointRotLimit(self.componentJoints[48],220, 0, 1300,self.rotation7max == true , 0,dt);	
	  self:setJointRotLimit(self.componentJoints[49],120, 0, 1300,self.rotation7max == true , 0,dt);	
	  self:setJointRotLimit(self.componentJoints[50],90, 0, 1300,self.rotation7max == true , 0,dt);
	  
	   self:setJointRotLimit(self.componentJoints[39],0, 70, 1000,self.lock== true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[108],0, 70, 1000,self.lock== true , 2,dt); 
		
		
		
		 self:setJointRotLimit(self.componentJoints[3],75, 0, 1000,self.free == true , 1,dt);	
		 self:setJointRotLimit(self.componentJoints[4],30, 0, 1000,self.free == true , 2,dt);	
			 self:setJointRotLimit(self.componentJoints[18],10, 0, 1000,self.free == true , 0,dt);	
	  self:setJointRotLimit(self.componentJoints[21],10, 0, 1000,self.free == true , 0,dt);	
	   self:setJointRotLimit(self.componentJoints[30],12, 0, 1000,self.free == true , 0,dt);	
	   self:setJointRotLimit(self.componentJoints[32],12, 0, 1000,self.free == true , 0,dt);	
	   self:setJointRotLimit(self.componentJoints[54],27, 0, 1000,self.free == true , 2,dt);	
	    self:setJointRotLimit(self.componentJoints[55],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[56],27, 0, 1000,self.free == true , 0,dt);
		  self:setJointRotLimit(self.componentJoints[57],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[58],27, 0, 1000,self.free == true , 2,dt);
		  self:setJointRotLimit(self.componentJoints[59],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[60],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[61],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[62],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[63],27, 0, 1000,self.free == true , 2,dt);
		  self:setJointRotLimit(self.componentJoints[64],27, 0, 1000,self.free == true , 0,dt);
		  self:setJointRotLimit(self.componentJoints[65],27, 0, 1000,self.free == true , 0,dt);
	  	    self:setJointRotLimit(self.componentJoints[66],27, 0, 1000,self.free == true , 2,dt);
		  self:setJointRotLimit(self.componentJoints[67],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[68],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[69],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[70],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[71],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[72],27, 0, 1000,self.free == true , 0,dt);
		  self:setJointRotLimit(self.componentJoints[73],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[74],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[75],27, 0, 1000,self.free == true , 2,dt);
		  self:setJointRotLimit(self.componentJoints[76],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[77],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[78],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[79],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[80],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[81],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[82],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[83],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[84],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[85],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[86],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[87],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[88],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[89],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[90],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[91],27, 0, 1000,self.free == true , 2,dt);
	    self:setJointRotLimit(self.componentJoints[92],27, 0, 1000,self.free == true , 0,dt);
	    self:setJointRotLimit(self.componentJoints[93],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[94],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[95],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[96],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[97],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[98],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[99],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[100],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[101],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[102],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[103],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[104],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[105],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[106],27, 0, 1000,self.free == true , 0,dt);
	  self:setJointRotLimit(self.componentJoints[107],27, 0, 1000,self.free == true , 0,dt);
	  
	  
	  
	-- juntas

			for i, jointDesc in pairs(self.componentJoints) do
	   setJointFrame(self.componentJoints[i].jointIndex, 0, self.componentJoints[i].jointNode);
	end;
		self:setHydraulicDirection();



end;
function Kinze3800:draw()
if self.attacherVehicle then
 	 if self.hudKinze3800Overlay ~= nil then
  if self.bcActive then
    self.hudKinze3800Overlay:render();
  end;
end;
		if self.bcActive then	
			g_currentMission:addExtraPrintText("play kp0: INFO ON");
		else
			g_currentMission:addExtraPrintText("play kp0: INFO Off");
		end;  
end;
end;
function Kinze3800:onAttach(attacherVehicle)
	self.doJointOrientation = true;	
	setJointRotationLimit(self.componentJoints[1].jointIndex, 1, true, math.rad(0), math.rad(0));
	setJointRotationLimit(self.componentJoints[1].jointIndex, 2, true, math.rad(0), math.rad(0));
	self.on=false;
	self.rotation3max=true;
	self.free=true;
 
 
	
	
end;
function Kinze3800:onDetach()
	self.free=true;
	self.on=false;
	self.rotation3max=false;
    if self.deactivateOnDetach then
        Kinze3800.onDeactivate(self);
    else
        Kinze3800.onDeactivateSounds(self)
    end;
	if self.attacherJointCopy ~= nil then
		local jointDesc = self.attacherJointCopy.joint;
		jointDesc.maxRot = self.attacherJointCopy.maxRotCopy;
		jointDesc.minRot = self.attacherJointCopy.minRotCopy;
	end;
	setJointRotationLimit(self.componentJoints[1].jointIndex, 1, true, math.rad(0), math.rad(0));
	setJointRotationLimit(self.componentJoints[1].jointIndex, 2, true, math.rad(0), math.rad(0));
	
	self.flashLightRightActive = false;
	self.flashLightLeftActive = false;
	setVisibility(self.FlashLightRight, false);
	setVisibility(self.FlashLightLeft, false);
	setVisibility(self.lightsbrake, false);
	Utils.setEmittingState(self.particleSystems1, false);
	Utils.setEmittingState(self.particleSystems2, false);
	Utils.setEmittingState(self.particleSystems3, false);
	Utils.setEmittingState(self.particleSystems4, false);
	Utils.setEmittingState(self.particleSystems5, false);
	Utils.setEmittingState(self.particleSystems6, false);
end;

function Kinze3800:onLeave()
    if self.deactivateOnLeave then
        Kinze3800.onDeactivate(self);
    else
        Kinze3800.onDeactivateSounds(self)
    end;
end;

function Kinze3800:onDeactivate()
    Kinze3800.onDeactivateSounds(self)

    
						
end;

function Kinze3800:onDeactivateSounds()
	if self.workSoundEnabled then
	stopSample(self.workSound);
	self.workSoundEnabled = false;
	end;
	if self.augersoundplayed  then
	stopSample(self.augerSoundId);
	self.augersoundplayed = false;
	end;
if self.hydraulicSoundplayed  then
	stopSample(self.hydraulicSoundId);
	self.hydraulicSoundplayed = false;
	end;
					
end;
function Kinze3800:setHydraulicDirection()
		for i=1, table.getn(self.hydraulics) do
		local ax, ay, az = getWorldTranslation(self.hydraulics[i].node);
		local bx, by, bz = getWorldTranslation(self.hydraulics[i].fixPoint);
		local x, y, z = worldDirectionToLocal(getParent(self.hydraulics[i].node), bx-ax, by-ay, bz-az);
		
		setDirection(self.hydraulics[i].node, x, y, z, 0, 1, 0);
		local distance = Utils.vector3Length(ax-bx, ay-by, az-bz);
		if self.hydraulics[i].doScale then
			local xScale, yScale, zScale = getScale(self.hydraulics[i].node);
			local newScale = yScale * (distance / self.hydraulics[i].punchDistance);
			setScale(self.hydraulics[i].node, 1, 1, newScale);
		else
			if self.hydraulics[i].punch ~= nil then
				setTranslation(self.hydraulics[i].punch, 0, 0, distance-self.hydraulics[i].punchDistance);
			end;
		end;
	
	end;
end;
function Kinze3800:setJointRotLimit(nodei, up, down, speed, value, axle, dt)

	if not self.firstDo[nodei] then
		self.firstDo[nodei] = true;
		self.arm[nodei] = {0}; 
	end; 
	x, y, z = getRotation(nodei);
	rot = {x,y,z};	
	newRotLimit = {}; 
	newRotLimit[nodei] = {0,0,0};
	newRotLimit[nodei] = Utils.getMovedLimitedValues(self.arm[nodei], {down}, {up}, 1, speed * 2, dt, value);
	if math.abs(newRotLimit[nodei][1] - self.arm[nodei][1]) > 0.001 then
		local joint = nodei;
		setJointRotationLimit(joint.jointIndex, axle, true, Utils.degToRad(-newRotLimit[nodei][1]), Utils.degToRad(newRotLimit[nodei][1]));
	end;
	self.arm[nodei] = newRotLimit[nodei];			
end;
function Kinze3800:allowFillType(fillType)
    return self.fillTypes[fillType] == true;
end;
function Kinze3800:aiLower()
	self.rotParts4 = false; 
	self.AIon=true;
	
end; 

function Kinze3800:aiRaise()
	self.rotParts4 = true; 
	self.AIon=false;
end; 
-- function Kinze3800:getSaveAttributesAndNodes(nodeIdent)
-- if self.openFinished== true  then
					
 -- finish = "true";	
-- else		
	-- finish = "false";	
-- end;		
		

	-- 'name="'..tostring(name)..'" name="'..tonumber(name)..'"';
	 -- local attributes = 'finish="'..tostring(finish)..'"';
	
	-- return attributes, nil;
-- end;


-- function Kinze3800:loadFromAttributesAndNodes(xmlFile, key, resetVehicles)
    -- local finish = getXMLString(xmlFile, key.."#finish");
	
	-- if finish == "true" and not resetVehicles then
	
		 -- self.translation1max  =true ;
		 -- self.translation2max  = false ;
		 -- self.rotation9max = true; 
		-- self.rotation10max = true;
		 -- self.rotation11max = true; 
		-- self.rotation12max = true;
		-- self.rotParts4 =true;
		-- self.lock =false;
		-- self.free=false;
		
	-- end; 
	
    -- return BaseMission.VEHICLE_LOAD_OK;
-- end;
function key_convert(key)
    if key ~= nil then 
	    local keyname = "";
	    if key > 32 and key < 123 then
	    	keyname = string.upper(string.char(key));
	    elseif key > 255 and key < 266 then
	    	keyname = "NUM "..string.char(key-208);
	    else 
	    	keyname = "";
	    end;
	    return(keyname);
	  end;
end;