fix(marker): arbejdsbredde læser variabel bredde (Unrealistic Pack) før AI-markører, som Courseplay (v1.21.1.0)

In-game 25/9: BiG M 450 læst som 10 m og læssevogn som 2,4 m, selv om begge står på 40,8 m.
This commit is contained in:
2026-09-25 22:45:01 +02:00
parent 61a32720ea
commit bade84129b
5 changed files with 49 additions and 4 deletions
+16 -1
View File
@@ -32,10 +32,25 @@ function ADCpBridge.getSpecs(vehicle)
return specs return specs
end end
-- Variabel bredde (Unrealistic Pack m.fl.) først, som Courseplays WorkWidthUtil: AI-markørerne står på
-- grundbredden (læssevogn 2,4 m selv om den er sat til 40,8 m).
local function variableWidth(object)
if object.getVariableWorkWidth == nil then return nil end
local okLeft, left, _, leftValid = pcall(object.getVariableWorkWidth, object, true)
local okRight, right, _, rightValid = pcall(object.getVariableWorkWidth, object)
if okLeft and okRight and leftValid and rightValid and type(left) == "number" and type(right) == "number" then
return math.abs(left) + math.abs(right)
end
return nil
end
function ADCpBridge.getWorkWidth(vehicle) function ADCpBridge.getWorkWidth(vehicle)
local best = 0 local best = 0
for _, object in ipairs(collect(vehicle)) do for _, object in ipairs(collect(vehicle)) do
if object.getAIMarkers ~= nil then local variable = variableWidth(object)
if variable ~= nil then
best = math.max(best, variable)
elseif object.getAIMarkers ~= nil then
pcall(function() if object.updateAIMarkerWidth ~= nil then object:updateAIMarkerWidth() end end) pcall(function() if object.updateAIMarkerWidth ~= nil then object:updateAIMarkerWidth() end end)
local ok, _, _, _, _, width = pcall(object.getAIMarkers, object) local ok, _, _, _, _, width = pcall(object.getAIMarkers, object)
if ok and type(width) == "number" and width > best then best = width end if ok and type(width) == "number" and width > best then best = width end
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107"> <modDesc descVersion="107">
<author>masterdraco</author> <author>masterdraco</author>
<version>1.21.0.0</version> <version>1.21.1.0</version>
<title> <title>
<en>AD Smart Pickup</en> <en>AD Smart Pickup</en>
</title> </title>
+1 -1
View File
@@ -1,6 +1,6 @@
# AD Smart Pickup — brugermanual # AD Smart Pickup — brugermanual
Version 1.21.0 · Farming Simulator 25 · tillæg til AutoDrive Version 1.21.1 · Farming Simulator 25 · tillæg til AutoDrive
*English version: [USER_MANUAL.md](USER_MANUAL.md)* *English version: [USER_MANUAL.md](USER_MANUAL.md)*
+1 -1
View File
@@ -1,6 +1,6 @@
# AD Smart Pickup — user manual # AD Smart Pickup — user manual
Version 1.21.0 · Farming Simulator 25 · add-on for AutoDrive Version 1.21.1 · Farming Simulator 25 · add-on for AutoDrive
*Dansk version: [BRUGERMANUAL.md](BRUGERMANUAL.md)* *Dansk version: [BRUGERMANUAL.md](BRUGERMANUAL.md)*
+30
View File
@@ -0,0 +1,30 @@
-- Kør: luajit tests/test_adCpBridge.lua (fra repo-roden)
-- Kun getWorkWidth: variabel bredde (Unrealistic Pack) vinder over AI-markørernes grundbredde.
dofile("FS25_ADSmartPickup/adCpBridge.lua")
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
local function withMarkers(width)
return {getAIMarkers = function() return 1, 2, 3, 4, width end}
end
-- W1: læssevogn med variabel bredde 20,4 + 20,4 = 40,8 m, AI-markører siger 2,4 m
local wagon = withMarkers(2.4)
wagon.getVariableWorkWidth = function(_, isLeft) return isLeft and 20.4 or -20.4, nil, true end
local tractor = {getAttachedImplements = function() return {{object = wagon}} end}
check("W1 variabel bredde", ADCpBridge.getWorkWidth(tractor), 40.8)
-- W2: ugyldig variabel bredde -> AI-markører
local plain = withMarkers(9.5)
plain.getVariableWorkWidth = function() return 0, nil, false end
check("W2 AI-markører", ADCpBridge.getWorkWidth(plain), 9.5)
-- W3: selvkørende slåmaskine uden redskaber, kun variabel bredde
local mower = {getVariableWorkWidth = function(_, isLeft) return isLeft and 20.4 or -20.4, nil, true end}
check("W3 selvkørende", ADCpBridge.getWorkWidth(mower), 40.8)
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1)