diff --git a/FS25_ADSmartPickup/adOutbound.lua b/FS25_ADSmartPickup/adOutbound.lua index 849fadc..63af915 100644 --- a/FS25_ADSmartPickup/adOutbound.lua +++ b/FS25_ADSmartPickup/adOutbound.lua @@ -232,6 +232,21 @@ function ADOutbound.buildPlanInput(adEnv, run, vehicle) local homeId = product.sources[1] ~= nil and product.sources[1].wayPointId or nil local quote, unreachableName = findSellQuote(adEnv, vehicle, product, sellMarkers, run.sellAtPercent, homeId) product.quote = quote + if quote == nil and unreachableName == nil then + -- intet salgssted tager varen: sig hvilke salgsmarkører der findes, og hvad de tager + local found = {} + for _, entry in ipairs(sellMarkers) do + local accepted = ADSources.describeAccepted ~= nil and ADSources.describeAccepted(entry.station) or "?" + table.insert(found, string.format("%s (%s)", tostring(entry.marker.name), accepted)) + end + local key = "nosell:" .. product.name + local text = string.format("intet salgssted tager %s — salgsmarkører: %s", product.name, #found > 0 and table.concat(found, "; ") or "ingen (sæt en markør ved et salgssted)") + if warned[vehicle] == nil or warned[vehicle][key] ~= text then + warned[vehicle] = warned[vehicle] or {} + warned[vehicle][key] = text + Logging.info(ADOutbound.LOG_PREFIX .. "'%s': %s", tostring(vehicle:getName()), text) + end + end -- gårdens eget behov (fabrikker/stalde) sælges ikke; kilderne selv tæller ikke som forbrugere if ADSources.getFarmDemand ~= nil then local demand = ADSources.getFarmDemand(adEnv, product.fillType, farmId, ADSources.getSourcePlaceables(sources)) diff --git a/FS25_ADSmartPickup/adSources.lua b/FS25_ADSmartPickup/adSources.lua index 9be02a0..2819664 100644 --- a/FS25_ADSmartPickup/adSources.lua +++ b/FS25_ADSmartPickup/adSources.lua @@ -314,14 +314,39 @@ function ADSources.spawnOne(source, objectInfoIndex) return ok == true end +-- acceptedFillTypes rummer kun bulk-triggerens varer; palletriggerens varer ligger i +-- supportedFillTypes (det AutoDrive selv slår op i). Begge tæller. function ADSources.stationAccepts(station, fillType) - if station.acceptedFillTypes ~= nil then - return station.acceptedFillTypes[fillType] == true + if station.acceptedFillTypes ~= nil and station.acceptedFillTypes[fillType] == true then + return true + end + if station.supportedFillTypes ~= nil and station.supportedFillTypes[fillType] == true then + return true end if station.getIsFillTypeSupported ~= nil then - return station:getIsFillTypeSupported(fillType) == true + local ok, value = pcall(station.getIsFillTypeSupported, station, fillType) + return ok and value == true end - return station.supportedFillTypes ~= nil and station.supportedFillTypes[fillType] == true + return false +end + +-- Til loggen: navnene på de varer stationen tager (sorteret), fx "SUGAR, STRAW_BASKET". +function ADSources.describeAccepted(station) + local set = {} + for _, field in ipairs({"acceptedFillTypes", "supportedFillTypes"}) do + for fillType, accepted in pairs(station[field] or {}) do + if accepted == true then set[fillType] = true end + end + end + local names = {} + for fillType in pairs(set) do + table.insert(names, g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeNameByIndex(fillType) or tostring(fillType)) + end + table.sort(names, function(a, b) + -- stabil rækkefølge efter indeks hvor det kendes, ellers navn + return tostring(a) < tostring(b) + end) + return table.concat(names, ", ") end -- Markører hvis aflæsningsstation er et rigtigt salgssted: { {marker, station} }. diff --git a/FS25_ADSmartPickup/modDesc.xml b/FS25_ADSmartPickup/modDesc.xml index 57132cb..2951025 100644 --- a/FS25_ADSmartPickup/modDesc.xml +++ b/FS25_ADSmartPickup/modDesc.xml @@ -1,7 +1,7 @@ masterdraco - 1.12.15.0 + 1.12.16.0 <en>AD Smart Pickup</en> diff --git a/tests/test_adOutbound.lua b/tests/test_adOutbound.lua index f086e98..de8ddb6 100644 --- a/tests/test_adOutbound.lua +++ b/tests/test_adOutbound.lua @@ -494,6 +494,22 @@ check("O22 ved 10 m ingen advarsel", lastLog("Max trigger distance"), nil) adEnv.AutoDrive.getSetting = nil products[1] = {{fillType = SUGAR, name = "SUGAR", available = 5000, level = 5000, capacity = 180000, isPallet = false}} +-- O23: intet salgssted tager varen -> log én gang med de fundne salgsmarkører og hvad de tager +ADSources.describeAccepted = function(station) return "SUGAR, FORAGE" end +local v23 = newVehicle("Dragon4", 100, 0, 1, true) +v23.carriable = {} +runs[v23] = outboundRun(26, {3}, {{fillType = "STRAW_CRATE", policy = "sell"}}) +quotes["selling station"][CRATE] = nil; quotes["Far station"][CRATE] = nil +sources[3].stored[CRATE] = 2 +logLines = {} +ADOutbound.choosePickup(adEnv, v23) +local noSell = lastLog("intet salgssted tager STRAW_CRATE") +check("O23 log om manglende salgssted", noSell ~= nil, true) +check("O23 lister salgsmarkører", noSell ~= nil and noSell:find("selling station (SUGAR, FORAGE)", 1, true) ~= nil, true) +logLines = {} +ADOutbound.choosePickup(adEnv, v23) +check("O23 kun én gang", lastLog("intet salgssted tager STRAW_CRATE"), nil) + -- O10: install wrapper: fejl i hook stopper ikke AD local calls = {} adEnv.LoadAtDestinationTask.update = function(self, dt) calls.update = (calls.update or 0) + 1 end diff --git a/tests/test_adSources.lua b/tests/test_adSources.lua index a41cfab..1a1e024 100644 --- a/tests/test_adSources.lua +++ b/tests/test_adSources.lua @@ -172,6 +172,11 @@ check("S5 ét salgssted", #sells, 1) check("S5 markør", sells[1].marker.id, 5) check("S5 tager SUGAR", ADSources.stationAccepts(sells[1].station, SUGAR), true) check("S5 tager ikke FORAGE", ADSources.stationAccepts(sells[1].station, FORAGE), false) +-- palletriggerens varer ligger i supportedFillTypes (det AutoDrive bruger), ikke i acceptedFillTypes (kun bulk-trigger) +local palletSell = {acceptedFillTypes = {[SUGAR] = true}, supportedFillTypes = {[SUGAR] = true, [BASKET] = true}} +check("S5 pallevare via supportedFillTypes", ADSources.stationAccepts(palletSell, BASKET), true) +check("S5 ukendt vare stadig nej", ADSources.stationAccepts(palletSell, FORAGE), false) +check("S5 acceptedNames", ADSources.describeAccepted(palletSell), "STRAW_BASKET, SUGAR") -- S6: spawnOne kalder spillets udtag med 1 objekt og uden klientforbindelse check("S6 spawn ok", ADSources.spawnOne(source3, 1), true)