--
-- @Lightbarscript by PATAR
--
-- @Modify by Repi @MRA-Modding
-- @DATE 03/12/2011
-- 
-- frei verwendbar - keine erlaubnis nötig  |  free for use - no permission needed.
-- Modifikationen erst nach Rücksprache!    |  modifications only with my permission.
--

greenstar2 = {};

function greenstar2.prerequisitesPresent(specializations)
    return true;
end;
function greenstar2:load(xmlFile)
	local lampscount = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.lamps#count"), 0);
	self.lamps = {};
	if lampscount ~= 0 then
		for i=1, lampscount do
			local lampnumber = string.format("vehicle.lamps.lamp%d", i);	
			self.lamps[i] = Utils.indexToObject(self.components, getXMLString(xmlFile, lampnumber .. "#index"));	
		end;	
	end;
	
    self.schnecke = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.schnecke#index"));
    self.rolle1 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rolle1#index"));
    self.rolle2 = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.rolle2#index"));
end;
function greenstar2:delete()
end;
function greenstar2:mouseEvent(posX, posY, isDown, isUp, button)
end;
function greenstar2:keyEvent(unicode, sym, modifier, isDown)
end;
function greenstar2:update(dt)
	local prozent = self.grainTankFillLevel/self.grainTankCapacity*100;
	if prozent >= 7 then
		setVisibility(self.lamps[1], true)
	else
		setVisibility(self.lamps[1], false)
	end;
	if prozent >= 14 then
		setVisibility(self.lamps[2], true)
	else
		setVisibility(self.lamps[2], false)
	end;
	if prozent >= 21 then
		setVisibility(self.lamps[3], true)
	else
		setVisibility(self.lamps[3], false)
	end;
	if prozent >= 28 then
		setVisibility(self.lamps[4], true)
	else
		setVisibility(self.lamps[4], false)
	end;
	if prozent >= 35 then
		setVisibility(self.lamps[5], true)
	else
		setVisibility(self.lamps[5], false)
	end;
	if prozent >= 42 then
		setVisibility(self.lamps[6], true)
	else
		setVisibility(self.lamps[6], false)
	end;
	if prozent >= 50 then
		setVisibility(self.lamps[7], true)
	else
		setVisibility(self.lamps[7], false)
	end;
	if prozent >= 57 then
		setVisibility(self.lamps[8], true)
	else
		setVisibility(self.lamps[8], false)
	end;
	if prozent >= 64 then
		setVisibility(self.lamps[9], true)
	else
		setVisibility(self.lamps[9], false)
	end;
	if prozent >= 71 then
		setVisibility(self.lamps[10], true)
	else
		setVisibility(self.lamps[10], false)
	end;
	if prozent >= 78 then
		setVisibility(self.lamps[11], true)
	else
		setVisibility(self.lamps[11], false)
	end;
	if prozent >= 85 then
		setVisibility(self.lamps[12], true)
	else
		setVisibility(self.lamps[12], false)
	end;
	if prozent >= 92 then
		setVisibility(self.lamps[13], true)
	else
		setVisibility(self.lamps[13], false)
	end;
	if prozent >= 100 then
		setVisibility(self.lamps[14], true)
	else
		setVisibility(self.lamps[14], false)
	end;
	
	for i=1,table.getn(self.movingParts) do
		Cylindered.updateMovingPart(self, self.movingParts[i]);
	end;
	
    if self.isThreshing and self.schnecke ~= nil then
        rotate(self.schnecke, dt*0.01, 0, 0);
    end;

    if self.isThreshing and self.rolle1 ~= nil then
        rotate(self.rolle1, dt*0.01, 0, 0);
    end;
	
    if self.isThreshing and self.rolle2 ~= nil then
        rotate(self.rolle2, dt*0.01, 0, 0);
    end;
end;
function greenstar2:draw()
end;