--
-- Autor: Lechu
-- Data:20-02-2013
-- Dla www.lsmodteam.pl
-- Zakaz jakiejkolwiek kurwa edycji!!!
-- Zakaz wyciagania do innych modeli!!!
-- Uszanuj moja prace!!!

Bujaj = {};

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

function Bujaj:load(xmlFile)
 ----------------------------------------Bujanie sie kabiny-------------------
local rotationPartNodebujanie = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, "vehicle.bujanie#index"));
   	if rotationPartNodebujanie ~= nil then
        self.rotationPartbujanie = {};
        self.rotationPartbujanie.node = rotationPartNodebujanie;

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

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

        self.rotationPartbujanie.rotTime = Utils.getNoNil(getXMLString(xmlFile, "vehicle.bujanie#rotTime"), 2)*1000;
        self.rotationPartbujanie.touchRotLimit = Utils.degToRad(Utils.getNoNil(getXMLString(xmlFile, "vehicle.bujanie#touchRotLimit"), 10));
    end;
		self.bujaj = 80;
end;

function Bujaj:delete()
end;

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

function Bujaj:keyEvent(unicode, sym, modifier, isDown)
------------------------Kabina--------------------------------
	--[[if self.isEntered then
		if isDown and sym == Input.KEY_KP_enter then
			self.kabina = not self.kabina;
		end;
	end;	]]
end;	

function Bujaj:update(dt)
------------------------bujanie sie kabiny-----------------------------
	if self.isMotorStarted then
		self.bujaj = self.bujaj - dt;
		if self.bujaj < 0 then
			self.bujaniekabiny = not self.bujaniekabiny;
			self.bujaj = 80;
		end;
	end;	
	if self.rotationPartbujanie ~= nil then
		local x, y, z = getRotation(self.rotationPartbujanie.node);
		local rot = {x,y,z};
		local newRot = Utils.getMovedLimitedValues(rot, self.rotationPartbujanie.maxRot, self.rotationPartbujanie.minRot, 3, self.rotationPartbujanie.rotTime, dt, not self.bujaniekabiny);
		setRotation(self.rotationPartbujanie.node, unpack(newRot));
  	end;	
end;

function Bujaj:draw()
end;