fix(udsendelse): retfærdig kø i udsendelsesporten — længst ventende sender næste maskine ud (v1.62.239)
This commit is contained in:
@@ -648,13 +648,16 @@ function ADFieldSilos.planNow(adEnv)
|
||||
ADFieldSilos.lastFeed = {reserve = feedReserve, stock = farmStock}
|
||||
ADFieldSilos.lastPlan = plan
|
||||
local paused = ADFieldJobs ~= nil and ADFieldJobs.state ~= nil and ADFieldJobs.state.paused
|
||||
if not cfg.enabled or paused then return plan end
|
||||
if not cfg.enabled or paused then
|
||||
if ADLaunchGate ~= nil then ADLaunchGate.done("fieldSilos") end
|
||||
return plan
|
||||
end
|
||||
local silosById, storesById = {}, {}
|
||||
for _, silo in ipairs(silos) do silosById[silo.id] = silo end
|
||||
for _, store in ipairs(stores) do storesById[store.id] = store end
|
||||
for _, order in ipairs(plan.dispatch) do
|
||||
-- fælles udsendelsesport: én maskine ad gangen; resten planlægges igen om lidt
|
||||
if ADLaunchGate ~= nil and not ADLaunchGate.isOpen() then
|
||||
if ADLaunchGate ~= nil and not ADLaunchGate.isOpen("fieldSilos") then
|
||||
gateBlocked = true
|
||||
break
|
||||
end
|
||||
@@ -665,20 +668,22 @@ function ADFieldSilos.planNow(adEnv)
|
||||
local pair = poolById ~= nil and poolById[order.vehicleId] or nil
|
||||
if vehicle ~= nil and pair ~= nil then
|
||||
local ok, err = pcall(dispatchPool, adEnv, order, pair, silosById, storesById)
|
||||
if ok and ADLaunchGate ~= nil then ADLaunchGate.markLaunched() end
|
||||
if ok and ADLaunchGate ~= nil then ADLaunchGate.markLaunched("fieldSilos") end
|
||||
if not ok then
|
||||
loans[vehicle] = nil
|
||||
Logging.warning(ADFieldSilos.LOG_PREFIX .. "kunne ikke sende '%s' efter puljevogn: %s", tostring(ADRuns.vehicleLabel(vehicle)), tostring(err))
|
||||
end
|
||||
elseif vehicle ~= nil then
|
||||
local ok, err = pcall(dispatchOne, adEnv, order, vehicle, silosById, storesById)
|
||||
if ok and ADLaunchGate ~= nil then ADLaunchGate.markLaunched() end
|
||||
if ok and ADLaunchGate ~= nil then ADLaunchGate.markLaunched("fieldSilos") end
|
||||
if not ok then
|
||||
loans[vehicle] = nil
|
||||
Logging.warning(ADFieldSilos.LOG_PREFIX .. "kunne ikke sende '%s': %s", tostring(ADRuns.vehicleLabel(vehicle)), tostring(err))
|
||||
end
|
||||
end
|
||||
end
|
||||
-- ikke blokeret: intet mere at sende ud nu — ud af portens kø
|
||||
if not gateBlocked and ADLaunchGate ~= nil then ADLaunchGate.done("fieldSilos") end
|
||||
return plan
|
||||
end
|
||||
|
||||
@@ -692,7 +697,7 @@ function ADFieldSilos.tick(adEnv, dt)
|
||||
checkLoans(adEnv)
|
||||
end
|
||||
planTimerMs = planTimerMs + (dt or 0)
|
||||
local gateReady = gateBlocked and ADLaunchGate ~= nil and ADLaunchGate.isOpen()
|
||||
local gateReady = gateBlocked and ADLaunchGate ~= nil and ADLaunchGate.isOpen("fieldSilos")
|
||||
if planTimerMs >= ADFieldSilos.PLAN_INTERVAL_MS or gateReady then
|
||||
planTimerMs, gateBlocked = 0, false
|
||||
ADFieldSilos.planNow(adEnv)
|
||||
|
||||
Reference in New Issue
Block a user