feat(markarbejde): tom spreder/sprøjte kan bruges (roller efter hvad den kan tage; påfyldning med rollens vare); spreder med forkert vare tømmes først og vælges kun hvis ingen anden kan (v1.28.8.0)

This commit is contained in:
2026-09-26 12:51:03 +02:00
parent abbe40da01
commit 6138b6b874
7 changed files with 128 additions and 16 deletions
+8 -3
View File
@@ -40,7 +40,7 @@ local function sortCandidates(candidates, role, x, z, requiredWidth, accept)
local usable, sawRole, sawAccepted = {}, false, false
local widthReason, widthArgs = nil, nil
for _, candidate in ipairs(candidates) do
if candidate.role == role and candidate.enabled then
if (candidate.role == role or (candidate.roles ~= nil and candidate.roles[role])) and candidate.enabled then
sawRole = true
if accept == nil or accept(candidate) then
sawAccepted = true
@@ -48,7 +48,9 @@ local function sortCandidates(candidates, role, x, z, requiredWidth, accept)
local ok, reason, args = ADFieldModel.checkWidth(role, candidate.width or 0, requiredWidth)
if ok then
local dx, dz = candidate.x - x, candidate.z - z
table.insert(usable, {candidate = candidate, distance = dx * dx + dz * dz})
-- spreder med en anden vare på skal tømmes først: kun hvis ingen anden kan
local wrongFill = candidate.filledRole ~= nil and candidate.filledRole ~= role
table.insert(usable, {candidate = candidate, distance = dx * dx + dz * dz, wrongFill = wrongFill})
elseif widthReason == nil then
widthReason, widthArgs = reason, args
end
@@ -56,7 +58,10 @@ local function sortCandidates(candidates, role, x, z, requiredWidth, accept)
end
end
end
table.sort(usable, function(a, b) return a.distance < b.distance end)
table.sort(usable, function(a, b)
if a.wrongFill ~= b.wrongFill then return not a.wrongFill end
return a.distance < b.distance
end)
local reason, args = nil, nil
if not sawRole then
reason = "noRig"