diff --git a/scripts/ai/controllers/SowingMachineController.lua b/scripts/ai/controllers/SowingMachineController.lua index 1286ac3d..21153fd7 100644 --- a/scripts/ai/controllers/SowingMachineController.lua +++ b/scripts/ai/controllers/SowingMachineController.lua @@ -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 @@ -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 \ No newline at end of file +end diff --git a/scripts/specializations/CpVehicleSettings.lua b/scripts/specializations/CpVehicleSettings.lua index d9f89d75..d4eed5d4 100644 --- a/scripts/specializations/CpVehicleSettings.lua +++ b/scripts/specializations/CpVehicleSettings.lua @@ -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