From cec1989be0b239039fbd9f084788b4c56aef589a Mon Sep 17 00:00:00 2001 From: David Schwietering Date: Thu, 8 May 2025 19:13:00 +0200 Subject: [PATCH 1/2] Changed soil sampler spec reference --- scripts/CpUtil.lua | 6 ++++++ scripts/ai/controllers/SoilSamplerController.lua | 7 ++++++- scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua | 2 +- scripts/ai/util/WorkWidthUtil.lua | 7 ++++--- scripts/specializations/CpAIFieldWorker.lua | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/CpUtil.lua b/scripts/CpUtil.lua index 85a433d90..3289410f8 100644 --- a/scripts/CpUtil.lua +++ b/scripts/CpUtil.lua @@ -501,4 +501,10 @@ function CpUtil.removeEventListenersBySpecialization(vehicle, specClass) end end end +end + +function CpUtil.getSoilSamplerSpecName() + if g_precisionFarming ~= nil then + return "spec_" .. g_precisionFarming.MOD_NAME .. ".soilSampler" + end end \ No newline at end of file diff --git a/scripts/ai/controllers/SoilSamplerController.lua b/scripts/ai/controllers/SoilSamplerController.lua index 34ba035b0..03ebb9df3 100644 --- a/scripts/ai/controllers/SoilSamplerController.lua +++ b/scripts/ai/controllers/SoilSamplerController.lua @@ -4,7 +4,12 @@ SoilSamplerController = CpObject(ImplementController) function SoilSamplerController:init(vehicle, implement) ImplementController.init(self, vehicle, implement) - self.soilSamplerSpec = implement.spec_soilSampler + local name = CpUtil.getSoilSamplerSpecName() + if name ~= nil then + self.soilSamplerSpec = implement[name] + else + CpUtil.errorImplement(implement, "Soil sampler is nil!") + end self.lastSampleTaken = nil -- The sampling radius is a hexagon, so we shrink this to roughly math a square. self.distBetweenProbes = self.soilSamplerSpec.samplingRadius diff --git a/scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua b/scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua index 315fada47..8e2e2501b 100644 --- a/scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua +++ b/scripts/ai/strategies/AIDriveStrategyFieldWorkCourse.lua @@ -278,7 +278,7 @@ function AIDriveStrategyFieldWorkCourse:initializeImplementControllers(vehicle) self:addImplementController(vehicle, VineCutterController, VineCutter, defaultDisabledStates) self:addImplementController(vehicle, PalletFillerController, nil, defaultDisabledStates, "spec_pdlc_premiumExpansion.palletFiller") - self:addImplementController(vehicle, SoilSamplerController, nil, defaultDisabledStates, "spec_soilSampler") + self:addImplementController(vehicle, SoilSamplerController, nil, defaultDisabledStates, CpUtil.getSoilSamplerSpecName()) self:addImplementController(vehicle, StumpCutterController, StumpCutter, defaultDisabledStates) self:addImplementController(vehicle, TreePlanterController, TreePlanter, {}) diff --git a/scripts/ai/util/WorkWidthUtil.lua b/scripts/ai/util/WorkWidthUtil.lua index d705bacd3..82df21fbe 100644 --- a/scripts/ai/util/WorkWidthUtil.lua +++ b/scripts/ai/util/WorkWidthUtil.lua @@ -84,9 +84,10 @@ function WorkWidthUtil.getAutomaticWorkWidthAndOffset(object, referenceNode, ign end --- Work width for soil samplers. - if not left and object.spec_soilSampler then - if object.spec_soilSampler.samplingRadius then - local width = 2 * object.spec_soilSampler.samplingRadius / math.sqrt(2) + local soilSamplerSpecName = CpUtil.getSoilSamplerSpecName() + if not left and object[soilSamplerSpecName] then + if object[soilSamplerSpecName].samplingRadius then + local width = 2 * object[soilSamplerSpecName].samplingRadius / math.sqrt(2) left, right = width / 2, -width / 2 WorkWidthUtil.debug(object, 'using soil sampler width of %.1f (from sampling radius).', width) else diff --git a/scripts/specializations/CpAIFieldWorker.lua b/scripts/specializations/CpAIFieldWorker.lua index a0c14f502..a40244895 100644 --- a/scripts/specializations/CpAIFieldWorker.lua +++ b/scripts/specializations/CpAIFieldWorker.lua @@ -283,7 +283,7 @@ function CpAIFieldWorker:getCanStartCpFieldWork() -- Harvester with cutter on trailer attached. AIUtil.hasCutterOnTrailerAttached(self) or --- precision farming - AIUtil.hasChildVehicleWithSpecialization(self, nil, "spec_soilSampler") or + AIUtil.hasChildVehicleWithSpecialization(self, nil, CpUtil.getSoilSamplerSpecName()) or --- FS22_aPalletAutoLoader from Achimobil: https://bitbucket.org/Achimobil79/ls22_palletautoloader/src/master/ AIUtil.hasChildVehicleWithSpecialization(self, nil, "spec_aPalletAutoLoader") or --- FS22_UniversalAutoload from Loki79uk: https://github.com/loki79uk/FS22_UniversalAutoload From 22dea901e6c5d341fbb6680876e001dd964efa32 Mon Sep 17 00:00:00 2001 From: David Schwietering Date: Fri, 9 May 2025 14:06:04 +0200 Subject: [PATCH 2/2] Fix for #843 and another fix for the soil sampler ... --- scripts/CpUtil.lua | 4 +--- scripts/gui/CustomFieldHotspot.lua | 34 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/scripts/CpUtil.lua b/scripts/CpUtil.lua index 3289410f8..6e69aee40 100644 --- a/scripts/CpUtil.lua +++ b/scripts/CpUtil.lua @@ -504,7 +504,5 @@ function CpUtil.removeEventListenersBySpecialization(vehicle, specClass) end function CpUtil.getSoilSamplerSpecName() - if g_precisionFarming ~= nil then - return "spec_" .. g_precisionFarming.MOD_NAME .. ".soilSampler" - end + return "spec_FS25_precisionFarming.soilSampler" end \ No newline at end of file diff --git a/scripts/gui/CustomFieldHotspot.lua b/scripts/gui/CustomFieldHotspot.lua index efa8dccd3..62121cc1a 100644 --- a/scripts/gui/CustomFieldHotspot.lua +++ b/scripts/gui/CustomFieldHotspot.lua @@ -5,11 +5,35 @@ CustomFieldHotspot.CATEGORY = 200 CustomFieldHotspot.SLICE_ID = "gui.ingameMap_other" CustomFieldHotspot.NAME = "CP_customFieldManager_hotspotName" CustomFieldHotspot.COLOR = {0.61049, 0.56471, 0.00303, 1} -local CustomFieldHotspot_mt = Class(CustomFieldHotspot, FarmlandHotspot) +local CustomFieldHotspot_mt = Class(CustomFieldHotspot, MapHotspot) function CustomFieldHotspot.new(customMt) - local self = FarmlandHotspot.new(customMt or CustomFieldHotspot_mt) + local self = MapHotspot.new(customMt or CustomFieldHotspot_mt) + self.width, self.height = getNormalizedScreenValues(60, 60) + self.icon = g_overlayManager:createOverlay("mapHotspots.miniMapField", 0, 0, self.width, self.height) + self.icon:setColor(unpack(HUD.COLOR.BACKGROUND_DARK)) + self.clickArea = MapHotspot.getClickCircle(0.667) self.lastName = "" + local _ + _, self.textSize = getNormalizedScreenValues(0, 16) + self.textColor = { 1, 1, 1 } + self.textColorDisabled = { + 0.89627, + 0.92158, + 0.81485, + 0.5 + } + _, self.textOffsetY = getNormalizedScreenValues(0, 2) + self.disabled = false + self.isFirstRendering = true + self.name = "" + + self.setFarmland = FarmlandHotspot.setFarmland + self.getFarmland = FarmlandHotspot.getFarmland + self.setOwnerFarmId = FarmlandHotspot.setOwnerFarmId + self.setDisabled = FarmlandHotspot.setDisabled + self.updateColors = FarmlandHotspot.updateColors + return self end @@ -22,7 +46,7 @@ function CustomFieldHotspot:render(x, y, rotation, small) self.icon:setDimension(width + self.width) end self.lastName = name - CustomFieldHotspot:superClass().render(self, x, y, rotation, small) + FarmlandHotspot.render(self, x, y, rotation, small) end function CustomFieldHotspot:setScale(scale) @@ -33,6 +57,10 @@ function CustomFieldHotspot:getCategory() return CustomFieldHotspot.CATEGORY end +function CustomFieldHotspot:getSortingValue() + return math.huge +end + ---@param field CustomField function CustomFieldHotspot:setField(field) self.field = field