From 0191504d62d30ad79ad7d47731fedffb7ee3036d Mon Sep 17 00:00:00 2001 From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com> Date: Sun, 10 Dec 2023 13:43:19 +0100 Subject: [PATCH] Fieldpolygon might be nil for fieldwork, so regenerate it from the course. --- scripts/ai/AIDriveStrategyFieldWorkCourse.lua | 4 ++++ scripts/ai/jobs/CpAIJobFieldWork.lua | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/ai/AIDriveStrategyFieldWorkCourse.lua b/scripts/ai/AIDriveStrategyFieldWorkCourse.lua index b42815945..1f36d23e7 100644 --- a/scripts/ai/AIDriveStrategyFieldWorkCourse.lua +++ b/scripts/ai/AIDriveStrategyFieldWorkCourse.lua @@ -656,6 +656,10 @@ end function AIDriveStrategyFieldWorkCourse:setFieldPolygon(polygon) self.fieldPolygon = polygon + if self.fieldPolygon == nil then + self:debug("No field polygon received, so regenerate it by the course.") + self.fieldPolygon = self.fieldWorkCourse:getFieldPolygon() + end end ----------------------------------------------------------------------------------------------------------------------- diff --git a/scripts/ai/jobs/CpAIJobFieldWork.lua b/scripts/ai/jobs/CpAIJobFieldWork.lua index bfcf1e8c8..54f266e47 100644 --- a/scripts/ai/jobs/CpAIJobFieldWork.lua +++ b/scripts/ai/jobs/CpAIJobFieldWork.lua @@ -82,6 +82,7 @@ function CpAIJobFieldWork:validateFieldSetup(isValid, errorMessage) self.hasValidPosition = false self.foundVines = nil local fieldPolygon, isCustomField = CpFieldUtil.getFieldPolygonAtWorldPosition(tx, tz) + self:setFieldPolygon(fieldPolygon) if fieldPolygon then self.hasValidPosition = true self.foundVines = g_vineScanner:findVineNodesInField(fieldPolygon, tx, tz, self.customField ~= nil) @@ -89,7 +90,6 @@ function CpAIJobFieldWork:validateFieldSetup(isValid, errorMessage) CpUtil.debugVehicle(CpDebug.DBG_FIELDWORK, vehicle, "Found vine nodes, generating a vine field border.") fieldPolygon = g_vineScanner:getCourseGeneratorVertices(0, tx, tz) end - self:setFieldPolygon(fieldPolygon) self.selectedFieldPlot:setWaypoints(fieldPolygon) self.selectedFieldPlot:setVisible(true) self.selectedFieldPlot:setBrightColor(true)