From a6e17d4f36b7bdf1fc588ced5fb509f7ba1034f4 Mon Sep 17 00:00:00 2001 From: masterdraco Date: Wed, 23 Sep 2026 12:00:55 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20AD's=20'AL=20unload'=20s=C3=A6ttes=20til?= =?UTF-8?q?=20center=20ved=20Start=20af=20udk=C3=B8rsel=20med=20autoload-b?= =?UTF-8?q?il=20(stod=20p=C3=A5=20fra=20=E2=86=92=20ingen=20afl=C3=A6sning?= =?UTF-8?q?=20ved=20salgssted);=20pris-%=20=3D=20kurven=20alene=20(v1.12.1?= =?UTF-8?q?0.0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FS25_ADSmartPickup/adPrices.lua | 9 ++++----- FS25_ADSmartPickup/adRunsController.lua | 27 +++++++++++++++++++++++++ FS25_ADSmartPickup/modDesc.xml | 2 +- tests/test_adPrices.lua | 18 +++++++++-------- tests/test_adRunsController.lua | 11 +++++++++- 5 files changed, 52 insertions(+), 15 deletions(-) diff --git a/FS25_ADSmartPickup/adPrices.lua b/FS25_ADSmartPickup/adPrices.lua index 2f7032a..f60016e 100644 --- a/FS25_ADSmartPickup/adPrices.lua +++ b/FS25_ADSmartPickup/adPrices.lua @@ -77,7 +77,9 @@ local function getCurrentPeriod() end -- {price, top, percent} for varen ved stationen; nil hvis stationen ikke kan prissætte den. --- percent = kurve-% × (effektiv ÷ stationens grundpris nu); top = den pris der svarer til 100 %. +-- percent = kurve-% (faktor nu ÷ årets højeste). Stationens `fillTypePrices` bruges IKKE som +-- reference: in-game (23/9) gav effektiv 1602 mod grundpris 505 = 317 %, fordi grundprisen +-- hverken indeholder sværhedsgrad eller prisskala. top = prisen der svarer til 100 % af kurven. function ADPrices.getQuote(station, fillType) if station == nil or station.getEffectiveFillTypePrice == nil then return nil @@ -88,10 +90,7 @@ function ADPrices.getQuote(station, fillType) end local fillTypeDesc = g_fillTypeManager ~= nil and g_fillTypeManager.getFillTypeByIndex ~= nil and g_fillTypeManager:getFillTypeByIndex(fillType) or nil local factors = fillTypeDesc ~= nil and fillTypeDesc.economy ~= nil and fillTypeDesc.economy.factors or nil - local curve = ADPrices.curvePercent(factors, getCurrentPeriod()) - local baseNow = station.fillTypePrices ~= nil and tonumber(station.fillTypePrices[fillType]) or nil - local stationRatio = (baseNow ~= nil and baseNow > 0) and (effective / baseNow) or 1 - local percent = math.floor(curve * stationRatio + 0.5) + local percent = ADPrices.curvePercent(factors, getCurrentPeriod()) local top = percent > 0 and (effective * 100 / percent) or effective return {price = effective, top = top, percent = percent} end diff --git a/FS25_ADSmartPickup/adRunsController.lua b/FS25_ADSmartPickup/adRunsController.lua index 026a080..cc6899e 100644 --- a/FS25_ADSmartPickup/adRunsController.lua +++ b/FS25_ADSmartPickup/adRunsController.lua @@ -568,10 +568,37 @@ local function findNearestLoadMarker(adEnv, vehicle, farmId) return best end +local function getSettingValue(adEnv, vehicle, settingName) + local global = adEnv.AutoDrive.settings[settingName] + if global == nil then + return nil + end + local setting = global + if global.isVehicleSpecific and vehicle.ad.settings ~= nil and vehicle.ad.settings[settingName] ~= nil then + setting = vehicle.ad.settings[settingName] + end + return setting.values ~= nil and setting.values[setting.current] or nil +end + +-- AutoDrives "AL unload" (aflæsning af autoload-vogn ved målet) står som standard på FRA (0): +-- bilen ville holde ved salgsstedet uden at læsse af. "center" (1) løsner stropperne i triggeren, +-- så salgsstedet tager pallerne; left/behind/right lader UAL sætte pallerne af ved siden af. +-- Et valg brugeren selv har lavet, røres ikke. +ADRunsController.AL_UNLOAD_CENTER = 1 +local function ensureAutoloadUnload(adEnv, vehicle) + if getSettingValue(adEnv, vehicle, "ALUnload") == 0 then + setSetting(adEnv, vehicle, "ALUnload", ADRunsController.AL_UNLOAD_CENTER) + Logging.info(ADRunsController.LOG_PREFIX .. "'%s': AutoDrives 'AL unload' var fra — sat til 'center' (stropper løsnes i triggeren)", tostring(vehicle:getName())) + end +end + -- Udkørsel: 1. og 2. markør = første kilde (pladsholder — kilde og mål vælges pr. tur af -- ADOutbound), varevalg = run'ets varer vognen kan bære, rotation "kun pålæsning" (hook'en). local function applyOutboundRunToVehicle(adEnv, run, vehicle) local stateModule = vehicle.ad.stateModule + if hasAutoload(adEnv, vehicle) then + ensureAutoloadUnload(adEnv, vehicle) + end stateModule:setMode(adEnv.AutoDrive.MODE_PICKUPANDDELIVER) local firstId = run.sourceWayPointIds[1] stateModule:setFirstMarkerByWayPointId(firstId) diff --git a/FS25_ADSmartPickup/modDesc.xml b/FS25_ADSmartPickup/modDesc.xml index 16b5a9c..335318f 100644 --- a/FS25_ADSmartPickup/modDesc.xml +++ b/FS25_ADSmartPickup/modDesc.xml @@ -1,7 +1,7 @@ masterdraco - 1.12.9.0 + 1.12.10.0 <en>AD Smart Pickup</en> diff --git a/tests/test_adPrices.lua b/tests/test_adPrices.lua index 4a6d515..38c0445 100644 --- a/tests/test_adPrices.lua +++ b/tests/test_adPrices.lua @@ -42,8 +42,8 @@ local station = { } local quote = ADPrices.getQuote(station, SUGAR) check("P4 pris", quote.price, 470) -check("P4 top (pris ved 100 %)", math.floor(quote.top + 0.5), 627) -check("P4 procent", quote.percent, 75) +check("P4 top (pris ved 100 %)", math.floor(quote.top + 0.5), 588) +check("P4 procent = kurven alene (stationens grundpris bruges ikke: den mangler sværhedsgrad m.m.)", quote.percent, 80) check("P4 er salgssted", ADPrices.isSellingStation(station), true) check("P4 skjult = ikke salgssted", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = true, hideFromPricesMenu = true}), false) check("P4 fabrik-station = ikke salgssted", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = false}), false) @@ -59,12 +59,14 @@ check("P7 curvePercent ved top", ADPrices.curvePercent({1.0, 1.25, 0.9}, 2), 100 check("P7 flad kurve = 100", ADPrices.curvePercent({1.0, 1.01, 1.0}, 3), 100) check("P7 ingen kurve = 100", ADPrices.curvePercent(nil, 1), 100) check("P7 ukendt periode = 100", ADPrices.curvePercent({1.0, 1.25}, nil), 100) --- P8: stor efterspørgsel ganger stationens egen faktor på: 500 grundpris, 700 effektiv, kurve 80 % -> 112 -local demandStation = {fillTypePrices = {[SUGAR] = 500}, getEffectiveFillTypePrice = function() return 700 end} -check("P8 stor efterspørgsel > 100", ADPrices.getQuote(demandStation, SUGAR).percent, 112) --- P9: sværhedsgraden påvirker ikke procenten (begge priser skaleres ens) -local hardStation = {fillTypePrices = {[SUGAR] = 250}, getEffectiveFillTypePrice = function() return 235 end} -check("P9 uafhængig af sværhedsgrad", ADPrices.getQuote(hardStation, SUGAR).percent, 75) +-- P8: in-game (23/9): effektiv 1602 mod fillTypePrices 505 gav 317 % — stationens grundpris indeholder +-- hverken sværhedsgrad eller prisskala, så forholdet er ubrugeligt. Procenten er kurven alene. +local demandStation = {fillTypePrices = {[SUGAR] = 505}, getEffectiveFillTypePrice = function() return 1602 end} +check("P8 procent uafhængig af stationens grundpris", ADPrices.getQuote(demandStation, SUGAR).percent, 80) +check("P8 top = pris ved 100 % af kurven", math.floor(ADPrices.getQuote(demandStation, SUGAR).top + 0.5), 2003) +-- P9: sværhedsgraden påvirker ikke procenten +local hardStation = {getEffectiveFillTypePrice = function() return 235 end} +check("P9 uafhængig af sværhedsgrad", ADPrices.getQuote(hardStation, SUGAR).percent, 80) check("P5 fejlende station -> nil", ADPrices.getQuote({getEffectiveFillTypePrice = function() error("x") end}, SUGAR), nil) -- P6: bedste tilbud = højeste procent, dernæst pris diff --git a/tests/test_adRunsController.lua b/tests/test_adRunsController.lua index 6dd12a2..cbe2c17 100644 --- a/tests/test_adRunsController.lua +++ b/tests/test_adRunsController.lua @@ -37,6 +37,7 @@ FS25_AutoDrive = { settings = { useFolders = {values = {false, true}, current = 1, isVehicleSpecific = false}, rotateTargets = {values = {1, 2, 3, 4}, current = 1, isVehicleSpecific = true}, + ALUnload = {values = {0, 1, 2, 3, 4}, current = 1, isVehicleSpecific = true}, }, getAllVehicles = function() return vehicles end, getAllUnits = function(vehicle) return vehicle.trailers end, @@ -101,7 +102,7 @@ local function makeVehicle(uniqueId, name, carriable, capacity, x, z) startAutoDrive = function(self) self.ad.stateModule.active = true; self.started = (self.started or 0) + 1 end, getClosestWayPoint = function() return nil, 0 end, stopAutoDrive = function(self) self.ad.stateModule.active = false; self.stopped = (self.stopped or 0) + 1 end, - ad = {stateModule = stateModule, settings = {rotateTargets = {values = {1, 2, 3, 4}, current = 1, new = 1, isVehicleSpecific = true}}}, + ad = {stateModule = stateModule, settings = {rotateTargets = {values = {1, 2, 3, 4}, current = 1, new = 1, isVehicleSpecific = true}, ALUnload = {values = {0, 1, 2, 3, 4}, current = 1, new = 1, isVehicleSpecific = true}}}, } nodePositions = nodePositions or {} nodePositions[uniqueId] = {x = x or 0, z = z or 0} @@ -522,6 +523,14 @@ check("Cout3 bulk-vogn: kun TMR", table.concat(bulkTractor.ad.stateModule.select check("Cout3 UAL-vogn: kurve", table.concat(ualTractor.ad.stateModule.selectedFillTypes, ","), tostring(BASKET)) check("Cout3 rotation kun pålæsning", bulkTractor.ad.settings.rotateTargets.current, 2) check("Cout3 startet", bulkTractor.started, 1) +-- AD's "AL unload" er slået FRA som standard (values[1] = 0): autoload-vognen ville aldrig læsse af +-- ved salgsstedet. Ved Start sættes den til "center" hvis den er fra; et brugervalg (left/right/behind) røres ikke. +check("Cout3 ALUnload sat til center for autoload-bil", ualTractor.ad.settings.ALUnload.current, 2) +check("Cout3 ALUnload rører ikke tipvogn", bulkTractor.ad.settings.ALUnload.current, 1) +ualTractor.ad.settings.ALUnload.current = 4 +ualTractor.ad.stateModule.active = false +ADRunsController.startRun(adEnv, out.id) +check("Cout3 ALUnload brugervalg bevares", ualTractor.ad.settings.ALUnload.current, 4) -- Cout4: produkter til fanen (politik slået op, sorteret på titel) og status local list = ADRunsController.getRunProducts(adEnv, outRun)