--
-- emptyMe (HWF)
-- Specialization for empty an fillable object
--
-- by Blacky_BPG
-- 
-- Version: 1.4.4.0 I    |    22.09.2017    fix wrong fillUnitIndex value from GIANTS
-- Version: 1.4.4.0 H    |    01.07.2017    fix incompatibility with extendedFunctions
-- Version: 1.4.4.0 G    |    29.06.2017    fix double text entrys #2
-- Version: 1.4.4.0 F    |    18.06.2017    fix missing particle effect, fix double text entrys
-- Version: 1.4.4.0 E    |    17.06.2017    fix incompatibility with extendedFunction mod, now it works
-- Version: 1.4.4.0 D    |    17.06.2017    fix incompatibility with extendedFunction mod
-- Version: 1.4.4.0 C    |    15.06.2017    fix multiplayer event
-- Version: 1.4.4.0 B    |    08.06.2017    add unloadingEffect functionality
-- Version: 1.4.4.0 A    |    08.06.2017    helpWindowFix is now include in this script
-- Version: 1.4.4.0      |    07.06.2017    initial Version for FS17
-- 

emptyMe = {} function emptyMe.prerequisitesPresent(specializations) return SpecializationUtil.hasSpecialization(Fillable, specializations) end function emptyMe:load(xmlFile) self.showTipOption = 0 self.tippingToEmpty = false self.emptyTipSound = false self.emptyTipAnimation = false self.emptyingMyLoad = SpecializationUtil.callSpecializationsFunction("emptyingMyLoad") end function emptyMe:update(dt) if self:getIsActiveForInput() then if self.showTipOption > 0 then if InputBinding.hasEvent(InputBinding.EMPTY_ME) then self.tippingToEmpty = not self.tippingToEmpty emptyMeEvent.sendEvent(self, self.tippingToEmpty) end end end end function emptyMe:updateTick(dt) if self:getIsActiveForInput() then self.showTipOption = 0 for i=1,table.getn(self.fillUnits) do local fillUnit = self.fillUnits[i] if fillUnit.fillLevel > 0 then self.showTipOption = i break end end end if self.isServer then if self.tippingToEmpty then self.showTipOption = 0 for i=1,table.getn(self.fillUnits) do local fillUnit = self.fillUnits[i] if fillUnit.fillLevel > 0 then self.showTipOption = i break end end if self.showTipOption <= 0 then self.tippingToEmpty = false emptyMeEvent.sendEvent(self, false) else self:emptyingMyLoad(dt) end end end if self.tippingToEmpty then if self.numTipReferencePoints > 0 then if not self.emptyTipAnimation then self.emptyTipAnimation = true self.currentTipReferencePointIndex = self.preferedTipReferencePointIndex self:enableTipAnimation(self.preferedTipReferencePointIndex, 1) end if self.emptyTipAnimation then local tipAnimation = self.tipAnimations[self.currentTipReferencePointIndex] if tipAnimation ~= nil then local currentFillType = self:getUnitFillType(Utils.getNoNil(self.showTipOption,self.trailer.fillUnitIndex)) local loadEffect = true if tipAnimation.emitterShape ~= nil and self.referenceParticleSystems[currentFillType] ~= nil then if not tipAnimation.isAdditionalEffect then loadEffect = false end if self.currentDischargeParticleSystem == nil then ParticleUtil.setEmitterShape(self.referenceParticleSystems[currentFillType], tipAnimation.emitterShape) self.currentDischargeParticleSystem = self.referenceParticleSystems[currentFillType] local scale = (self.currentDischargeParticleSystem.emitterShapeSize/self.currentDischargeParticleSystem.defaultEmitterShapeSize)*tipAnimation.emitCountScale ParticleUtil.initEmitterScale(self.currentDischargeParticleSystem, scale) end ParticleUtil.setEmittingState(self.currentDischargeParticleSystem, true) if tipAnimation.fillVolumeHeightIndex ~= nil then local currentScale = 1 if self.fillVolumeHeights[tipAnimation.fillVolumeHeightIndex] ~= nil and self.fillVolumeHeights[tipAnimation.fillVolumeHeightIndex].currentMinHeight ~= nil then currentScale = self.fillVolumeHeights[tipAnimation.fillVolumeHeightIndex].currentMinHeight end ParticleUtil.setEmitCountScale(self.currentDischargeParticleSystem, currentScale) end end if loadEffect and tipAnimation.tipEffect ~= nil then self.currentTipEffects = tipAnimation.tipEffect EffectManager:setFillType(self.currentTipEffects, currentFillType) EffectManager:startEffects(self.currentTipEffects) end end else if self.currentTipEffects ~= nil and self.currentTipEffects[1] ~= nil then if self.currentTipReferencePointIndex ~= nil then local tipAnimation = self.tipAnimations[self.currentTipReferencePointIndex] if tipAnimation ~= nil then if self:getUnitFillLevel(self.trailer.fillUnitIndex) > 0 then if tipAnimation.dischargeEndTime > tipAnimation.dischargeStartTime then local m = self:getCapacity()/((tipAnimation.dischargeEndTime-tipAnimation.dischargeStartTime)/tipAnimation.unloadingSpeedScale) if self:getUnitFillLevel(self.trailer.fillUnitIndex) <= m * self.currentTipEffects[1].planeFadeTime then EffectManager:stopEffects(self.currentTipEffects) self.currentTipEffects = nil end end end end end end end end if self.isClient then if self.sampleFillSound ~= nil then if self:getIsActiveForSound() then if not self.emptyTipSound then SoundUtil.playSample(self.sampleFillSound, 0, 0, nil) end self.emptyTipSound = true else if self.emptyTipSound then SoundUtil.stopSample(self.sampleFillSound) self.emptyTipSound = false end end end end else if self.numTipReferencePoints > 0 then if self.emptyTipAnimation then self.emptyTipAnimation = false self:enableTipAnimation(self.currentTipReferencePointIndex, -1) end end if self.isClient then if self.sampleFillSound ~= nil and self.emptyTipSound then SoundUtil.stopSample(self.sampleFillSound) self.emptyTipSound = false end end end end function emptyMe:emptyingMyLoad(dt) if self.isServer then if self.tippingToEmpty and self.showTipOption > 0 then local fillLevel = self:getUnitFillLevel(self.showTipOption) fillLevel = fillLevel - (Utils.getNoNil(self.fillLitersPerSecond,self:getUnitCapacity(self.showTipOption)/20)*dt*0.001) self:setUnitFillLevel(self.showTipOption, fillLevel, self:getUnitFillType(self.showTipOption), true) end end end function emptyMe:mouseEvent(posX, posY, isDown, isUp, button) end function emptyMe:keyEvent(unicode, sym, modifier, isDown) end function emptyMe:readStream(streamId, connection) end  function emptyMe:readUpdateStream(streamId, timestamp, connection) end  function emptyMe:writeStream(streamId, connection) end  function emptyMe:writeUpdateStream(streamId, connection, dirtyMask) end  function emptyMe:draw() if self:getIsActiveForInput() then if self.showTipOption > 0 then if self.tippingToEmpty then g_currentMission:addHelpButtonText(g_i18n:getText("input_EMPTY_ME").." "..g_i18n:getText("ui_off"), InputBinding.EMPTY_ME, nil, GS_PRIO_HIGH) else g_currentMission:addHelpButtonText(g_i18n:getText("input_EMPTY_ME").." "..g_i18n:getText("ui_on"), InputBinding.EMPTY_ME, nil, GS_PRIO_HIGH) end end end end function emptyMe:delete() end
-----------------------------O V E R R I D E F U N C T I O N S-------------------------------------
local oldTrailerGetCanTipToGround = Trailer.getCanTipToGround Trailer.getCanTipToGround = function(self) if self.showTipOption ~= nil and self.tippingToEmpty ~= nil and self.tippingToEmpty then return true end return oldTrailerGetCanTipToGround(self) end
local oldSprayergetDrawFirstFillText = Sprayer.getDrawFirstFillText Sprayer.getDrawFirstFillText = function(self) return false end
local oldSowingMachinegetDrawFirstFillText = SowingMachine.getDrawFirstFillText SowingMachine.getDrawFirstFillText = function(self) return false end
local oldFillablegetDrawFirstFillText = Fillable.getDrawFirstFillText Fillable.getDrawFirstFillText = function(self) return false end
local oldFillableDraw = Fillable.draw Fillable.draw = function(self) if self.isClient then local showFFT = false if self.waterTrailerFillUnitIndex ~= nil and self:getUnitFillLevel(self.waterTrailerFillUnitIndex) <= 0 and self:getUnitCapacity(self.waterTrailerFillUnitIndex) ~= 0 then g_currentMission:addExtraPrintText(g_i18n:getText("info_firstFillTheTool")) showFFT = true elseif self.fuelTrailer ~= nil and self:getUnitFillLevel(self.fuelTrailer.fillUnitIndex) <= 0 and self:getUnitCapacity(self.fuelTrailer.fillUnitIndex) ~= 0 then g_currentMission:addExtraPrintText(g_i18n:getText("info_firstFillTheTool")) showFFT = true elseif self.sprayer ~= nil and not self.isAlwaysTurnedOn and not self:getIsTurnedOnAllowed(true) and self:getUnitFillLevel(self.sprayer.fillUnitIndex) <= 0 and self:getUnitCapacity(self.sprayer.fillUnitIndex) > 0 then g_currentMission:addExtraPrintText(g_i18n:getText("info_firstFillTheTool")) showFFT = true elseif self.sowingMachine ~= nil and self:getUnitFillLevel(self.sowingMachine.fillUnitIndex) <= 0 and self:getUnitCapacity(self.sowingMachine.fillUnitIndex) ~= 0 then g_currentMission:addExtraPrintText(g_i18n:getText("info_firstFillTheTool")) showFFT = true end if not showFFT then oldFillableDraw(self) end end end
local oldWaterTrailerDraw = WaterTrailer.draw WaterTrailer.draw = function(self) end
local oldFuelTrailerDraw = FuelTrailer.draw FuelTrailer.draw = function(self) end
-----------------------------------------E V E N T-------------------------------------------------
emptyMeEvent = {} emptyMeEvent_mt = Class(emptyMeEvent, Event) InitEventClass(emptyMeEvent, "emptyMeEvent") function emptyMeEvent:emptyNew() local self = Event:new(emptyMeEvent_mt) self.className="emptyMeEvent" return self end function emptyMeEvent:new(vehicle, state) local self = emptyMeEvent:emptyNew() self.vehicle = vehicle self.state = state return self end function emptyMeEvent:readStream(streamId, connection) self.vehicle = readNetworkNodeObject(streamId) self.state = streamReadBool(streamId) self:run(connection) end function emptyMeEvent:writeStream(streamId, connection) writeNetworkNodeObject(streamId, self.vehicle) streamWriteBool(streamId, self.state) end function emptyMeEvent:run(connection) self.vehicle.tippingToEmpty = self.state if not connection:getIsServer() then g_server:broadcastEvent(emptyMeEvent:new(self.vehicle, self.state), nil, connection, self.vehicle) end end function emptyMeEvent.sendEvent(vehicle, state, noEventSend) if noEventSend == nil or noEventSend == false then if g_server ~= nil then g_server:broadcastEvent(emptyMeEvent:new(vehicle, state), nil, nil, vehicle) else g_client:getServerConnection():sendEvent(emptyMeEvent:new(vehicle, state)) end end end
