feat(markarbejde): faste maskiner pr. mark (bruges kun dér; marken venter på sin egen); fix: AD-påfyldning får varen sat (kom tom tilbage); AD der stopper undervejs startes igen 2x, ellers hjem til parkering (v1.30.0.0)

This commit is contained in:
2026-09-26 18:09:12 +02:00
parent 9ef1eb6655
commit 4c60fd555f
10 changed files with 129 additions and 6 deletions
+37
View File
@@ -78,6 +78,43 @@ end
-- Nærmeste brugbare sæt. Grund når intet passer: noRig (ingen med flueben og rollen), cannotDo (ingen kan
-- tage opgaven, fx afgrøden), allBusy, tooWide/tooNarrow (bredden, med tal fra den første).
-- accept (valgfri): candidate -> bool, fx "høsteren kan tage hvede".
-- Faste maskiner: rigIdsByField = {[fieldId] = {id, ...}}. En maskine der er fast på en ANDEN mark må
-- ikke bruges her. Har marken selv faste maskiner med rollen, bruges kun de (marken venter på sin egen);
-- ellers de frie. (in-game 26/9: sprøjten "til F22" blev sendt til F109.)
function ADFieldFleet.filterDedicated(candidates, fieldId, role, rigIdsByField)
local ownerOf, own = {}, {}
for otherId, ids in pairs(rigIdsByField or {}) do
for _, id in ipairs(ids or {}) do
ownerOf[id] = otherId
if otherId == fieldId then own[id] = true end
end
end
local ownWithRole = {}
for _, candidate in ipairs(candidates or {}) do
local hasRole = candidate.role == role or (candidate.roles ~= nil and candidate.roles[role])
if own[candidate.id] and hasRole then table.insert(ownWithRole, candidate) end
end
if #ownWithRole > 0 then return ownWithRole end
local free = {}
for _, candidate in ipairs(candidates or {}) do
if ownerOf[candidate.id] == nil then table.insert(free, candidate) end
end
return free
end
-- Gør en maskine fast på én mark (fjernes fra andre marker). Returnerer ny tabel {[fieldId] = ids}.
function ADFieldFleet.dedicate(rigIdsByField, fieldId, vehicleId, isOn)
local result = {}
for otherId, ids in pairs(rigIdsByField or {}) do
local copy = {}
for _, id in ipairs(ids or {}) do if id ~= vehicleId then table.insert(copy, id) end end
result[otherId] = copy
end
result[fieldId] = result[fieldId] or {}
if isOn then table.insert(result[fieldId], vehicleId) end
return result
end
function ADFieldFleet.pick(candidates, role, x, z, requiredWidth, accept)
local usable, reason, args = sortCandidates(candidates, role, x, z, requiredWidth, accept)
if usable[1] ~= nil then return usable[1].candidate end