Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuel info now is shown when ai driver is stopped because of low fuel #2843

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading