fix(flow): ledig traktor startes kun når målet mangler mere end de andre vogne har med (v1.62.247)

This commit is contained in:
2026-10-16 03:56:51 +02:00
parent 725b8b617c
commit 857d82beae
4 changed files with 37 additions and 4 deletions
+34 -3
View File
@@ -228,7 +228,7 @@ function ADFlowSleep.hasWork(adEnv, run, byId, onlyTractorId)
local name = g_fillTypeManager ~= nil and g_fillTypeManager:getFillTypeNameByIndex(choice.fillType) or tostring(choice.fillType)
return true, string.format("hent %s ved %s (%.0f l der, mål mangler %.0f l), vogn '%s'", tostring(name),
tostring(choice.markerName), choice.level or -1, choice.need ~= nil and choice.need.freeSpace or -1,
tostring(ADRuns.vehicleLabel(cargo)))
tostring(ADRuns.vehicleLabel(cargo))), choice, targetId
end
end
return false, nil
@@ -346,6 +346,32 @@ local restartDue = {} -- runId -> ms hvor næste tjek for ledige traktorer må
local restartWaiting = {} -- runId -> true mens en ledig traktor med arbejde står i udsendelsesportens kø
local lastControlled = setmetatable({}, {__mode = "k"}) -- køretøj -> ms hvor spilleren sidst sad i den
-- Ren: skal endnu en traktor ud? Kun når målet mangler mere end flowets andre vogne allerede har med (in-game 16/10:
-- 'Cow Food 2' sendt ud efter 14.583 l, mens 'Cow Food 1' ventede ved Wait med 157.921 l af samme foder).
function ADFlowSleep.needsMoreThanCarried(freeSpace, carriedByOthers)
if freeSpace == nil then return true end
return freeSpace > (carriedByOthers or 0)
end
-- Liter af varen som flowets ANDRE traktorer har med uden at være meldt "på vej" til målet (fx en rest ved Wait).
-- Meldt på vej er allerede trukket fra målets behov (findSupplyPickup/getPending) — ikke to gange (review 16/10).
local function carriedByOthers(adEnv, run, byId, exceptId, fillType, targetId)
local total = 0
if ADSmartPickup.carriedLiters == nil or fillType == nil then return total end
for _, id in ipairs(run.vehicleIds or {}) do
local vehicle = byId[id]
if id ~= exceptId and vehicle ~= nil then
local route = ADSmartPickup.getEnRoute ~= nil and ADSmartPickup.getEnRoute(vehicle) or nil
local carried = ADSmartPickup.carriedLiters(adEnv, vehicle, fillType) or 0
local counted = route ~= nil and route.fillType == fillType and (targetId == nil or route.wayPointId == targetId)
-- meldt på vej: kun det den har med ud over det meldte (planlagt mængde kan være mindre end lasten)
if counted then carried = math.max(0, carried - (tonumber(route.liters) or 0)) end
total = total + carried
end
end
return total
end
local function restartIdleMember(adEnv, run, byId, now)
local members = {}
for _, id in ipairs(run.vehicleIds or {}) do
@@ -372,8 +398,13 @@ local function restartIdleMember(adEnv, run, byId, now)
end
end
local id = ADFlowSleep.pickIdleMember(run, members)
local hasWork, why = false, nil
if id ~= nil then hasWork, why = ADFlowSleep.hasWork(adEnv, run, byId, id) end
local hasWork, why, choice, choiceTarget = false, nil, nil, nil
if id ~= nil then hasWork, why, choice, choiceTarget = ADFlowSleep.hasWork(adEnv, run, byId, id) end
-- de andre vogne har allerede nok med til det målet mangler: ingen ekstra tur
if hasWork and choice ~= nil and choice.need ~= nil then
local carried = carriedByOthers(adEnv, run, byId, id, choice.fillType, choiceTarget)
if not ADFlowSleep.needsMoreThanCarried(choice.need.freeSpace, carried) then hasWork = false end
end
if not hasWork then
restartDue[run.id] = now + ADFlowSleep.WAKE_CHECK_MS
if ADLaunchGate ~= nil then ADLaunchGate.done(gateName) end
+1
View File
@@ -1077,6 +1077,7 @@ local function carriedLiters(adEnv, driver, fillType)
end)
return total
end
ADSmartPickup.carriedLiters = carriedLiters
-- Køb dyrefoder ved en købestation, når intet eget lager kan levere: første tilladte trug-behov i rækkefølgen.
-- Aldrig når vognen allerede har varen (in-game 8/10: EDK 650 på 1 mio. l blev fyldt ved Solid Buy, truget tog
+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.246.0</version>
<version>1.62.247.0</version>
<title>
<en>AD Smart Pickup</en>
</title>