
-- by boembchen
--

Allrads = {};

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

function Allrads:load(xmlFile)


		
		 
		 self.Allrad = false
		 
		 
	-- Allradwelle --
	self.GelenkF = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Allradwelle.GelenkF#index"));
    self.Welle = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Allradwelle.Welle#index"));    

	self.RotPoint = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.Allradwelle.RotPoint#index"));
    self.lightsAllrad = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.extra_lights.allrad#index"));
	
    self.allSwitch = {}; 
	self.allSwitch.node = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.allSwitch#index"));
	self.allSwitch.off = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.allSwitch#off"));
	self.allSwitch.on = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.allSwitch#on"));
end;

function Allrads:delete()

end;

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

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

function Allrads:update(dt)

    if self:getIsActiveForInput() and self.isEntered then
		
		if InputBinding.hasEvent(InputBinding.ALLRAD) then
		   	if self.Allrad == false then
		   	   self.Allrad = true
		   	else
		   		self.Allrad = false
		   	end;
		end;

		-- Allrad -- driveMode 2 = Allrad , driveMode 0 = kein Antrieb --
		if self.Allrad == true then
		 	self.wheels[1].driveMode =2
		 	self.wheels[2].driveMode =2
		 	self.wheels[3].driveMode =2
		 	self.wheels[4].driveMode =2
		else
		 	self.wheels[1].driveMode =0
		 	self.wheels[2].driveMode =0
		 	self.wheels[3].driveMode =2
		 	self.wheels[4].driveMode =2
		end;
		if self.Allrad then
			setRotation(self.allSwitch.node, Utils.degToRad(10),0,0);
			setVisibility(self.allSwitch.off, false);
			setVisibility(self.allSwitch.on, true);
			setVisibility(self.lightsAllrad, false);
		else
			setRotation(self.allSwitch.node, Utils.degToRad(-10),0,0);
			setVisibility(self.allSwitch.off, true);
			setVisibility(self.allSwitch.on, false);
			setVisibility(self.lightsAllrad, true);
		end;
	   -- Allradwelle --
	   if self.Allrad == true then
	   self.PointRot = getRotation(self.RotPoint)

       setRotation(self.GelenkF,0 ,0 ,self.PointRot);
       setRotation(self.Welle,0 ,0 ,self.PointRot);
	   
	   end;
				
	end;			 

end;

function Allrads:draw()

end;

