Hydraulic = {};

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

function Hydraulic:load(xmlFile)

	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 = getWorldTranslation(self.hydraulics[i].punch);
		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;
end;

function Hydraulic:delete()
end;

function Hydraulic:readStream(streamId, connection)
end;

function Hydraulic:writeStream(streamId, connection)	
end;

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

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

function Hydraulic:update(dt)
	if self:getIsActive() then		
		for _, part in pairs(self.movingParts) do
			Cylindered.setDirty(self, part);
		end;
		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);
			if i == 1 then
				setDirection(self.hydraulics[i].node, x, y, z, 1, 1, 0);
			else
				setDirection(self.hydraulics[i].node, x, y, z, 0, 1, 0);
			end;
			local distance = Utils.vector3Length(ax-bx, ay-by, az-bz);
			if self.hydraulics[i].doScale then
				local xScale, yScale, zScale = getScale(self.hydraulics[i].punch);
				local newScale = yScale * (distance / self.hydraulics[i].punchDistance);
				setScale(self.hydraulics[i].punch, 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;
end;

function Hydraulic:updateTick(dt)
end;

function Hydraulic:draw()
end;

function Hydraulic:onAttach(attacherVehicle)
end;

function Hydraulic:onDetach()
end;