fix: salgsmarkør uden P/Connect/Wait og fremmede bygningers markører; breddevagt måler aktive sektioner (v1.62.59)

This commit is contained in:
2026-10-07 19:15:43 +02:00
parent dd434a2fc1
commit e8e742faaa
5 changed files with 130 additions and 25 deletions
+43 -2
View File
@@ -508,13 +508,54 @@ function ADCpBridge.needsWidthReset(current, target)
return type(current) == "number" and current > (target or ADCpBridge.VARIABLE_TARGET_WIDTH) + ADCpBridge.WIDTH_GUARD_TOLERANCE
end
-- sections = {{isCenter, isLeft, d (afstand fra midten), isActive}} -> de aktive sektioners bredde (yderkant venstre +
-- højre); nil når sektionerne ikke oplyser isActive (så må spillets måling bruges).
function ADCpBridge.activeSectionWidth(sections)
local left, right, known = 0, 0, false
for _, section in ipairs(sections or {}) do
if type(section.isActive) == "boolean" then known = true end
if section.isActive and not section.isCenter then
if section.isLeft then left = math.max(left, section.d or 0) else right = math.max(right, section.d or 0) end
end
end
return known and left + right or nil
end
-- Skal vagten nulstille? -> reset, ny "sidst nulstillede måling". En måling der står præcis stille efter en
-- nulstilling er ubrugelig (Unrealistic-redskaber svarer altid 120 m; in-game 7/10 nulstillet hvert 10. s).
function ADCpBridge.guardDecision(current, target, lastReset)
if not ADCpBridge.needsWidthReset(current, target) then return false, nil end
if lastReset ~= nil and current == lastReset then return false, lastReset end
return true, current
end
local function sectionDistance(object, section)
local ref = section.maxWidthNode or section.node
if ref == nil or object.rootNode == nil then return 0 end
local okD, x = pcall(function() local lx = localToLocal(ref, object.rootNode, 0, 0, 0) return lx end)
return okD and math.abs(x or 0) or 0
end
-- Aktiv bredde ud fra sektionerne (som setVariableWidth regner), ellers spillets måling.
local function guardedWidth(object, spec)
local list = {}
for _, section in ipairs(spec.sections) do
table.insert(list, {isCenter = section.isCenter, isLeft = section.isLeft, isActive = section.isActive, d = sectionDistance(object, section)})
end
return ADCpBridge.activeSectionWidth(list) or currentVariableWidth(object)
end
local lastGuardReset = setmetatable({}, {__mode = "k"}) -- redskab -> måling ved sidste nulstilling
function ADCpBridge.guardVariableWidth(vehicle)
for _, object in ipairs(collect(vehicle)) do
local spec = object.spec_variableWorkWidth
if spec ~= nil and type(spec.sections) == "table" and #spec.sections > 0 and object.setSectionsActive ~= nil
and object.getVariableWorkWidth ~= nil then
local current = currentVariableWidth(object)
if ADCpBridge.needsWidthReset(current, ADCpBridge.VARIABLE_TARGET_WIDTH) then
local current = guardedWidth(object, spec)
local reset
reset, lastGuardReset[object] = ADCpBridge.guardDecision(current, ADCpBridge.VARIABLE_TARGET_WIDTH, lastGuardReset[object])
if reset then
Logging.warning("ADSmartPickup: bredde: '%s' er sprunget tilbage til %.1f m under arbejdet — stilles igen",
tostring(object.getName ~= nil and object:getName() or "?"), current)
ADCpBridge.setVariableWidth(vehicle)