forcaPolivalente = {};
function forcaPolivalente.prerequisitesPresent(specializations) return true; end;
function forcaPolivalente:load(xmlFile) self.objectInRangeFP = forcaPolivalente.objectInRangeFP;
	self.currentBalle = -1; self.currentPunte = 1; self.currentSupport = true; self.sceltaPunteE = 3; self.currentPosizione = 2; self.isResetTM = true; self.isReset = 0;
	self.capacityFill = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.capacity"), 0.0);
	self.smokeParticleSystems = {}; local entry = {}; entry.particleSystems = {};
    Utils.loadParticleSystem(xmlFile, entry.particleSystems, "vehicle.smokeParticleSystem", self.components, false, nil, self.baseDirectory);
    if table.getn(entry.particleSystems) > 0 then entry.isActive = false; table.insert(self.smokeParticleSystems, entry); end; local i = 0;
	while true do local baseName = string.format("vehicle.smokeParticleSystems.smokeParticleSystem(%d)", i);
		if not hasXMLProperty(xmlFile, baseName) then break; end;
        local entry = {}; entry.particleSystems = {};
        Utils.loadParticleSystem(xmlFile, entry.particleSystems, baseName, self.components, false, nil, self.baseDirectory);
        if table.getn(entry.particleSystems) > 0 then entry.isActive = false; table.insert(self.smokeParticleSystems, entry); end;
        i = i + 1; end; end;
function forcaPolivalente:delete() 
	for _, entry in ipairs(self.smokeParticleSystems) do Utils.deleteParticleSystem(entry.particleSystems); entry.isActive = false; end; end;
function forcaPolivalente:mouseEvent(posX, posY, isDown, isUp, button) end;
function forcaPolivalente:keyEvent(unicode, sym, modifier, isDown) end;
function forcaPolivalente:objectInRangeFP(refNode) local nearestDistance = 3; local nearestBale = nil; local px, py, pz = getWorldTranslation(refNode.node);
    for index, item in pairs(g_currentMission.itemsToSave) do if item.item:isa(Bale) then local vx, vy, vz = getWorldTranslation(item.item.nodeId); local distance = Utils.vector3Length(px-vx, py-vy, pz-vz);
		if distance < nearestDistance then nearestDistance = distance; nearestBale = item.item; end; end; end; return nearestBale; end;
function forcaPolivalente: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 self.currentAttacco ~= 0 then local bale = self:objectInRangeFP(self.lockPrima); 
	if (bale ~= nil or self.setBaleLoader > 0) and self.currentSupport == true then if self.capacity > 100 then self.capacity = self.capacityBale; end; self:setcurrentSupport(true); self:playAnimation("collisione", 1); self.currentFillType = 0; elseif self.currentFillType > 0 then self.capacity = self.capacityFill; self:setcurrentSupport(false); if self.currentBalle > -1 then self:setcurrentBalle(-1); end; self:getFirstEnabledFillType(); self:playAnimation("collisione", -1); end; end;
	if self:getIsActiveForInput() then 
		if InputBinding.isPressed(InputBinding.active) and (self.currentBalle == 4 or self.currentBalle == 5) then self.isResetTM = false; end; 
		if self.fillLevel < 3 and self.isReset > 3 and (self.currentBalle == 4 or self.currentBalle == 5) then self.isReset = 2; end; 
		if self.fillLevel > 2 and self.isReset < 2 and (self.currentBalle == 4 or self.currentBalle == 5) then self.isReset = 3; end; end; end;
function forcaPolivalente:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) return BaseMission.VEHICLE_LOAD_OK; end;
function forcaPolivalente:getSaveAttributesAndNodes(nodeIdent) end;
function forcaPolivalente:updateTick(dt) if self.isClient then for _,particleSystems in pairs(self.smokeParticleSystems) do                  
    if self.currentFillType == Fillable.FILLTYPE_MANURE and self.fillLevel > 2000 and self.setmovingDirection < 300 
	then Utils.setEmittingState(particleSystems.particleSystems, true); else Utils.setEmittingState(particleSystems.particleSystems, false); end; end; end; if self.currentPiloni ~= 3 then self:setcurrentPiloni(3); end;
	if self.isResetTM == false then if self.fillLevel < 3 then self:playAnimation("trattenitoreUnload", 1.5); else self:playAnimation("trattenitoreLoad", 1); end; self.isResetTM = true; end; if self.isReset == 3 then self:playAnimation("trattenitoreLoad", 1); self.isReset = 4; end; if self.isReset == 2 then self:playAnimation("trattenitoreUnload", 1.5); self.isReset = 1; end; end;
function forcaPolivalente: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; end;
function forcaPolivalente:onAttach(attacherVehicle, jointDescIndex) self:playAnimation("tubiIdraulici", 1); end;
function forcaPolivalente:onDetach() self:playAnimation("tubiIdraulici", -1); end;
function forcaPolivalente:onDeactivate() end;