From 27095ec6ff2e40090b3d1adb1ee9bf4eefaaa8df Mon Sep 17 00:00:00 2001 From: masterdraco Date: Wed, 23 Sep 2026 11:28:14 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20bulk-vare=20der=20ogs=C3=A5=20st=C3=A5r?= =?UTF-8?q?=20p=C3=A5=20paller=20(sukkerfabrik)=20tages=20som=20paller=20a?= =?UTF-8?q?f=20en=20UAL-vogn,=20som=20bulk=20af=20en=20tipvogn=20(v1.12.3.?= =?UTF-8?q?0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FS25_ADSmartPickup/adOutbound.lua | 13 ++++++++++--- FS25_ADSmartPickup/adRunsController.lua | 5 ++++- FS25_ADSmartPickup/adSources.lua | 11 ++++++++--- FS25_ADSmartPickup/modDesc.xml | 2 +- tests/test_adOutbound.lua | 16 ++++++++++++++++ tests/test_adSources.lua | 7 +++++++ 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/FS25_ADSmartPickup/adOutbound.lua b/FS25_ADSmartPickup/adOutbound.lua index f444e97..3636f7b 100644 --- a/FS25_ADSmartPickup/adOutbound.lua +++ b/FS25_ADSmartPickup/adOutbound.lua @@ -195,17 +195,24 @@ function ADOutbound.buildPlanInput(adEnv, run, vehicle) for _, source in ipairs(sources) do for _, item in ipairs(ADSources.getProducts(adEnv, source, farmId)) do local policy = ADRuns.getProductPolicy(run, item.name) - local canCarry = (item.isPallet and hasAutoload) or (not item.isPallet and carriable[item.fillType] == true) + -- bulk hvis vognen kan bære varen; ellers paller hvis varen står på paller og vognen har UAL + -- (en pallebil ved sukkerfabrikken tager sukkerpallerne, en tipvogn tager bulk) + local usePallets = item.isPallet or (carriable[item.fillType] ~= true and hasAutoload and item.canPallet == true) + local canCarry = usePallets and hasAutoload or (not usePallets and carriable[item.fillType] == true) + local available = item.available + if usePallets and not item.isPallet then + available = item.palletLiters or 0 + end local emptyKey = tostring(source.wayPointId) .. ":" .. tostring(item.fillType) local isMarkedEmpty = emptyUntil[emptyKey] ~= nil and emptyUntil[emptyKey] > time if policy ~= "off" and canCarry and not isMarkedEmpty then local product = byName[item.name] if product == nil then - product = {fillType = item.fillType, name = item.name, policy = policy, isPallet = item.isPallet, sources = {}} + product = {fillType = item.fillType, name = item.name, policy = policy, isPallet = usePallets, sources = {}} byName[item.name] = product table.insert(products, product) end - table.insert(product.sources, {wayPointId = source.wayPointId, available = item.available, level = item.level, capacity = item.capacity}) + table.insert(product.sources, {wayPointId = source.wayPointId, available = available, level = item.level, capacity = item.capacity}) end end end diff --git a/FS25_ADSmartPickup/adRunsController.lua b/FS25_ADSmartPickup/adRunsController.lua index d0c330a..4f91d77 100644 --- a/FS25_ADSmartPickup/adRunsController.lua +++ b/FS25_ADSmartPickup/adRunsController.lua @@ -327,7 +327,7 @@ function ADRunsController.getRunProducts(adEnv, run) for _, item in ipairs(ADSources.getProducts(adEnv, source, farmId)) do local product = byName[item.name] if product == nil then - product = {fillType = item.fillType, name = item.name, title = item.title or item.name, policy = ADRuns.getProductPolicy(run, item.name), isPallet = item.isPallet, available = 0, level = 0, capacity = 0} + product = {fillType = item.fillType, name = item.name, title = item.title or item.name, policy = ADRuns.getProductPolicy(run, item.name), isPallet = item.isPallet, canPallet = item.canPallet, available = 0, level = 0, capacity = 0} byName[item.name] = product table.insert(result, product) end @@ -356,6 +356,9 @@ local function getOutboundFillTypes(adEnv, run, vehicle) if canLoadPallets then table.insert(result, product.fillType) end elseif carriable[product.fillType] then table.insert(result, product.fillType) + elseif product.canPallet and canLoadPallets then + -- bulk-vare der også står på paller (sukkerfabrik): pallebilen tager pallerne + table.insert(result, product.fillType) end end end diff --git a/FS25_ADSmartPickup/adSources.lua b/FS25_ADSmartPickup/adSources.lua index 1750b6e..a31b7f7 100644 --- a/FS25_ADSmartPickup/adSources.lua +++ b/FS25_ADSmartPickup/adSources.lua @@ -184,10 +184,12 @@ local function getPalletsNearSpawner(placeable, fillType, farmId) return total end +-- canPallet: varen er en palletype (kan stå på paller); palletLiters: liter på paller ved +-- kilden når varen ELLERS læsses som bulk (fabrik med både læssestation og pallespawner). local function newProduct(fillType, available, level, capacity, isPallet) local name = g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeNameByIndex(fillType) or tostring(fillType) local title = g_fillTypeManager ~= nil and g_fillTypeManager.getFillTypeTitleByIndex ~= nil and g_fillTypeManager:getFillTypeTitleByIndex(fillType) or nil - return {fillType = fillType, name = name, title = title or name, available = available, level = level, capacity = capacity, isPallet = isPallet} + return {fillType = fillType, name = name, title = title or name, available = available, level = level, capacity = capacity, isPallet = isPallet, canPallet = isPallet or ADSources.isPalletFillType(fillType), palletLiters = 0} end local function getFactoryProducts(source, farmId) @@ -202,8 +204,11 @@ local function getFactoryProducts(source, farmId) local level = storage ~= nil and storage.getFillLevel ~= nil and (storage:getFillLevel(fillType) or 0) or 0 local capacity = storage ~= nil and storage.getCapacity ~= nil and (storage:getCapacity(fillType) or 0) or 0 local isPallet = ADSources.isPalletAt(source, fillType) - local available = level + (isPallet and getPalletsNearSpawner(source.placeable, fillType, farmId) or 0) - table.insert(products, newProduct(fillType, available, level, capacity, isPallet)) + local palletLiters = ADSources.isPalletFillType(fillType) and getPalletsNearSpawner(source.placeable, fillType, farmId) or 0 + local available = level + (isPallet and palletLiters or 0) + local product = newProduct(fillType, available, level, capacity, isPallet) + product.palletLiters = palletLiters + table.insert(products, product) end end end diff --git a/FS25_ADSmartPickup/modDesc.xml b/FS25_ADSmartPickup/modDesc.xml index 750d19f..253f835 100644 --- a/FS25_ADSmartPickup/modDesc.xml +++ b/FS25_ADSmartPickup/modDesc.xml @@ -1,7 +1,7 @@ masterdraco - 1.12.2.0 + 1.12.3.0 <en>AD Smart Pickup</en> diff --git a/tests/test_adOutbound.lua b/tests/test_adOutbound.lua index 412f103..90ecbc3 100644 --- a/tests/test_adOutbound.lua +++ b/tests/test_adOutbound.lua @@ -413,6 +413,22 @@ local input18 = ADOutbound.buildPlanInput(adEnv, runs[v18], v18) check("O18 palle-lager som store-mål", input18.products[1].store ~= nil and input18.products[1].store.wayPointId, 40) check("O18 reserve spørges ikke for lager-politik", demandCalls[#demandCalls] ~= BASKET, true) +-- O19: pallebil (kun UAL) ved en fabrik der både har bulk-læssestation og sukkerpaller -> paller +local v19 = newVehicle("Dragon", 0, 0, 6000, true) +v19.carriable = {} +runs[v19] = outboundRun(19, {1}, {{fillType = "SUGAR", policy = "sell"}}) +products[1] = {{fillType = SUGAR, name = "SUGAR", available = 150000, level = 150000, capacity = 180000, isPallet = false, canPallet = true, palletLiters = 3000}} +quotes["selling station"][SUGAR].percent = 92 +local input19 = ADOutbound.buildPlanInput(adEnv, runs[v19], v19) +check("O19 varen tages som paller", input19.products[1] ~= nil and input19.products[1].isPallet, true) +check("O19 mængde = paller ved spawner", input19.products[1].sources[1].available, 3000) +local v19b = newVehicle("Tipvogn", 0, 0, 20000) +runs[v19b] = outboundRun(20, {1}, {{fillType = "SUGAR", policy = "sell"}}) +local input19b = ADOutbound.buildPlanInput(adEnv, runs[v19b], v19b) +check("O19 tipvogn tager bulk", input19b.products[1].isPallet, false) +check("O19 bulk-mængde", input19b.products[1].sources[1].available, 150000) +products[1] = {{fillType = SUGAR, name = "SUGAR", available = 5000, level = 5000, capacity = 180000, isPallet = false}} + -- 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 9de4137..e307f0d 100644 --- a/tests/test_adSources.lua +++ b/tests/test_adSources.lua @@ -119,6 +119,9 @@ check("S1 SUGAR available", products1[1].available, 150000) check("S1 SUGAR level", products1[1].level, 150000) check("S1 SUGAR capacity", products1[1].capacity, 180000) check("S1 SUGAR bulk", products1[1].isPallet, false) +check("S1 SUGAR kan også stå på paller", products1[1].canPallet, true) +check("S1 SUGAR paller ved spawner (ingen endnu)", products1[1].palletLiters, 0) +check("S1 TMR-lignende bulk kan ikke paller", products1[2].canPallet, true) check("S1 BASKET er palle", products1[2].isPallet, true) check("S1 BASKET tomt", products1[2].available, 0) @@ -155,6 +158,10 @@ addPallet(BASKET, 1000, 112, 102, 2) -- anden farm: tæller ikke local products4 = ADSources.getProducts(adEnv, source1, 1) check("S4 paller ved spawner", products4[2].available, 2000) check("S4 bulk uændret", products4[1].available, 150000) +addPallet(SUGAR, 2000, 111, 101) +local products4b = ADSources.getProducts(adEnv, source1, 1) +check("S4 sukkerpaller tælles separat", products4b[1].palletLiters, 2000) +check("S4 bulk-mængde uden paller", products4b[1].available, 150000) -- S5: salgssteder = kun markører hvis aflæsningsstation er et rigtigt salgssted local sells = ADSources.getSellMarkers(adEnv, 1)