diff --git a/modDesc.xml b/modDesc.xml index a24cfce9b..7027b0378 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -241,6 +241,7 @@ Changelog 8.1.0.3 + diff --git a/scripts/ai/controllers/VineyardToolController.lua b/scripts/ai/controllers/VineyardToolController.lua new file mode 100644 index 000000000..57aa149b7 --- /dev/null +++ b/scripts/ai/controllers/VineyardToolController.lua @@ -0,0 +1,15 @@ +--- Lowers and raises vineyard tools without AI markers. +--- These are not in the AI implement list of giants, so lowering all implements +--- at the start of the work would not turn them on. +---@class VineyardToolController : ImplementController +VineyardToolController = CpObject(ImplementController) + +function VineyardToolController:onLowering() + self:debug('Lowering vineyard tool without AI markers') + self.implement:aiImplementStartLine() +end + +function VineyardToolController:onRaising() + self:debug('Raising vineyard tool without AI markers') + self.implement:aiImplementEndLine() +end diff --git a/scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua b/scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua index dceee575c..3e2444be4 100644 --- a/scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua +++ b/scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua @@ -284,6 +284,9 @@ function AIDriveStrategyFieldWorkCourse:initializeImplementControllers(vehicle) self:addImplementController(vehicle, SoilSamplerController, nil, defaultDisabledStates, CpUtil.getSoilSamplerSpecName()) self:addImplementController(vehicle, StumpCutterController, StumpCutter, defaultDisabledStates) self:addImplementController(vehicle, TreePlanterController, TreePlanter, {}) + for _, tool in ipairs(AIUtil.getVineyardToolsWithoutAIMarkers(vehicle)) do + self:appendImplementController(VineyardToolController(vehicle, tool), {}) + end end diff --git a/scripts/ai/util/AIUtil.lua b/scripts/ai/util/AIUtil.lua index 2a34911e5..c666c2944 100644 --- a/scripts/ai/util/AIUtil.lua +++ b/scripts/ai/util/AIUtil.lua @@ -759,6 +759,37 @@ function AIUtil.hasValidUniversalTrailerAttached(vehicle) return spec.isAutoloadAvailable and not spec.autoloadDisabled end +--- Is this a vineyard tool with work areas? +--- Giants leaves out the AI markers on some of them, for example on the row spreading +--- configuration of the Kuhn Accura 1200, as the built in helper can't work in vineyards. +function AIUtil.isVineyardTool(object) + if object.getAIIsVineyardTool and object:getAIIsVineyardTool() and WorkWidthUtil.hasWorkAreas(object) then + return true + end + return false +end + +--- Checks if a vineyard tool with work areas is attached. +function AIUtil.hasVineyardToolAttached(vehicle) + for _, childVehicle in pairs(vehicle:getChildVehicles()) do + if AIUtil.isVineyardTool(childVehicle) then + return true + end + end + return false +end + +--- Gets all vineyard tools, that are not in the AI implement list of giants, as they have no AI markers. +function AIUtil.getVineyardToolsWithoutAIMarkers(vehicle) + local tools = {} + for _, childVehicle in pairs(vehicle:getChildVehicles()) do + if AIUtil.isVineyardTool(childVehicle) and not childVehicle:getCanImplementBeUsedForAI() then + table.insert(tools, childVehicle) + end + end + return tools +end + --- Checks if cutter on an trailer is attached. function AIUtil.hasCutterOnTrailerAttached(vehicle) local trailer = AIUtil.getImplementWithSpecialization(vehicle, DynamicMountAttacher) diff --git a/scripts/specializations/CpAIFieldWorker.lua b/scripts/specializations/CpAIFieldWorker.lua index 0206324c7..4bbd511d2 100644 --- a/scripts/specializations/CpAIFieldWorker.lua +++ b/scripts/specializations/CpAIFieldWorker.lua @@ -276,6 +276,8 @@ function CpAIFieldWorker:getCanStartCpFieldWork() AIUtil.hasImplementWithSpecialization(self, Cutter) or AIUtil.hasChildVehicleWithSpecialization(self, VineCutter) or AIUtil.hasChildVehicleWithSpecialization(self, VinePrepruner) or + --- Vineyard tools may come without AI markers, the giants fieldworker can't use them anyway. + AIUtil.hasVineyardToolAttached(self) or --- This also allows the use of stump cutters, that work like a mulcher. AIUtil.hasChildVehicleWithSpecialization(self, Plow) or --- A few mowers can't be used by the giants fieldworker