Skip to content

Commit

Permalink
Merge pull request #2843 from tn4799/fuelLowInfoFix
Browse files Browse the repository at this point in the history
Fuel info now is shown when ai driver is stopped because of low fuel
  • Loading branch information
Tensuko authored Oct 10, 2023
2 parents c9a7aac + 066daac commit c14997d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions scripts/ai/controllers/MotorController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,41 @@ function MotorController:init(vehicle, implement)
end

function MotorController:update()
if not self.isValid then
if not self.isValid then
return
end
if not self.settings.fuelSave:getValue() then
if not self.motorSpec.isMotorStarted then
if not self.settings.fuelSave:getValue() then
if not self.motorSpec.isMotorStarted then
self:startMotor()
self.vehicle:raiseAIEvent("onAIFieldWorkerContinue", "onAIImplementContinue")
end
self.timerSet = false
return
end
if self:isFuelSaveDisabled() or self.driveStrategy:getMaxSpeed() > self.speedThreshold then
if not self.motorSpec.isMotorStarted then
if not self.motorSpec.isMotorStarted then
self:startMotor()
self.vehicle:raiseAIEvent("onAIFieldWorkerContinue", "onAIImplementContinue")
end
self.timerSet = false
elseif self.vehicle:getLastSpeed() <= self.speedThreshold then
if not self.timerSet then
if not self.timerSet then
--- Resets the timer
self.timer:set(false, self.delayMs)
self.timerSet = true
end
if self.timer:get() then
if self.timer:get() then
if self.motorSpec.isMotorStarted then
self.vehicle:raiseAIEvent("onAIFieldWorkerBlock", "onAIImplementBlock")
self:stopMotor()
end
end
end
if self:isFuelLow(10) then -- 10%
if self:isFuelLow(self.fuelThresholdSetting:getValue()) then
self:setInfoText(InfoTextManager.FUEL_IS_LOW)
else
self:clearInfoText(InfoTextManager.FUEL_IS_LOW)
end
if self:isFuelLow(self.fuelThresholdSetting:getValue()) then
self.vehicle:stopCurrentAIJob(AIMessageErrorOutOfFuel.new())
else
self:clearInfoText(InfoTextManager.FUEL_IS_LOW)
end
end

Expand All @@ -63,7 +61,7 @@ end

function MotorController:isFuelLow(threshold)
for _, fillUnit in pairs(self.motorSpec.propellantFillUnitIndices) do
if self.implement:getFillUnitFillLevelPercentage(fillUnit)*100 < threshold then
if self.implement:getFillUnitFillLevelPercentage(fillUnit)*100 < threshold then
return true
end
end
Expand Down

0 comments on commit c14997d

Please sign in to comment.