forcaPunteReclinabili = {};
function forcaPunteReclinabili.prerequisitesPresent(specializations) return true; end;
function forcaPunteReclinabili:load(xmlFile) 
	self.setsceltaPunteB = SpecializationUtil.callSpecializationsFunction("setsceltaPunteB"); 
	self.tubiIdraulici = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.tubiIdraulici#index")); self.currentBalle = -1;self.sceltaPunteB = 3; self.currentSupport = true; self.currentPosizione = 2; end;
function forcaPunteReclinabili:readStream(streamId, connection) self:setsceltaPunteB(streamReadInt8(streamId), true); end;
function forcaPunteReclinabili:writeStream(streamId, connection) streamWriteInt8(streamId, self.sceltaPunteB); end;
function forcaPunteReclinabili:setsceltaPunteB(int, noEventSend) self.sceltaPunteB = int; setsceltaPunteBEvent.sendEvent(self, int, noEventSend); end;
function forcaPunteReclinabili:loadFromAttributesAndNodes(xmlFile, key, resetVehicles)
	local sceltaPunteB = getXMLInt(xmlFile, key .. "#sceltaPunteB"); if sceltaPunteB ~= nil then self:setsceltaPunteB(sceltaPunteB-1); end;
	return BaseMission.VEHICLE_LOAD_OK; end;
function forcaPunteReclinabili:getSaveAttributesAndNodes(nodeIdent) local attributes = 'sceltaPunteB="' .. self.sceltaPunteB .. '"'; return attributes; end;
function forcaPunteReclinabili:delete() end;
function forcaPunteReclinabili:mouseEvent(posX, posY, isDown, isUp, button) end;
function forcaPunteReclinabili:keyEvent(unicode, sym, modifier, isDown) end;
function forcaPunteReclinabili:update(dt)
	if self:getIsActiveForInput() or self.currentAttacco == 1 then 
		if InputBinding.hasEvent(InputBinding.OpenClose) and self.setBaleLoader == 0 and not self.balesAttached then 
			if self.currentSupport then self:playAnimation("telaioMobile", 1); self:setcurrentSupport(false); self:setcurrentBalle(-1); 
			else self:playAnimation("telaioMobile", -1); self:setcurrentSupport(true); self:setcurrentBalle(-1); end; end; end;
	if g_currentMission.player ~= nil and g_currentMission.player.isEntered then
		local px, py, pz = getWorldTranslation(g_currentMission.player.rootNode);
		local tx, ty, tz = getWorldTranslation(self.components[1].node);
		if self.attacherVehicle ~= nil and Utils.vector3Length(px-tx, py-ty, pz-tz) < 3 then
			if InputBinding.hasEvent(InputBinding.selectRightKP) and self.currentPunte == 11 and not self:getIsAnimationPlaying("punte") then if self.sceltaPunteB == 1 then self:setsceltaPunteB(8); else self:setsceltaPunteB(4); end; end;
			if InputBinding.hasEvent(InputBinding.selectCenterKP) and self.currentPunte == 11 and not self:getIsAnimationPlaying("punte") then if self.sceltaPunteB == 1 then self:setsceltaPunteB(2); end; if self.sceltaPunteB == 5 then self:setsceltaPunteB(6); end; end;
			if InputBinding.hasEvent(InputBinding.selectLeftKP) and self.currentPunte == 11 and not self:getIsAnimationPlaying("punte") then if self.sceltaPunteB == 5 then self:setsceltaPunteB(10); else self:setsceltaPunteB(0); end; end;
			if self.sceltaPunteB == 3 then g_currentMission:addExtraPrintText(g_i18n:getText("baleLoaderRotondeNoPilaN"));
			elseif self.sceltaPunteB == 1 then g_currentMission:addExtraPrintText(g_i18n:getText("baleLoaderRotondePilaN")); 
			elseif self.sceltaPunteB == 5 then g_currentMission:addExtraPrintText(g_i18n:getText("baleLoaderNormali")); end;
			if self.currentPunte == 11 and not self:getIsAnimationPlaying("punte") then
				if self.sceltaPunteB == 1 then g_currentMission:addHelpButtonText(g_i18n:getText("punteEsterne"), InputBinding.selectRightKP); g_currentMission:addHelpButtonText(g_i18n:getText("punteCentrali"), InputBinding.selectCenterKP);
				elseif self.sceltaPunteB == 3 or self.sceltaPunteB == 7 then g_currentMission:addHelpButtonText(g_i18n:getText("punteInterne"), InputBinding.selectLeftKP); g_currentMission:addHelpButtonText(g_i18n:getText("punteEsterne"), InputBinding.selectRightKP);
				elseif self.sceltaPunteB == 5 then g_currentMission:addHelpButtonText(g_i18n:getText("punteInterne"), InputBinding.selectLeftKP); g_currentMission:addHelpButtonText(g_i18n:getText("punteCentrali"), InputBinding.selectCenterKP); end; end; end; end; end;
function forcaPunteReclinabili:updateTick(dt) 
	if     self.sceltaPunteB == 0 then self:playAnimation("punteInterne", 1, nil, true); self.sceltaPunteB = 1;
	elseif self.sceltaPunteB == 2 then self:playAnimation("punteInterne", -1, nil, true); self.sceltaPunteB = 3;
	elseif self.sceltaPunteB == 4 then self:playAnimation("punteEsterne", 1, nil, true); self.sceltaPunteB = 5;
	elseif self.sceltaPunteB == 6 then self:playAnimation("punteEsterne", -1, nil, true); self.sceltaPunteB = 7;
	elseif self.sceltaPunteB == 8 then self:playAnimation("punteInterneEsterne", 1, nil, true); self.sceltaPunteB = 5;
	elseif self.sceltaPunteB == 10 then self:playAnimation("punteEsterneInterne", 1, nil, true); self.sceltaPunteB = 1; end; end;
function forcaPunteReclinabili:draw() if self.setBaleLoader == 0 and not self.balesAttached then if self.currentSupport then g_currentMission:addHelpButtonText(g_i18n:getText("forcaApri"), InputBinding.OpenClose); else g_currentMission:addHelpButtonText(g_i18n:getText("forcaChiudi"), InputBinding.OpenClose); end; end;
	if self.currentAttacco > 0 and self.currentPunte == 1 and self.currentBalle > -1 then
		if self.sceltaPunteB == 3 then g_currentMission:addExtraPrintText(g_i18n:getText("baleLoaderRotondeNoPilaN"));
		elseif self.sceltaPunteB == 1 then g_currentMission:addExtraPrintText(g_i18n:getText("baleLoaderRotondePilaN")); 
		elseif self.sceltaPunteB == 5 then g_currentMission:addExtraPrintText(g_i18n:getText("baleLoaderNormali")); end; end; end;
function forcaPunteReclinabili:onAttach(attacherVehicle, jointDescIndex) setVisibility(self.tubiIdraulici, false); end;
function forcaPunteReclinabili:onDetach() setVisibility(self.tubiIdraulici, true); end;
function forcaPunteReclinabili:onDeactivate() end;
setsceltaPunteBEvent = {}; setsceltaPunteBEvent_mt = Class(setsceltaPunteBEvent, Event); InitEventClass(setsceltaPunteBEvent, "setsceltaPunteBEvent");
function setsceltaPunteBEvent:emptyNew() local self = Event:new(setsceltaPunteBEvent_mt); self.className="setsceltaPunteBEvent"; return self; end;
function setsceltaPunteBEvent:new(vehicle, sceltaPunteB) local self = setsceltaPunteBEvent:emptyNew() self.vehicle = vehicle; self.sceltaPunteB = sceltaPunteB; return self; end;
function setsceltaPunteBEvent:readStream(streamId, connection) local id = streamReadInt32(streamId);
    self.vehicle = networkGetObject(id); self.sceltaPunteB = streamReadInt8(streamId); self.vehicle:setsceltaPunteB(self.sceltaPunteB, true);
	if not connection:getIsServer() then g_server:broadcastEvent(setsceltaPunteBEvent:new(self.vehicle, self.sceltaPunteB), nil, connection, self.vehicle); end; end;
function setsceltaPunteBEvent:writeStream(streamId, connection) streamWriteInt32(streamId, networkGetObjectId(self.vehicle)); streamWriteInt8(streamId, self.sceltaPunteB); end;
function setsceltaPunteBEvent.sendEvent(vehicle, sceltaPunteB, noEventSend) if noEventSend == nil or noEventSend == false then
	if g_server ~= nil then	g_server:broadcastEvent(setsceltaPunteBEvent:new(vehicle, sceltaPunteB), nil, nil, vehicle);
	else g_client:getServerConnection():sendEvent(setsceltaPunteBEvent:new(vehicle, sceltaPunteB)); end; end; end;