Skip to content
Open
Show file tree
Hide file tree
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
45 changes: 40 additions & 5 deletions scripts/ai/controllers/SowingMachineController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ end

function SowingMachineController:update()
if not self.settings.optionalSowingMachineEnabled:getIsDisabled() then
if self.settings.optionalSowingMachineEnabled:getValue() then
if self.settings.optionalSowingMachineEnabled:getValue() then
--- Makes sure the sowing machine get's turned on
if not self.implement:getIsTurnedOn() then
self.implement:setIsTurnedOn(true)
end
else
else
--- Makes sure the sowing machine is turned off if not needed.
if self.implement:getIsTurnedOn() then
self.implement:setIsTurnedOn(false)
end
end
end
if self.sowingMachineSpec.showWrongFruitForMissionWarning then
if self.sowingMachineSpec.showWrongFruitForMissionWarning then
self:debug("Wrong fruit type for mission selected!")
self.vehicle:stopCurrentAIJob(AIMessageErrorWrongMissionFruitType.new())
end
Expand All @@ -41,15 +41,50 @@ function SowingMachineController:onFinished()
self.implement:setIsTurnedOn(false)
end

--- While Courseplay is driving and sowing was disabled by the user, the machine stays turned off.
--- Without this override, TurnOnVehicle:getCanAIImplementContinueWork() fails for machines that
--- require turning on but are turned off, so the driver would lower the implement and then just
--- stand still, waiting forever (#989).
local function getAIRequiresTurnOn(implement, superFunc, ...)
--- Only for cultivators with a seeder unit configuration, like the Horsch Finer 6 SL.
--- The structural check must not go through the setting's getIsDisabled() here, as that
--- calls isOptionalSowingMachineSettingVisible(), which in turn calls getAIRequiresTurnOn(),
--- resulting in an infinite recursion.
if implement.spec_sowingMachine ~= nil and
SpecializationUtil.hasSpecialization(Cultivator, implement.specializations) then
local rootVehicle = implement.rootVehicle
if rootVehicle ~= nil and rootVehicle.getIsCpActive and rootVehicle:getIsCpActive() then
local setting = rootVehicle:getCpSettings().optionalSowingMachineEnabled
if not setting:getValue() then
return false
end
end
end
return superFunc(implement, ...)
end
TurnOnVehicle.getAIRequiresTurnOn = Utils.overwrittenFunction(
TurnOnVehicle.getAIRequiresTurnOn, getAIRequiresTurnOn)

-------------------------
--- Refill handling
-------------------------

function SowingMachineController:needsRefilling()
if not self.settings.optionalSowingMachineEnabled:getIsDisabled() and
not self.settings.optionalSowingMachineEnabled:getValue() then
--- Sowing was disabled by the user, so no seeds are needed (#989).
return false
end
if self.implement:getFillUnitCapacity(self.sowingMachineSpec.fillUnitIndex) == 0 then
--- Sowing machines without a real seed tank (capacity 0), like the seeder unit
--- of the Horsch Finer 6 SL, don't consume seeds (see getSowingMachineCanConsume)
--- and therefore never need refilling (#989).
return false
end
if not g_currentMission.missionInfo.helperBuySeeds then
if self.implement:getFillUnitFillLevel(self.sowingMachineSpec.fillUnitIndex) <= 0 then
if self.implement:getFillUnitFillLevel(self.sowingMachineSpec.fillUnitIndex) <= 0 then
return ImplementController.needsRefilling(self)
end
end
return false
end
end
15 changes: 12 additions & 3 deletions scripts/specializations/CpVehicleSettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,21 @@ end

function CpVehicleSettings:isOptionalSowingMachineSettingVisible()
local vehicles, found = AIUtil.getAllChildVehiclesWithSpecialization(self, SowingMachine)
return found and not vehicles[1]:getAIRequiresTurnOn()
if not found then
return false
end
if not vehicles[1]:getAIRequiresTurnOn() then
--- Passive sowing machines, for example a roller with a seeder configuration.
return true
end
--- Cultivators with a seeder unit configuration, like the Horsch Finer 6 SL,
--- are primarily cultivators, so sowing is optional for them as well, even
--- though their seeder unit needs to be turned on (#989).
return SpecializationUtil.hasSpecialization(Cultivator, vehicles[1].specializations)
end

function CpVehicleSettings:isOptionalSowingMachineSettingDisabled()
local vehicles, found = AIUtil.getAllChildVehiclesWithSpecialization(self, SowingMachine)
return not found or vehicles[1]:getAIRequiresTurnOn()
return not CpVehicleSettings.isOptionalSowingMachineSettingVisible(self)
end


Expand Down