feat: skift flowets vogn i guiden — tøm, sæt af og hent ny ved start (v1.62.44)

This commit is contained in:
2026-10-06 15:40:27 +02:00
parent a58fb77eb7
commit 3b33060238
5 changed files with 88 additions and 12 deletions
+14 -7
View File
@@ -367,18 +367,23 @@ local function rowsWait(guide)
end
-- Vognvalg under en valgt solo-traktor: dens egen vogn + ledige vogne ingen anden traktor i flowet har.
local function rowWagon(guide, tractorId)
local function rowWagon(guide, tractorId, ownWagon)
local wagons = guide.draft.wagons or {}
local usedByOthers = {}
for otherId, wagonId in pairs(wagons) do
if otherId ~= tractorId then usedByOthers[wagonId] = true end
end
local options = {}
-- vognen der hænger på traktoren nu står først (vælg en anden for at bytte ved næste start)
if ownWagon ~= nil and ownWagon.id ~= nil then table.insert(options, {label = T(tostring(ownWagon.label)), value = ownWagon.id}) end
for _, wagon in ipairs(guide.context.wagons or {}) do
if not usedByOthers[wagon.id] then table.insert(options, {label = T(tostring(wagon.label)), value = wagon.id}) end
if not usedByOthers[wagon.id] and (ownWagon == nil or wagon.id ~= ownWagon.id) then
table.insert(options, {label = T(tostring(wagon.label)), value = wagon.id})
end
end
if #options == 0 or wagons[tractorId] == nil then return text("spu_guide_flow_noFreeWagon") end
return choice("wagon", L("spu_guide_flow_wagon"), options, wagons[tractorId], tractorId)
local current = wagons[tractorId] or (ownWagon ~= nil and ownWagon.id or nil)
if #options == 0 or current == nil then return text("spu_guide_flow_noFreeWagon") end
return choice("wagon", L("spu_guide_flow_wagon"), options, current, tractorId)
end
-- Traktorer: flowets egne først, så de ledige. Traktorer i andre flows og blokerede (vognen passer ikke)
@@ -401,13 +406,15 @@ local function rowsTractors(guide)
blocked = blocked + 1
table.insert(blockedTexts, tostring(vehicle.text))
end
table.insert(entries, {id = vehicle.id, label = tostring(vehicle.text), state = state})
table.insert(entries, {id = vehicle.id, label = tostring(vehicle.text), state = state, ownWagon = vehicle.ownWagon})
end
local solo = soloIds(guide.context)
for _, entry in ipairs(ADFlowView.vehicleRows(entries, false)) do
table.insert(rows, check("vehicleIds", entry.id, entry.label, entry.state == "in"))
if entry.state == "in" and solo[entry.id] then
local wagonRow = rowWagon(guide, entry.id)
local own = nil
for _, e in ipairs(entries) do if e.id == entry.id then own = e.ownWagon end end
if entry.state == "in" and (solo[entry.id] or own ~= nil) then
local wagonRow = rowWagon(guide, entry.id, own)
if wagonRow ~= nil then table.insert(rows, wagonRow) end
end
end
+62 -3
View File
@@ -33,6 +33,12 @@ end
function ADFlowWagons.startAction(s)
-- lånt ud af puljen (markarbejde, marksilo, på hjemtur): vent til den er fri
if s.tractorBusy then return "wait" end
-- spilleren har valgt en anden vogn end den der hænger på (brugerønske 6/10: Chicken Food-vognen var for stor):
-- byt, når den valgte er ledig og kan hentes — ellers videre med den der sidder på
if s.hasRear and s.rearId ~= nil and s.wagonId ~= nil and s.rearId ~= s.wagonId and s.wagonExists and s.hasConnect
and not s.wagonAttached and not s.wagonBusy and s.rearParkId ~= nil then
return "swap"
end
if s.hasRear or s.wagonId == nil or not s.wagonExists or not s.hasConnect then return "start" end
if s.wagonAttached or s.wagonBusy then return "wait" end
return "fetch"
@@ -336,7 +342,15 @@ function ADFlowWagons.beforeStart(adEnv, run, vehicle)
end
local wagon = wagonId ~= nil and findAnyVehicle(wagonId) or nil
local connectId = wagon ~= nil and connectOf(adEnv, wagon) or nil
local rear = ADHitch.rearImplementsOf(vehicle)[1]
local rearId = rear ~= nil and ADRunsController.getVehicleId(rear.object) or nil
local rearPark = nil
if rear ~= nil and rear.object.advd ~= nil and type(rear.object.advd.parkDestination) == "number" then
local marker = adEnv.ADGraphManager:getMapMarkerById(rear.object.advd.parkDestination)
rearPark = marker ~= nil and marker.id or nil
end
local startState = {
rearId = rearId, rearParkId = rearPark,
tractorBusy = ADFlowWagons.isPoolBusy(vehicle, tractorId),
hasRear = #ADHitch.rearImplementsOf(vehicle) > 0, wagonId = wagonId, wagonExists = wagon ~= nil,
hasConnect = connectId ~= nil,
@@ -346,6 +360,26 @@ function ADFlowWagons.beforeStart(adEnv, run, vehicle)
local action = ADFlowWagons.startAction(startState)
if action == "start" then lastWaitText[vehicle] = nil return false end
ADRunsController.runningRuns[run.id] = true
if action == "swap" then
fetching[vehicle] = run.id
local runId = run.id
Logging.info(ADFlowWagons.LOG_PREFIX .. "flow '%s': '%s' bytter vogn — '%s' sættes af, '%s' hentes", tostring(run.name),
tostring(ADRuns.vehicleLabel(vehicle)), tostring(ADRuns.vehicleLabel(rear.object)), tostring(ADRuns.vehicleLabel(wagon)))
local okSwap, errSwap = pcall(ADFlowWagons.emptyThen, adEnv, vehicle, run, function() ADHitch.route(adEnv, vehicle, {rearPark, connectId}, function(tractor, ok, detail)
fetching[tractor] = nil
local current = ADRuns.getRun(ADRunsController.store, runId)
if current == nil or current.stopped then ADHitch.returnHome(adEnv, tractor) return end
if ok then
local result = ADRunsController.startVehicle(adEnv, current, tractor)
if result ~= nil and not result.ok then ADHitch.returnHome(adEnv, tractor) end
else
Logging.warning(ADFlowWagons.LOG_PREFIX .. "flow '%s': '%s' kunne ikke bytte vogn (%s)", tostring(current.name),
tostring(ADRuns.vehicleLabel(tractor)), tostring(detail))
end
end) end)
if not okSwap then fetching[vehicle] = nil return true, {vehicle = vehicle, ok = false, reason = "error"} end
return true, {vehicle = vehicle, ok = true, reason = "fetchingWagon"}
end
if action == "wait" then
local holder = wagon ~= nil and wagon.getAttacherVehicle ~= nil and wagon:getAttacherVehicle() or nil
local waitText = ADFlowWagons.waitReason(startState) .. ": " .. (startState.tractorBusy and ADFlowWagons.busyWhy(vehicle, tractorId)
@@ -510,6 +544,28 @@ function ADFlowWagons.homeVehicle(adEnv, vehicle, runName, reason)
end
end
-- Tøm vognen (flowets mål, ellers silo/egen fabrik) og kald så onEmptied — i stedet for hjemturen (vognbytte 6/10).
local function emptyThen(adEnv, vehicle, run, onEmptied)
local module = vehicle.ad ~= nil and vehicle.ad.stateModule or nil
local second = module ~= nil and module.getSecondMarker ~= nil and module:getSecondMarker() or nil
local targetId = ADFlowWagons.emptyTarget(second ~= nil and second.id or nil, run ~= nil and run.targetWayPointIds or nil)
local target = targetId ~= nil and adEnv.ADGraphManager:getMapMarkerByWayPointId(targetId) or nil
local cargo, fillType = cargoOf(adEnv, vehicle)
local action = ADFlowWagons.emptyStep("start", {cargo = cargo, hasTarget = target ~= nil})
if action == "home" then return onEmptied() end
local state = {stage = action, since = nowMs, runName = run ~= nil and run.name or nil, onEmptied = onEmptied,
markerId = target ~= nil and target.id or nil, markerName = target ~= nil and target.name or nil}
emptying[vehicle] = state
if action == "target" then
ADFieldWork.startAd(adEnv, vehicle, adEnv.AutoDrive.MODE_DELIVERTO, target.id, nil, fillType)
Logging.info(ADFlowWagons.LOG_PREFIX .. "'%s' afleverer sit læs (%d l %s) ved %s før vognbyttet",
tostring(ADRuns.vehicleLabel(vehicle)), math.floor(cargo), fillName(fillType), tostring(target.name))
else
startDump(adEnv, vehicle, state)
end
end
ADFlowWagons.emptyThen = emptyThen
-- ADHitch: spilleren har selv kørt traktoren til Connect og koblet på.
function ADFlowWagons.onManualAttach(adEnv, vehicle, wagon)
local run = ADRunsController.getRunForVehicle(vehicle)
@@ -618,13 +674,13 @@ local function tickEmptying(adEnv)
tostring(state.markerName))
end
if action == "home" then
goHome(adEnv, vehicle)
if state.onEmptied ~= nil then emptying[vehicle] = nil state.onEmptied() else goHome(adEnv, vehicle) end
elseif action == "dump" then
startDump(adEnv, vehicle, state)
elseif action == "giveUp" then
Logging.warning(ADFlowWagons.LOG_PREFIX .. "'%s' kunne ikke tømme vognen (%d l %s tilbage) — parkeres med last",
tostring(ADRuns.vehicleLabel(vehicle)), math.floor(cargo), fillName(fillType))
goHome(adEnv, vehicle)
if state.onEmptied ~= nil then emptying[vehicle] = nil state.onEmptied() else goHome(adEnv, vehicle) end
end
end
end
@@ -637,7 +693,10 @@ local function rememberAll(adEnv)
local vehicle = ADRunsController.findVehicleById(adEnv, vehicleId)
local rear = vehicle ~= nil and ADHitch.rearImplementsOf(vehicle) or {}
local wagonId = rear[1] ~= nil and isCargoWagon(rear[1].object) and ADRunsController.getVehicleId(rear[1].object) or nil
if wagonId ~= nil then
-- et valgt vogn (fx i guiden, byttes ved start) overskrives ikke af den der hænger på, så længe den findes
local chosen = (run.wagons or {})[vehicleId]
local keepChoice = chosen ~= nil and chosen ~= wagonId and findAnyVehicle(chosen) ~= nil
if wagonId ~= nil and not keepChoice and fetching[vehicle] == nil and emptying[vehicle] == nil then
local updated = ADFlowWagons.remember(run.wagons, vehicleId, wagonId)
if updated ~= run.wagons then
run.wagons = updated
@@ -176,8 +176,17 @@ function SmartPickupFrame:flowVehicleContext(adEnv, preview, wagons)
local solo = validation.reason == "noTrailer" and ADPool.canPull(ADPool.ownRole(vehicle))
if solo and hasWagons then text = string.format(self.i18n:getText("spu_guide_flow_soloText"), tostring(label)) end
local blocked = SmartPickupFrame.VEHICLE_BLOCKING_REASONS[validation.reason] == true and not (solo and hasWagons)
-- vognen der hænger på nu (kan byttes til en ledig i vognvalget)
local own = nil
local rear = ADHitch.rearImplementsOf(vehicle)[1]
if rear ~= nil and rear.object ~= nil then
local okCap, _, capacity = pcall(ADPool.cargoOf, rear.object)
if okCap and (capacity or 0) > 0 then
own = {id = ADRunsController.getVehicleId(rear.object), label = tostring(ADRuns.vehicleLabel(rear.object))}
end
end
return {id = ADRunsController.getVehicleId(vehicle), text = text, label = label, otherRunId = other ~= nil and other.id or nil,
otherRunName = other ~= nil and other.name or nil, blocked = blocked, solo = solo}
otherRunName = other ~= nil and other.name or nil, blocked = blocked, solo = solo, ownWagon = own}
end)
if ok and entry.id ~= nil then
table.insert(result, entry)
+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.43.0</version>
<version>1.62.44.0</version>
<title>
<en>AD Smart Pickup</en>
</title>