From 813ee6d0b95e712da98f0eb931c78d8057616c72 Mon Sep 17 00:00:00 2001 From: masterdraco Date: Sat, 26 Sep 2026 15:45:05 +0200 Subject: [PATCH] =?UTF-8?q?fix(markarbejde):=20p=C3=A5fyldning=20ogs=C3=A5?= =?UTF-8?q?=20ved=20k=C3=B8bestationer=20(buyingStation,=20ingen=20lagerbe?= =?UTF-8?q?holdning)=20=E2=80=94=20'Liquid=20Buy=20Station'=20blev=20aldri?= =?UTF-8?q?g=20fundet;=20mark=C3=B8r=20inden=20for=2030=20m=20af=20trigger?= =?UTF-8?q?=20eller=2040=20m=20af=20bygningen=20(v1.29.3.0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FS25_ADSmartPickup/adFieldWork.lua | 73 ++++++++++++++++++++++++++---- FS25_ADSmartPickup/modDesc.xml | 2 +- tests/test_adFieldWorkBuying.lua | 22 +++++++++ 3 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 tests/test_adFieldWorkBuying.lua diff --git a/FS25_ADSmartPickup/adFieldWork.lua b/FS25_ADSmartPickup/adFieldWork.lua index 85c6f21..5179c98 100644 --- a/FS25_ADSmartPickup/adFieldWork.lua +++ b/FS25_ADSmartPickup/adFieldWork.lua @@ -387,26 +387,79 @@ end -- Nærmeste påfyldning af varen: en læssestation gården har adgang til, med varen på lager, en AutoDrive- -- markør ved triggeren og vej fra traktoren. (AutoDrives eget "automatiske påfyldningsmål" er slået fra i -- AutoDrive — AutoDrive.automaticPickupTarget = false — så vi finder stedet selv, som silovalget.) +-- Sælger købestationen varen? (placeable.spec_buyingStation.buyingStation; FS25-felter varierer, så flere +-- opslag: udbudte varer, triggernes varer, AI-varer.) +function ADFieldWork.buyingSupports(station, fillType) + if station == nil or fillType == nil then return false end + local ok, result = pcall(function() + for _, key in ipairs({"providedFillTypes", "supportedFillTypes", "fillTypes"}) do + local set = station[key] + if type(set) == "table" and set[fillType] then return true end + end + for _, trigger in pairs(station.loadTriggers or {}) do + if type(trigger.fillTypes) == "table" and trigger.fillTypes[fillType] then return true end + end + if station.getAISupportedFillTypes ~= nil then + local set = station:getAISupportedFillTypes() + if type(set) == "table" and set[fillType] then return true end + end + return false + end) + return ok and result == true +end + +-- AD-markøren ved stationen: AutoDrives eget opslag (30 m fra triggeren), ellers nærmeste ikke-Wait +-- markør inden for 40 m af bygningen ("Liquid Buy Station" står ved tanken, ikke ved triggeren). +local function markerAtStation(adEnv, vehicle, station, placeable) + local okAd, wayPointId = pcall(function() return adEnv.ADTriggerManager:getMarkerAtStation(station, vehicle, 30) end) + if okAd and wayPointId ~= nil and wayPointId > 0 then return wayPointId end + local node = placeable ~= nil and placeable.rootNode or nil + if node == nil then return nil end + local px, _, pz = getWorldTranslation(node) + local best, bestDistance = nil, 40 * 40 + for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do + local isWait = ADSupplyPlanner ~= nil and ADSupplyPlanner.isWaitMarker ~= nil and ADSupplyPlanner.isWaitMarker(marker) + local wayPoint = not isWait and adEnv.ADGraphManager:getWayPointById(marker.id) or nil + if wayPoint ~= nil then + local d = (wayPoint.x - px) ^ 2 + (wayPoint.z - pz) ^ 2 + if d < bestDistance then best, bestDistance = marker.id, d end + end + end + return best +end + +-- Nærmeste påfyldning af varen med AD-markør og vej: lagre/siloer med varen, og købestationer (købes +-- efter behov — ingen lagerbeholdning, så de fandtes ikke før; in-game 26/9 "Liquid Buy Station"). function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z) local farmId = vehicle:getOwnerFarmId() local best, bestDistance = nil, math.huge - local ok = pcall(function() + local function consider(wayPointId) + local wayPoint = wayPointId ~= nil and wayPointId > 0 and adEnv.ADGraphManager:getWayPointById(wayPointId) or nil + if wayPoint == nil then return end + local distance = (wayPoint.x - x) ^ 2 + (wayPoint.z - z) ^ 2 + if distance < bestDistance and ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId) then + best, bestDistance = wayPointId, distance + end + end + pcall(function() for _, station in pairs(g_currentMission.storageSystem:getLoadingStations()) do local supported = station.getAISupportedFillTypes ~= nil and station:getAISupportedFillTypes() or {} if g_currentMission.accessHandler:canFarmAccess(farmId, station) and supported[fillType] and (station:getFillLevel(fillType, farmId) or 0) > 0 then - local wayPointId = adEnv.ADTriggerManager:getMarkerAtStation(station, vehicle, 10) - local wayPoint = wayPointId ~= nil and wayPointId > 0 and adEnv.ADGraphManager:getWayPointById(wayPointId) or nil - if wayPoint ~= nil then - local distance = (wayPoint.x - x) ^ 2 + (wayPoint.z - z) ^ 2 - if distance < bestDistance and ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId) then - best, bestDistance = wayPointId, distance - end - end + consider(markerAtStation(adEnv, vehicle, station, station.owningPlaceable)) end end end) - return ok and best or nil + pcall(function() + for _, placeable in pairs(g_currentMission.placeableSystem.placeables) do + local spec = placeable.spec_buyingStation + local station = spec ~= nil and spec.buyingStation or nil + if station ~= nil and ADFieldWork.buyingSupports(station, fillType) then + consider(markerAtStation(adEnv, vehicle, station, placeable)) + end + end + end) + return best end -- Påfyldning undervejs (såmaskine/sprøjte/spreder): AutoDrive LOAD med hjælper = Courseplay. Når CP melder diff --git a/FS25_ADSmartPickup/modDesc.xml b/FS25_ADSmartPickup/modDesc.xml index eaa4ca7..8da190b 100644 --- a/FS25_ADSmartPickup/modDesc.xml +++ b/FS25_ADSmartPickup/modDesc.xml @@ -1,7 +1,7 @@ masterdraco - 1.29.2.0 + 1.29.3.0 <en>AD Smart Pickup</en> diff --git a/tests/test_adFieldWorkBuying.lua b/tests/test_adFieldWorkBuying.lua new file mode 100644 index 0000000..a1d148b --- /dev/null +++ b/tests/test_adFieldWorkBuying.lua @@ -0,0 +1,22 @@ +-- Kør: luajit tests/test_adFieldWorkBuying.lua (fra repo-roden) +-- Påfyldning ved købestation (in-game 26/9: "Liquid Buy Station", FarmFillStations buyingStationConfigurable): +-- ingen lagerbeholdning, så varen læses fra udbud/triggere/AI-varer. +local failures = 0 +local function check(name, actual, expected) + if actual == expected then print("OK " .. name) else + failures = failures + 1 + print(string.format("FAIL %s: forventede %s, fik %s", name, tostring(expected), tostring(actual))) + end +end +Logging = {info = function() end, warning = function() end} +dofile("FS25_ADSmartPickup/adFieldWork.lua") +local HERBICIDE, LIME, SEEDS = 20, 21, 22 +local W = ADFieldWork +check("BS1 udbudte varer", W.buyingSupports({providedFillTypes = {[HERBICIDE] = true}}, HERBICIDE), true) +check("BS2 triggerens varer", W.buyingSupports({loadTriggers = {{fillTypes = {[HERBICIDE] = true}}}}, HERBICIDE), true) +check("BS3 AI-varer", W.buyingSupports({getAISupportedFillTypes = function() return {[SEEDS] = true} end}, SEEDS), true) +check("BS4 sælger ikke kalk", W.buyingSupports({providedFillTypes = {[HERBICIDE] = true}}, LIME), false) +check("BS5 fejl i opslag = nej", W.buyingSupports({getAISupportedFillTypes = function() error("x") end}, LIME), false) +check("BS6 ingen station", W.buyingSupports(nil, LIME), false) +print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) +os.exit(failures == 0 and 0 or 1)