-- xyzspain
-- 2013 fin050808
Visio200 = {};

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

function Visio200:load(xmlFile)

   self.aiTerrainDetailChannel1 = g_currentMission.sowingChannel; 
self.aiTerrainDetailChannel2 = g_currentMission.cultivatorChannel; 
self.safeMode = true
			---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;
	
	-------------	
		-- 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 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 translationNode6 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.translation6#index"));
    if translationNode6 ~= nil then
        self.translation6 = {};
        self.translation6.node = translationNode6;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.translation6#minTrans"));
        self.translation6.minTrans = {};
        self.translation6.minTrans[1] = Utils.getNoNil(x, 0);
        self.translation6.minTrans[2] = Utils.getNoNil(y, 0);
        self.translation6.minTrans[3] = Utils.getNoNil(z, 0);

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

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

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

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

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

	    self.translation8.transTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.translation8#transTime"), 2)*1000;
      
    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 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 rotationNode13 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rotation13#index"));
    if rotationNode13 ~= nil then
        self.rotation13 = {};
        self.rotation13.node = rotationNode13;
        local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, "vehicle.rotation13#minRot"));
        self.rotation13.minRot = {};
        self.rotation13.minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
        self.rotation13.minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
        self.rotation13.minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));

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

         self.rotation13.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.rotation13#rotTime"), 2)*1000;
      
    end;
	    local numRotParts = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.RotParts#count"), 0);
    self.RotParts = {};
    for i=1, numRotParts do
      local partnamei = string.format("vehicle.RotParts.part" .. "%d", i);
      self.RotParts[i] = {};
      self.RotParts[i].index = Utils.indexToObject(self.components, getXMLString(xmlFile, partnamei .. "#index"));
      local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#minRot"));
      self.RotParts[i].minRot = {};
      self.RotParts[i].minRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts[i].minRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts[i].minRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, partnamei .. "#maxRot"));
      self.RotParts[i].maxRot = {};
      self.RotParts[i].maxRot[1] = Utils.degToRad(Utils.getNoNil(x, 0));
      self.RotParts[i].maxRot[2] = Utils.degToRad(Utils.getNoNil(y, 0));
      self.RotParts[i].maxRot[3] = Utils.degToRad(Utils.getNoNil(z, 0));
      self.RotParts[i].rotTime = Utils.getNoNil(getXMLString(xmlFile,  partnamei .. "#rotSpeed"), 2)*1000;
    end;
	self.rotParts = false;
		---- particulas
	self.groundParticleSystems = {};
    local groundParticleSystemCount = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.groundParticleSystems#count"), 0);
    for i=1, groundParticleSystemCount do
        local namei = string.format("vehicle.groundParticleSystems.part%d", i);
		local nodei = Utils.indexToObject(self.components, getXMLString(xmlFile, namei .. "#index"));
        Utils.loadParticleSystem(xmlFile, self.groundParticleSystems, namei, nodei, false, nil, self.baseDirectory)	
		Utils.setEmittingState(self.groundParticleSystems,false)
		self.groundParticleSystemsdisableTime = 0;		
    end;
	self.groundParticleSystems1 = {};
    local groundParticleSystemCount = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.groundParticleSystems1#count"), 0);
    for i=1, groundParticleSystemCount do
        local namei = string.format("vehicle.groundParticleSystems1.part%d", i);
		local nodei = Utils.indexToObject(self.components, getXMLString(xmlFile, namei .. "#index"));
        Utils.loadParticleSystem(xmlFile, self.groundParticleSystems1, namei, nodei, false, nil, self.baseDirectory)
		Utils.setEmittingState(self.groundParticleSystems1,false)
		self.groundParticleSystems1disableTime = 0;		
    end;
	
	
	----- cultivators and rollers
	self.cultivator1 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.cultivator1#index"));
	self.cultivator2 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.cultivator2#index"));
	self.cultivator3 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.cultivator3#index"));
	self.cultivator4 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.cultivator4#index"));
	self.rollerLeft = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rollerLeft#index"));
	self.rollerRight = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rollerRight#index"));
	
	----------
	 ---------flashlights
	self.FlashLightLeft = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.indexl#index"));
    self.FlashLightRight = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.indexr#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);

	
	self.lightsbrakel = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.brakel#index"));
	self.lightsbraker = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.braker#index"));

	self.braking = false;
		-------------------------
    local workSound = getXMLString(xmlFile, "vehicle.workSound#file");
    if workSound ~= nil and workSound ~= "" then
        workSound = Utils.getFilename(workSound, self.baseDirectory); 
        self.workSound = createSample("workSound");
        self.workSoundEnabled = false;
        loadSample(self.workSound, workSound, false);
        self.workSoundPitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.workSound#pitchOffset"), 1);
        self.workSoundVolume = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.workSound#volume"), 1);
    end;

	-------------------------
    local workSound1 = getXMLString(xmlFile, "vehicle.workSound1#file");
    if workSound1 ~= nil and workSound1 ~= "" then
        workSound1 = Utils.getFilename(workSound1, self.baseDirectory); 
        self.workSound1 = createSample("workSound1");
        self.workSound1Enabled = false;
        loadSample(self.workSound1, workSound1, false);
        self.workSound1PitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.workSound1#pitchOffset"), 1);
        self.workSound1Volume = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.workSound1#volume"), 1);
    end;
	--------------
	local sound1 = getXMLString(xmlFile, "vehicle.sound1#file");
    if sound1 ~= nil and sound1 ~= "" then
        sound1 = Utils.getFilename(sound1, self.baseDirectory); 
        self.sound1 = createSample("sound1");
        self.sound1Enabled = false;
        loadSample(self.sound1, sound1, false);
        self.sound1PitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.sound1#pitchOffset"), 1);
        self.sound1Volume = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.sound1#volume"), 1);
    end;
	
	----------
	local sound2 = getXMLString(xmlFile, "vehicle.sound2#file");
    if sound2 ~= nil and sound2 ~= "" then
        sound2 = Utils.getFilename(sound2, self.baseDirectory); 
        self.sound2 = createSample("sound2");
        self.sound2Enabled = false;
        loadSample(self.sound2, sound2, false);
        self.sound2PitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.sound2#pitchOffset"), 1);
        self.sound2Volume = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.sound2#volume"), 1);
    end;
	
	----------
		local sound3 = getXMLString(xmlFile, "vehicle.sound3#file");
    if sound3 ~= nil and sound3 ~= "" then
        sound3 = Utils.getFilename(sound3, self.baseDirectory); 
        self.sound3 = createSample("sound3");
        self.sound3Enabled = false;
        loadSample(self.sound3, sound3, false);
        self.sound3PitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.sound3#pitchOffset"), 1);
        self.sound3Volume = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.sound3#volume"), 1);
    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;
		---libertad bloques
	self.setJointRotLimit = SpecializationUtil.callSpecializationsFunction("setJointRotLimit");
	self.firstDo = {};
	self.arm = {};
	local numCuttingAreas = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.cuttingAreas#count"), 0);
    for i=1, numCuttingAreas do
        local areanamei = string.format("vehicle.cuttingAreas.cuttingArea%d", i);
        self.cuttingAreas[i].groundthreshold = Utils.getNoNil(getXMLFloat(xmlFile, areanamei .. "#groundthreshold"), 0.2);
        self.cuttingAreas[i].groundindex = Utils.indexToObject(self.components, getXMLString(xmlFile, areanamei .. "#groundindex"));
    end;
	
	
	
	
	
	-----------------
	self.aiTerrainDetailChannel1 = g_currentMission.sowingChannel;
	self.AIon=false;
	self.isLowering=true;
	self.isOPen =false;
	self.OPenRollers=false;
	self.posCount = 0;
	
	self.free=true;
	self.onRollers=false;
end;	
function Visio200:delete()
	Utils.deleteParticleSystem(self.groundParticleSystems);
            Utils.deleteParticleSystem(self.groundParticleSystems1);
		Utils.deleteParticleSystem(self.wheelParticleSystems);	
    if self.workSound ~= nil then
        delete(self.workSound);
    end;
    if self.workSound1 ~= nil then
        delete(self.workSound1);
    end;
 if self.sound1 ~= nil then
        delete(self.sound1);
    end;
if self.sound2 ~= nil then
        delete(self.sound2);
    end;
if self.sound3 ~= nil then
        delete(self.sound3);
    end;

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

function Visio200:keyEvent(unicode, sym, modifier, isDown)
 
---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 Visio200:update(dt)

if self:getIsActiveForInput() then 
if InputBinding.hasEvent(InputBinding.IMPLEMENT_EXTRA2) then   --2 eingeschrieben
self.safeMode = not self.safeMode 
end;
end;


if self.attacherVehicle then
	---ai---
		if self.attacherVehicle.isAITractorActivated ~= nil then
			self.AIon = self.attacherVehicle.isAITractorActivated;
			
		end; 
		
	if self.attacherVehicle.isAITractorActivated then				
    	self.attacherVehicle.turnStage3Timeout = 0;
		
			if self.attacherVehicle.turnStage == 0 then
			self.isLowering=true;
			
			else
			self.isLowering=false;
			end;
	else
		
		if self.attacherVehicle.isAITractorActivated ~= nil then
			self.attacherVehicle.turnStage3Timeout = 35000;
		end; 	
	end;

---------ai end----	

	if self.fixAttacher then
			local implement = self.attacherVehicle:getImplementByObject(self);
			if implement ~= nil then
				local joint = self.attacherVehicle.attacherJoints[implement.jointDescIndex];
				self.saveJoint = self.attacherVehicle.attacherJoints[implement.jointDescIndex];
				self.maxRotJoint = joint.maxRotLimit;
				self.attacherJointIndex = implement.jointDescIndex;
				self.rotationCopy  = joint.minRot;
				joint.minRot = {Utils.degToRad(2),0,0};			
				joint.maxRotLimit = {0, 0, 0};
				setJointRotationLimit(joint.jointIndex, 2, true, 0, 0);
			end;
			self.fixAttacher = false;
		end;

if self.isEntered then
--- flashLights
if self:getIsActive() then --aislarlo de otros objetos
	if self.FlashLightLeft ~= nil then
            if self.flashLightLeftActive then
            	setVisibility(self.FlashLightLeft, self.flashLightLeftActive);
				
	    else
            	setVisibility(self.FlashLightLeft, self.flashLightLeftActive);
	    end;
        end;

	if self.FlashLightRight ~= nil then
            if self.FlashLightRightActive then
            	setVisibility(self.FlashLightRight, self.flashLightRightActive);
	    else
            	setVisibility(self.FlashLightRight, 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 = 500;
				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 = 500;
				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 = 500;
				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 = 500;
				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 = 500;
				
				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 = 500;
			
				self.flashLightLeftActive = false;
				self.flashLightRightActive = false;
			end;
		end;
		else
		
	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;
end;

---particulas ruedas

local dens = 0; local dens1; local dens2; local dens3;
	 local x,y,z = getWorldTranslation(self.wheels[1].repr);
	 local x1,y1,z1 = getWorldTranslation(self.wheels[2].repr);
	 local x2,y2,z2 = getWorldTranslation(self.wheels[2].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 dens > 0 and self.lastSpeed*self.speedDisplayScale*3600 > 4 then
		
		
		for k=1, 2 do
			Utils.setEmittingState(self.wheelParticleSystems[k].particleSystems, self.wheels[k].hasGroundContact);
		end;
	else
		for i=1, table.getn(self.wheelParticleSystems) do
			Utils.setEmittingState(self.wheelParticleSystems[i].particleSystems, false);
		end;
	
	end;
	
	--------------------brake------------------------
   inputAxisY = InputBinding.getAnalogInputAxis(InputBinding.AXIS_FORWARD);

        if InputBinding.isAxisZero(inputAxisY) then
        inputAxisY = InputBinding.getDigitalInputAxis(InputBinding.AXIS_FORWARD);
        end;
	
		if (self.movingDirection*self.lastSpeed*(-inputAxisY)) < -0.001 then
			setVisibility(self.lightsbrakel, true);
			setVisibility(self.lightsbraker, true);
			self.rotParts=true;
			self.translation1Max=true;
			self.braking = true;
			
		else
		     setVisibility(self.lightsbrakel, false);
			setVisibility(self.lightsbraker, false);
			self.braking = false;
			self.rotParts=false;
			self.translation1Max=false;
			
		end;
	
	--------------
	if self.time > self.groundParticleSystemsdisableTime then
           Utils.setEmittingState(self.groundParticleSystems, false);
    end;
--[[	if self.time > self.groundParticleSystems1disableTime then
           Utils.setEmittingState(self.groundParticleSystems1, false);
    end;]]		
	self.wasToFast = false;
	
	 if self:getIsActiveForInput()  then
        if InputBinding.hasEvent(InputBinding.OPEN) then
		          self.isOPen = not self.isOPen;
		 end;
		 
		  if InputBinding.hasEvent(InputBinding.LOWER) then
				 self.isLowering = not self.isLowering;
		 end;
		if self.isLowering==false then
		   if InputBinding.hasEvent(InputBinding.HEIGHT) then
				if not Input.isKeyPressed(Input.KEY_shift) then
				self.posCount =  self.posCount+1;
				else
				self.posCount =  self.posCount-1;
				end;
			end;
		end;
	
    end;
	
		
	
	
	
	
	
	if self.isLowering==true then
		if not self.sound3Enabled and not self.AIon and self:getIsActiveForSound() then
		setSamplePitch(self.sound3, self.sound3PitchOffset);
		playSample(self.sound3, 0, self.sound3Volume, 0);
		self.sound3Enabled = true;
		end;
		self.rotation1Max=false;
		self.rotation2Max=false;
		self.rotation12Max=false;
		self.rotation13Max=false;
	elseif self.isLowering==false then
		if not self.sound3Enabled  and not self.AIon and self:getIsActiveForSound() then
		setSamplePitch(self.sound3, self.sound3PitchOffset);
		playSample(self.sound3, 0, self.sound3Volume, 0);
		self.sound3Enabled = true;
		end;
		self.rotation1Max=true;
		self.rotation2Max=true;
		self.rotation12Max=true;
		self.rotation13Max=true;
	end;
	
	local x, y, z = getRotation(self.rotation1.node);
			if x > Utils.degToRad(-8)  then	
				if self.isLowering==true then
				self.free=true;
				end;
			elseif x < Utils.degToRad(-1)  then
				if self.isLowering==false then
				self.free=false;
				end;
			end;
			if x < Utils.degToRad(-15)  then
					self.freeRollers=false;
			end;
			
			
			if x < Utils.degToRad(-64.8)  then	
				if self.sound3Enabled then
				stopSample(self.sound3);
				self.sound3Enabled = false;
				end;
			end;
			if x > Utils.degToRad(-0.3)  then	
				if self.sound3Enabled then
				stopSample(self.sound3);
				self.sound3Enabled = false;
				end;
			end;
			
			if x < Utils.degToRad(-50)  then	
			if self.isOPen then
				self.closeCultivators=false;
				if not self.sound1Enabled and not self.AIon and self:getIsActiveForSound() then
				setSamplePitch(self.sound1, self.sound1PitchOffset);
				playSample(self.sound1, 0, self.sound1Volume, 0);
				self.sound1Enabled = true;
				end;
		
			elseif not self.isOPen then
				self.closeCultivators=true;
				if not self.sound1Enabled and not self.AIon and self:getIsActiveForSound() then
				setSamplePitch(self.sound1, self.sound1PitchOffset);
				playSample(self.sound1, 0, self.sound1Volume, 0);
				self.sound1Enabled = true;
				end;
			end;
			end;
			
			
		
		
		
		if self.closeCultivators==false then
			 self.rotation3Max=true;
			 self.rotation4Max=true;
			 self.rotation5Max=true;
			 self.rotation6Max=true;
			self.translation2Max=true;
			self.translation3Max=true;
		elseif self.closeCultivators==true then
				self.OPenRollers =false;
				self.onWork=false;
				self.onRollers=false;
		end;
		local x, y, z = getTranslation(self.translation2.node)
			if z>0.7 then
				 self.rotation10Max=true;
			end;
			if z<1.16 then
				 self.rotation10Max=false;
			end;
		local x, y, z = getTranslation(self.translation3.node)
			if z<-1.7 then
				 self.rotation11Max=true;
			end;
			if z>-2.06 then
				 self.rotation11Max=false;
			end;
		local x, y, z = getRotation(self.rotation3.node);
			if y> Utils.degToRad(71)  then
				if self.sound1Enabled then
				stopSample(self.sound1);
				self.sound1Enabled = false;
				end;
				
					if self.posCount <= 0 then
						self.posCount = 0;
					end;
					
					local x2, y2, z3 = getTranslation(self.translation4.node)
					local trans2 = {x2,y2,z2};
				
					if self.posCount == 0 then
					
						local newTrans2 = Utils.getMovedLimitedValues(trans2, {x2,-0.25689,z2}, {x2,0,z2}, 3, 800, dt,true);
						setTranslation(self.translation4.node, unpack(newTrans2));
						setTranslation(self.translation5.node, unpack(newTrans2));
						setTranslation(self.translation6.node, unpack(newTrans2));
						setTranslation(self.translation7.node, unpack(newTrans2));
						setTranslation(self.translation8.node,0,0,0);
					
					elseif self.posCount == 1 then
						local newTrans2 = Utils.getMovedLimitedValues(trans2, {x2,0,z2}, {x2,-0.05,z2}, 3, 800, dt,true);
						setTranslation(self.translation4.node, unpack(newTrans2));
						setTranslation(self.translation5.node, unpack(newTrans2));
						setTranslation(self.translation6.node, unpack(newTrans2));
						setTranslation(self.translation7.node, unpack(newTrans2));						
						setTranslation(self.translation8.node,0,0,0.025);
						
					elseif self.posCount == 2 then
							local newTrans2 = Utils.getMovedLimitedValues(trans2, {x2,-0.05,z2}, {x2,-0.11,z2}, 3, 800, dt,true);
							setTranslation(self.translation4.node, unpack(newTrans2));
							setTranslation(self.translation5.node, unpack(newTrans2));
							setTranslation(self.translation6.node, unpack(newTrans2));
							setTranslation(self.translation7.node, unpack(newTrans2));
							setTranslation(self.translation8.node,0,0,0.055);
						
					elseif self.posCount == 3 then
							local newTrans2 = Utils.getMovedLimitedValues(trans2, {x2,-0.11,z2}, {x2,-0.15,z2}, 3, 800, dt,true);
							setTranslation(self.translation4.node, unpack(newTrans2));
							setTranslation(self.translation5.node, unpack(newTrans2));
							setTranslation(self.translation6.node, unpack(newTrans2));
							setTranslation(self.translation7.node, unpack(newTrans2));
							setTranslation(self.translation8.node,0,0,0.075);
						
					elseif self.posCount == 4 then
							local newTrans2 = Utils.getMovedLimitedValues(trans2, {x2,-0.15,z2}, {x2,-0.22,z2}, 3, 800, dt,true);
							setTranslation(self.translation4.node, unpack(newTrans2));
							setTranslation(self.translation5.node, unpack(newTrans2));
							setTranslation(self.translation6.node, unpack(newTrans2));
							setTranslation(self.translation7.node, unpack(newTrans2));
							setTranslation(self.translation8.node,0,0,0.1);	
							elseif self.posCount >= 5 then
						self.posCount = 0;
					end;
				
				
				
				if self.closeCultivators==false then
				self.onRollers=true;
				self.onWork=true;
				end;
			elseif y < Utils.degToRad(72)  then
				self.translation4Max=false;
				self.translation5Max=false;
				self.translation6Max=false;
				self.translation7Max=false;
				
			end;
			if y< Utils.degToRad(0.3)  then
				if self.sound1Enabled then
				stopSample(self.sound1);
				self.sound1Enabled = false;
				end;
			end;
			 if self.onRollers==true then
				self.OPenRollers =true;
			end;
		
			
					if self.OPenRollers ==true then
						if not self.sound2Enabled and not self.AIon and self:getIsActiveForSound() then
						setSamplePitch(self.sound2, self.sound2PitchOffset);
						playSample(self.sound2, 0, self.sound2Volume, 0);
						self.sound2Enabled = true;
						end;
					
						self.rotation8Max=true;
						
					elseif self.OPenRollers ==false  then
						if not self.sound2Enabled and not self.AIon  and self:getIsActiveForSound() then
						setSamplePitch(self.sound2, self.sound2PitchOffset);
						playSample(self.sound2, 0, self.sound2Volume, 0);
						self.sound2Enabled = true;
						end;
						
						self.rotation7Max=false;
						
					end;
				
			
		local x, y, z = getRotation(self.rotation7.node);
			if x < Utils.degToRad(-74)  then
				if self.isLowering==true then
				self.freeRollers=true;
				end;
			-- elseif x > Utils.degToRad(-74)  then
					-- self.freeRollers=false;
		
			end;
			
				if x > Utils.degToRad(-5)  then
					if self.closeCultivators==true then
						self.rotation9Max=false;
						 self.rotation3Max=false;
						self.rotation4Max=false;
						self.rotation5Max=false;
						self.rotation6Max=false;
						self.translation2Max=false;
						self.translation3Max=false;
				
					end;
				end;
			if x < Utils.degToRad(-74)  then
				if self.OPenRollers ==true  then
					if self.sound2Enabled then
					stopSample(self.sound2);
					self.sound2Enabled = false;
					end;
				end;
			end;
		
		local x, y, z = getRotation(self.rotation8.node);
				
				if y< Utils.degToRad(-85)  then
						if self.OPenRollers ==true  then
							self.rotation9Max=true;
						end;
				end;
				if y> Utils.degToRad(-0.2)  then
					if self.OPenRollers ==false  then
						if self.sound2Enabled then
						stopSample(self.sound2);
						self.sound2Enabled = false;
						end;
					end;
				end;
		local x, y, z = getRotation(self.rotation9.node);
				
				if y> Utils.degToRad(85)  then
					if self.OPenRollers ==true  then
					self.rotation7Max=true;
					end;
				end;

				if y< Utils.degToRad(5)  then
					if self.OPenRollers ==false  then
						self.rotation8Max=false;
					end;
				end;
			
				
				
				
				
				
				
		if	self.free==true  and self.onWork==true then
		  local toFast = self:doCheckSpeedLimit() and self.lastSpeed*3600 > 15;
            if not toFast then
			-- renderText(0.1, 0.05, 0.03," on work");
			if self.attacherVehicle.lastSpeed*3600 > 2  then
			local x,y,z = getRotation(self.wheels[1].repr);	
			setRotation(self.cultivator1, z, y, x/2);
			setRotation(self.cultivator2, z, y, (x*-1)/2);
			setRotation(self.cultivator3, z, y, (x*-1)/2);
			setRotation(self.cultivator4, z, y, x/2);
			end;
			local area = 0;
			for k, cuttingArea in pairs(self.cuttingAreas) do
			    local x,y,z = getWorldTranslation(cuttingArea.groundindex);
	            local terrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 0, z);
				if (k == 1 or  k == 2 or k == 3 or  k == 4)and cuttingArea.groundindex ~= nil and terrainHeight+cuttingArea.groundthreshold >= y then
					local x,y,z = getWorldTranslation(cuttingArea.start);
					local x1,y1,z1 = getWorldTranslation(cuttingArea.width);
					local x2,y2,z2 = getWorldTranslation(cuttingArea.height);
if self.safeMode then
Visio200.updateSafeArea (x, z, x1, z1, x2, z2) 
else 
Utils.updatePloughArea (x, z, x1, z1, x2, z2); 
end;
                    local pixelToQm = 2048 / 8192 * 2048 / 8192; -- 8192px are mapped to 2048m
                    local qm = area*pixelToQm;
                    local ha = qm/10000;
					
				if self.attacherVehicle.lastSpeed*3600 > 3  then
					if g_currentMission.environment.lastRainScale <= 0.1 and g_currentMission.environment.timeSinceLastRain > 30 then
						self.groundParticleSystemsdisableTime = self.time + 40;
						Utils.setEmittingState(self.groundParticleSystems, true)
													
					end;
						if not self.workSoundEnabled and not self.AIon and self:getIsActiveForSound() then
							setSamplePitch(self.workSound, self.workSoundPitchOffset);
							playSample(self.workSound, 0, self.workSoundVolume, 0);
							self.workSoundEnabled = true;
						end;
				elseif self.attacherVehicle.lastSpeed*3600 < 3 then
						Utils.setEmittingState(self.groundParticleSystems, false)
						 if self.workSoundEnabled then
							stopSample(self.workSound);
							self.workSoundEnabled = false;
							end;
				
				
				end;	
			end;
		end;
	else
			Utils.setEmittingState(self.groundParticleSystems, false)
						 if self.workSoundEnabled then
							stopSample(self.workSound);
							self.workSoundEnabled = false;
							end;
	end;
		self.wasToFast = toFast;
		else
		Utils.setEmittingState(self.groundParticleSystems, false)
						 if self.workSoundEnabled then
							stopSample(self.workSound);
							self.workSoundEnabled = false;
							end;
	end;		
		if	self.freeRollers==true  and self.free==true then
		 
            if not toFast then
			if self.attacherVehicle.lastSpeed*3600 > 2  then
			local x,y,z = getRotation(self.wheels[1].repr);	
			setRotation(self.rollerLeft, z, y, x);
			setRotation(self.rollerRight, z, y, x*-1);
			end;
				local area = 0;
			
			for k, cuttingArea in pairs(self.cuttingAreas) do
			    local x,y,z = getWorldTranslation(cuttingArea.groundindex);
	            local terrainHeight = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 0, z);
					-- renderText(0.1, 0.07, 0.03," on roll");
				if (k == 5 or  k == 6)and cuttingArea.groundindex ~= nil and terrainHeight+cuttingArea.groundthreshold >= y then
					local x,y,z = getWorldTranslation(cuttingArea.start);
					local x1,y1,z1 = getWorldTranslation(cuttingArea.width);
					local x2,y2,z2 = getWorldTranslation(cuttingArea.height);
					
if self.safeMode then
Visio200.updateSafeArea (x, z, x1, z1, x2, z2) 
else 
Utils.updateCultivatorArea (x, z, x1, z1, x2, z2); 
end;
                    local pixelToQm = 2048 / 8192 * 2048 / 8192; -- 8192px are mapped to 2048m
                    local qm = area*pixelToQm;
                    local ha = qm/10000;
				if self.attacherVehicle.lastSpeed*3600 > 3 then
					if g_currentMission.environment.lastRainScale <= 0.1 and g_currentMission.environment.timeSinceLastRain > 30 then
						self.groundParticleSystems1disableTime = self.time + 40;
						Utils.setEmittingState(self.groundParticleSystems1, true)
					end;
						if not self.workSound1Enabled  and not self.AIon and self:getIsActiveForSound() then
							setSamplePitch(self.workSound1, self.workSound1PitchOffset);
							playSample(self.workSound1, 0, self.workSound1Volume, 0);
							self.workSound1Enabled = true;
						end;
				elseif self.attacherVehicle.lastSpeed*3600 < 3 then
						Utils.setEmittingState(self.groundParticleSystems1, false)
						 if self.workSound1Enabled then
							stopSample(self.workSound1);
							self.workSound1Enabled = false;
							end;
				
				
				end;	
			end;
		end;
	
	
	else
			Utils.setEmittingState(self.groundParticleSystems1, false)
						 if self.workSound1Enabled then
							stopSample(self.workSound1);
							self.workSound1Enabled = false;
							end;
	end;
		self.wasToFast = toFast;
		else
		Utils.setEmittingState(self.groundParticleSystems1, false)
						 if self.workSound1Enabled then
							stopSample(self.workSound1);
							self.workSound1Enabled = false;
							end;
	end;		
	
end;---isentered
end;---attacher	
 -------------
	if self.translation1Max ~= 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.translation2Max ~= 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.translation3Max ~= 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.translation4Max ~= 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.translation5Max ~= 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;
	
	if self.translation6Max ~= nil then
					local x, y, z = getTranslation(self.translation6.node);
					local trans = {x,y,z};
					local newTrans = Utils.getMovedLimitedValues(trans, self.translation6.maxTrans, self.translation6.minTrans, 3, self.translation6.transTime, dt, not self.translation6Max);
					setTranslation(self.translation6.node, unpack(newTrans));
				end;
	
	if self.translation7Max ~= nil then
					local x, y, z = getTranslation(self.translation7.node);
					local trans = {x,y,z};
					local newTrans = Utils.getMovedLimitedValues(trans, self.translation7.maxTrans, self.translation7.minTrans, 3, self.translation7.transTime, dt, not self.translation7Max);
					setTranslation(self.translation7.node, unpack(newTrans));
				end;
	
	if self.translation8Max ~= nil then
					local x, y, z = getTranslation(self.translation8.node);
					local trans = {x,y,z};
					local newTrans = Utils.getMovedLimitedValues(trans, self.translation8.maxTrans, self.translation8.minTrans, 3, self.translation8.transTime, dt, not self.translation8Max);
					setTranslation(self.translation8.node, unpack(newTrans));
				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.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.rotation3Max ~= 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.rotation4Max ~= 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.rotation5Max ~= 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.rotation6Max ~= 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.rotation7Max ~= 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.rotation7Max ~= 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.rotation8Max ~= 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.rotation9Max ~= 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.rotation10Max ~= 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.rotation11Max ~= 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.rotation12Max ~= 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.rotation13Max ~= nil then
        local x, y, z = getRotation(self.rotation13.node);
        local rot = {x,y,z};
        local newRot = Utils.getMovedLimitedValues(rot, self.rotation13.maxRot, self.rotation13.minRot, 3, self.rotation13.rotTime, dt, not self.rotation13Max);
        setRotation(self.rotation13.node, unpack(newRot));
    end;
		if self.rotParts ~= nil   then
				for i=1, table.getn(self.RotParts) do
					local rot = {getRotation(self.RotParts[i].index)};
					local newRot = Utils.getMovedLimitedValues(rot, self.RotParts[i].maxRot, self.RotParts[i].minRot, 3, self.RotParts[i].rotTime, dt, not self.rotParts);
					setRotation(self.RotParts[i].index, unpack(newRot));
				end;
				end;
	--- asignacion de ejes de libertad  de rotacion segun condiciones de emsamblage  0 x, 2 y ,1 z 
		
		
	self:setJointRotLimit(self.componentJoints[1],6, 0, 1000,self.free == true, 0,dt);	
	self:setJointRotLimit(self.componentJoints[2],60, 0, 1000,self.isEntered == true, 1,dt);
	self:setJointRotLimit(self.componentJoints[3],40, 0, 1000,self.isEntered == true, 2,dt);
	self:setJointRotLimit(self.componentJoints[4],95, 0, 1000,self.isEntered == true, 0,dt);
	self:setJointRotLimit(self.componentJoints[5],9, 0, 1000,self.freeRollers == true, 0,dt);	
	self:setJointRotLimit(self.componentJoints[12],8, 0, 1000,self.free==true, 0,dt);	
	-- juntas

		local joint = self.componentJoints[1];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[2];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[3];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[4];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[5];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[6];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[7];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[8];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[9];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[10];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[11];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[12];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[13];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
			local joint = self.componentJoints[14];
		setJointFrame(joint.jointIndex, 0,joint.jointNode);
		self:setHydraulicDirection();


end;
function Visio200:draw()

 if self.safeMode then 
g_currentMission:addHelpButtonText("switch to normal mode", InputBinding.IMPLEMENT_EXTRA2); ---eingeschrieben
else 
g_currentMission:addHelpButtonText("switch to safe mode", InputBinding.IMPLEMENT_EXTRA2); 	---eingeschrieben
end;

if self.AIon == false then
	
	g_currentMission:addExtraPrintText("visio200 :x open/close,n lower/raise,m height work ");
	end;

end;
function Visio200:onAttach()
self.isOPen=false;
self.isEntered = true;
self.fixAttacher = true; 
end;

Visio200.updateSafeArea = function(l_18_0, l_18_1, l_18_2, l_18_3, l_18_4, l_18_5)
  local cultiId = g_currentMission.cultivatorChannel
  local sowingId = g_currentMission.sowingChannel
  local detailId = g_currentMission.terrainDetailId
  local ploughId = g_currentMission.ploughChannel
  local sprayId = g_currentMission.sprayChannel
  local x, z, widthX, widthZ, heightX, heightZ = Utils.getXZWidthAndHeight(detailId, l_18_0, l_18_1, l_18_2, l_18_3, l_18_4, l_18_5)
  Utils.updateDestroyCommonArea(l_18_0, l_18_1, l_18_2, l_18_3, l_18_4, l_18_5)
  setDensityMaskedParallelogram(detailId, x, z, widthX, widthZ, heightX, heightZ, cultiId, 1, detailId, sowingId, 1, 1)
  setDensityMaskedParallelogram(detailId, x, z, widthX, widthZ, heightX, heightZ, cultiId, 1, detailId, ploughId, 1, 1)
  setDensityParallelogram(detailId, x, z, widthX, widthZ, heightX, heightZ, sowingId, 1, 0)
  setDensityParallelogram(detailId, x, z, widthX, widthZ, heightX, heightZ, ploughId, 1, 0)
  setDensityParallelogram(detailId, x, z, widthX, widthZ, heightX, heightZ, sprayId, 1, 0)
 end


function Visio200:onDetach()
	self.rotParts=false;
	self.translation1Max=false;
	
    if self.deactivateOnDetach then
        Visio200.onDeactivate(self);
    else
        Visio200.onDeactivateSounds(self)
    end;

setVisibility(self.lightsbrakel, false);
setVisibility(self.lightsbraker, false);
self.flashLightRightActive = false;
self.flashLightLeftActive = false;
setVisibility(self.FlashLightRight, false);
setVisibility(self.FlashLightLeft, false);

 self.isEntered = false;
 local joint = self.saveJoint; 
	joint.minRot = self.rotationCopy;
	joint.maxRotLimit = self.maxRotJoint;

end;

function Visio200:onLeave()

    if self.deactivateOnLeave then
        Visio200.onDeactivate(self);
    else
        Visio200.onDeactivateSounds(self)
    end;

end;

function Visio200:onDeactivate()

    Visio200.onDeactivateSounds(self)
   

end;

function Visio200:onDeactivateSounds()
	 if self.workSoundEnabled then
        stopSample(self.workSound);
        self.workSoundEnabled = false;
    end;
    if self.workSound1Enabled then
        stopSample(self.workSound1);
        self.workSound1Enabled = false;
    end;
	 if self.sound1Enabled then
        stopSample(self.sound1);
        self.sound1Enabled = false;
    end;
	 if self.sound2Enabled then
        stopSample(self.sound25);
        self.sound2Enabled = false;
    end;
	 if self.sound3Enabled then
        stopSample(self.sound3);
        self.sound3Enabled = false;
    end;
end;
function Visio200: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 Visio200: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 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;
