fix: breddevagt højst én nulstilling pr. redskab hvert 5. min, tolerance på målingen (v1.62.62)

This commit is contained in:
2026-10-07 21:46:48 +02:00
parent 514da163a9
commit d5ed292741
3 changed files with 24 additions and 8 deletions
+22 -7
View File
@@ -523,9 +523,15 @@ 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).
ADCpBridge.GUARD_COOLDOWN_MS = 5 * 60 * 1000 -- højst én nulstilling pr. redskab så tit
function ADCpBridge.guardCooldownOver(lastAt, nowMs)
return lastAt == nil or nowMs - lastAt >= ADCpBridge.GUARD_COOLDOWN_MS
end
ADCpBridge.GUARD_SAME_READING_M = 1 -- målinger så tæt på hinanden er "den samme" (kommatal varierer)
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
if lastReset ~= nil and math.abs(current - lastReset) < ADCpBridge.GUARD_SAME_READING_M then return false, lastReset end
return true, current
end
@@ -536,28 +542,37 @@ local function sectionDistance(object, section)
return okD and math.abs(x or 0) or 0
end
-- Aktiv bredde ud fra sektionerne (som setVariableWidth regner), ellers spillets måling.
-- Aktiv bredde ud fra sektionerne (som setVariableWidth regner), ellers spillets måling. -> bredde, kilde
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)
local fromSections = ADCpBridge.activeSectionWidth(list)
if fromSections ~= nil then return fromSections, "sektioner" end
return currentVariableWidth(object), "spillets måling"
end
local lastGuardReset = setmetatable({}, {__mode = "k"}) -- redskab -> måling ved sidste nulstilling
local lastGuardResetAt = setmetatable({}, {__mode = "k"}) -- redskab -> tid (ms) for sidste nulstilling
local function guardNow()
if g_currentMission ~= nil and type(g_currentMission.time) == "number" then return g_currentMission.time end
return os.clock() * 1000
end
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 = guardedWidth(object, spec)
local current, source = 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)
local now = guardNow()
if reset and ADCpBridge.guardCooldownOver(lastGuardResetAt[object], now) then
lastGuardResetAt[object] = now
Logging.warning("ADSmartPickup: bredde: '%s' er sprunget tilbage til %.1f m under arbejdet (%s) — stilles igen",
tostring(object.getName ~= nil and object:getName() or "?"), current, source)
ADCpBridge.setVariableWidth(vehicle)
return true
end
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107">
<author>masterdraco</author>
<version>1.62.61.0</version>
<version>1.62.62.0</version>
<title>
<en>AD Smart Pickup</en>
</title>