diff --git a/scripts/ai/controllers/TrailerController.lua b/scripts/ai/controllers/TrailerController.lua index c9a1774ba..5c9d069ea 100644 --- a/scripts/ai/controllers/TrailerController.lua +++ b/scripts/ai/controllers/TrailerController.lua @@ -19,7 +19,7 @@ function TrailerController:getDriveData() maxSpeed = 0 self:debugSparse("Waiting for unloading!") end - if self.trailerSpec.tipState == Trailer.TIPSTATE_OPENING then + if self.implement:getDischargeNodeEmptyFactor(self.dischargeData.dischargeNode) < 0.1 then --- Trailer not yet ready to unload. maxSpeed = 0 self:debugSparse("Waiting for trailer animation opening!") @@ -39,22 +39,22 @@ function TrailerController:update(dt) if self.isDischargingToGround then if self:isEmpty() then if self:isDischarging() then - self.implement:setDischargeState(Dischargeable.DISCHARGE_STATE_OFF) + self.implement:setManualDischargeState(Dischargeable.DISCHARGE_STATE_OFF) end if self.implement:getAIHasFinishedDischarge(self.dischargeData.dischargeNode) then self:finishedDischarge() end return end + local fillLevel = self.implement:getFillUnitFillLevelPercentage(self.dischargeData.dischargeNode.fillUnitIndex) + if fillLevel ~= self.dischargeData.lastFillLevel then + self:debugSparse("Resetting the discharge timer") + self.isDischargingTimer:set(true, 250) + end + self.dischargeData.lastFillLevel = fillLevel if self.implement:getCanDischargeToGround(self.dischargeData.dischargeNode) then - --- Update discharge timer - local fillLevel = self.implement:getFillUnitFillLevelPercentage(self.dischargeData.dischargeNode) - if fillLevel ~= self.dischargeData.lastFillLevel then - self.isDischargingTimer:set(true, 10000) - end - self.dischargeData.lastFillLevel = fillLevel if not self:isDischarging() then - self.implement:setDischargeState(Dischargeable.DISCHARGE_STATE_GROUND) + self.implement:setManualDischargeState(Dischargeable.DISCHARGE_STATE_GROUND) end end end @@ -141,7 +141,7 @@ function TrailerController:prepareForUnload() end function TrailerController:onFinished() - self.implement:setDischargeState(Dischargeable.DISCHARGE_STATE_OFF) + self.implement:setManualDischargeState(Dischargeable.DISCHARGE_STATE_OFF) end function TrailerController:isDischarging()