feat: gylle som gødning — flåden foretrækker gyllevogn når lageret dækker mindst X % af markens behov (indstilling, 80 %), salg holder markernes resterende behov tilbage (loft 80 % af tankkapacitet), påfyldning nærmeste tank med helt læs først — 1.62.305

This commit is contained in:
2026-10-17 10:18:34 +02:00
parent 2d7b696821
commit 244f98109b
13 changed files with 308 additions and 23 deletions
+9 -6
View File
@@ -49,7 +49,8 @@ function ADFieldFleet.rolesFor(role)
end
-- Kandidater med rollen, sorteret nærmest først, delt i brugbare og afviste (med første grund).
local function sortCandidates(candidates, role, x, z, requiredWidth, accept)
-- prefer (valgfri): candidate -> bool; foretrukne sæt vælges før andre (fx gyllevogn før kunstgødning), nærmest først inden for hver gruppe
local function sortCandidates(candidates, role, x, z, requiredWidth, accept, prefer)
local usable, sawRole, sawAccepted = {}, false, false
local widthReason, widthArgs = nil, nil
for _, candidate in ipairs(candidates) do
@@ -65,7 +66,8 @@ local function sortCandidates(candidates, role, x, z, requiredWidth, accept)
local wrongFill = candidate.filledRole ~= nil and candidate.filledRole ~= role
-- fuld af en anden vare: bruges slet ikke til denne opgave (resten hældes kun ud når den er lille)
if not (wrongFill and candidate.dumpable == false) then
table.insert(usable, {candidate = candidate, distance = dx * dx + dz * dz, wrongFill = wrongFill})
table.insert(usable, {candidate = candidate, distance = dx * dx + dz * dz, wrongFill = wrongFill,
preferred = prefer ~= nil and prefer(candidate) == true})
end
elseif widthReason == nil then
widthReason, widthArgs = reason, args
@@ -76,6 +78,7 @@ local function sortCandidates(candidates, role, x, z, requiredWidth, accept)
end
table.sort(usable, function(a, b)
if a.wrongFill ~= b.wrongFill then return not a.wrongFill end
if a.preferred ~= b.preferred then return a.preferred end
return a.distance < b.distance
end)
local reason, args = nil, nil
@@ -131,15 +134,15 @@ function ADFieldFleet.dedicate(rigIdsByField, fieldId, vehicleId, isOn)
return result
end
function ADFieldFleet.pick(candidates, role, x, z, requiredWidth, accept)
local usable, reason, args = sortCandidates(candidates, role, x, z, requiredWidth, accept)
function ADFieldFleet.pick(candidates, role, x, z, requiredWidth, accept, prefer)
local usable, reason, args = sortCandidates(candidates, role, x, z, requiredWidth, accept, prefer)
if usable[1] ~= nil then return usable[1].candidate end
return nil, reason, args
end
-- n sæt på én gang (multi-tool kræver alle baner): de n nærmeste, ellers ingen. notEnough har {ledige, n}.
function ADFieldFleet.pickMany(candidates, role, n, x, z, requiredWidth, accept)
local usable, reason, args = sortCandidates(candidates, role, x, z, requiredWidth, accept)
function ADFieldFleet.pickMany(candidates, role, n, x, z, requiredWidth, accept, prefer)
local usable, reason, args = sortCandidates(candidates, role, x, z, requiredWidth, accept, prefer)
if #usable >= n then
local picked = {}
for index = 1, n do picked[index] = usable[index].candidate end