variablePunteForca = {};
function variablePunteForca.prerequisitesPresent(specializations) return true; end;
function variablePunteForca:load(xmlFile)
	self.setcurrentPunte = SpecializationUtil.callSpecializationsFunction("setcurrentPunte"); self.currentPunte = 1;
    local copigliaSound = getXMLString(xmlFile, "vehicle.copigliaSound#file"); copigliaSound  = Utils.getFilename(copigliaSound, self.baseDirectory);
    self.copigliaSound = createSample("copigliaSound"); loadSample(self.copigliaSound, copigliaSound, false); 
	self.speedViolationMaxTimePunte = 2500; self.speedViolationTimerPunte = self.speedViolationMaxTimePunte; end;
function variablePunteForca:delete() end;
function variablePunteForca:readStream(streamId, connection) self:setcurrentPunte(streamReadInt8(streamId), true); end;
function variablePunteForca:writeStream(streamId, connection) streamWriteInt8(streamId, self.currentPunte); end;
function variablePunteForca:setcurrentPunte(int, noEventSend) self.currentPunte = int; setcurrentPunteEvent.sendEvent(self, int, noEventSend); end;
function variablePunteForca:mouseEvent(posX, posY, isDown, isUp, button) end;
function variablePunteForca:keyEvent(unicode, sym, modifier, isDown) end;
function variablePunteForca:update(dt)
	if self:getIsActiveForInput() and self:getIsActive() then 
		if self.currentPunte == 1 then self.speedViolationTimerPunte = self.speedViolationMaxTimePunte; end;
		if self.movingDirection > 0 and self.currentPunte > 1 then self.speedViolationTimerPunte = self.speedViolationTimerPunte - dt; end;
		if self.isServer and self.speedViolationTimerPunte < 0 and self.attacherVehicle ~= nil then self.attacherVehicle:detachImplementByObject(self); 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 and not self.balesAttached and self.fillLevel == 0 then
			if InputBinding.hasEvent(InputBinding.CAMERA_SWITCH) then 
				if     self.currentPunte == 3 and not self:getIsAnimationPlaying("copiglia") and not self:getIsAnimationPlaying("fermi") then self:setcurrentPunte(5);
				elseif self.currentPunte == 5 and not self:getIsAnimationPlaying("copiglia") and not self:getIsAnimationPlaying("fermi") then self:setcurrentPunte(3);
				elseif self.currentPunte == 7 and not self:getIsAnimationPlaying("fermi") and not self:getIsAnimationPlaying("punte") then self:setcurrentPunte(9);
				elseif self.currentPunte == 9 and not self:getIsAnimationPlaying("fermi") and not self:getIsAnimationPlaying("punte") then self:setcurrentPunte(7);	end; end;
			if InputBinding.hasEvent(InputBinding.attachCSZ) then
				if     self.currentPunte == 1 and not self:getIsAnimationPlaying("copiglia") then self:setcurrentPunte(2);
				elseif self.currentPunte == 3 and not self:getIsAnimationPlaying("copiglia") then self:setcurrentPunte(0);
				elseif self.currentPunte == 5 and not self:getIsAnimationPlaying("fermi") then self:setcurrentPunte(6);
				elseif self.currentPunte == 7 and not self:getIsAnimationPlaying("fermi") then self:setcurrentPunte(4);
				elseif self.currentPunte == 9 and not self:getIsAnimationPlaying("punte") then self:setcurrentPunte(10);
				elseif self.currentPunte == 11 and not self:getIsAnimationPlaying("punte") then self:setcurrentPunte(8); end; end;
			if self.currentPunte == 1 and not self:getIsAnimationPlaying("copiglia") then 
				g_currentMission:addHelpButtonText(g_i18n:getText("copigliaOpen"), InputBinding.attachCSZ);
			elseif self.currentPunte == 3 and not self:getIsAnimationPlaying("copiglia") then
				g_currentMission:addHelpButtonText(g_i18n:getText("copigliaClose"), InputBinding.attachCSZ);
				g_currentMission:addHelpButtonText(g_i18n:getText("cambiaOggetto"), InputBinding.CAMERA_SWITCH); 
			elseif self.currentPunte == 5 and not self:getIsAnimationPlaying("fermi") then 
				g_currentMission:addHelpButtonText(g_i18n:getText("fermiOpen"), InputBinding.attachCSZ);
				g_currentMission:addHelpButtonText(g_i18n:getText("cambiaOggetto"), InputBinding.CAMERA_SWITCH); 
			elseif self.currentPunte == 7 and not self:getIsAnimationPlaying("fermi") then
				g_currentMission:addHelpButtonText(g_i18n:getText("fermiClose"), InputBinding.attachCSZ);
				g_currentMission:addHelpButtonText(g_i18n:getText("cambiaOggetto"), InputBinding.CAMERA_SWITCH); 
			elseif self.currentPunte == 9 and not self:getIsAnimationPlaying("punte") then 
				g_currentMission:addHelpButtonText(g_i18n:getText("punteStacca"), InputBinding.attachCSZ);
				g_currentMission:addHelpButtonText(g_i18n:getText("cambiaOggetto"), InputBinding.CAMERA_SWITCH); 
			elseif self.currentPunte == 11 and not self:getIsAnimationPlaying("punte") then
				g_currentMission:addHelpButtonText(g_i18n:getText("punteAttacca"), InputBinding.attachCSZ); end; end; end; end;
function variablePunteForca:updateTick(dt)
	if     self.currentPunte == 0 then self:playAnimation("copiglia", -1, nil, true); self.currentPunte = 1; playSample(self.copigliaSound, 1, 1, 0);
	elseif self.currentPunte == 2 then self:playAnimation("copiglia", 1, nil, true); self.currentPunte = 3;
	elseif self.currentPunte == 4 then self:playAnimation("fermi", -1, nil, true); self.currentPunte = 5;
	elseif self.currentPunte == 6 then self:playAnimation("fermi", 1, nil, true); self.currentPunte = 7;
	elseif self.currentPunte == 8 then self:playAnimation("punte", -1, nil, true); self.currentPunte = 9; 
	elseif self.currentPunte == 10 then self:playAnimation("punte", 1, nil, true); self.currentPunte = 11; end; end;	
function variablePunteForca:onAttach(attacherVehicle, jointDescIndex) end;
function variablePunteForca:onDetach() self.speedViolationTimerPunte = self.speedViolationMaxTimePunte; end;
function variablePunteForca:draw() end;
setcurrentPunteEvent = {}; setcurrentPunteEvent_mt = Class(setcurrentPunteEvent, Event); InitEventClass(setcurrentPunteEvent, "setcurrentPunteEvent");
function setcurrentPunteEvent:emptyNew() local self = Event:new(setcurrentPunteEvent_mt); self.className="setcurrentPunteEvent"; return self; end;
function setcurrentPunteEvent:new(vehicle, currentPunte) local self = setcurrentPunteEvent:emptyNew() self.vehicle = vehicle; self.currentPunte = currentPunte; return self; end;
function setcurrentPunteEvent:readStream(streamId, connection) local id = streamReadInt32(streamId); self.vehicle = networkGetObject(id); self.currentPunte = streamReadInt8(streamId); self.vehicle:setcurrentPunte(self.currentPunte, true);
	if not connection:getIsServer() then g_server:broadcastEvent(setcurrentPunteEvent:new(self.vehicle, self.currentPunte), nil, connection, self.vehicle); end; end;
function setcurrentPunteEvent:writeStream(streamId, connection) streamWriteInt32(streamId, networkGetObjectId(self.vehicle)); streamWriteInt8(streamId, self.currentPunte); end;
function setcurrentPunteEvent.sendEvent(vehicle, currentPunte, noEventSend)	if noEventSend == nil or noEventSend == false then
	if g_server ~= nil then	g_server:broadcastEvent(setcurrentPunteEvent:new(vehicle, currentPunte), nil, nil, vehicle);
	else g_client:getServerConnection():sendEvent(setcurrentPunteEvent:new(vehicle, currentPunte)); end; end; end;