feat: udkørsel koblet på AutoDrive-hooks; Wait-logik springer udkørsels-traktorer over; v1.12.0.0

This commit is contained in:
2026-09-23 09:59:10 +02:00
parent de36abe1fa
commit cb115f9588
4 changed files with 85 additions and 3 deletions
+37 -1
View File
@@ -13,6 +13,8 @@ ADSmartPickup = {}
ADSmartPickup.dir = g_currentModDirectory
if ADSmartPickup.dir ~= nil and source ~= nil then
source(ADSmartPickup.dir .. "gui/SmartPickupFrame.lua")
source(ADSmartPickup.dir .. "gui/SmartPickupSupplyTab.lua")
source(ADSmartPickup.dir .. "gui/SmartPickupOutboundTab.lua")
end
-- Markøren er dér hvor trækkerens næse stopper; læssetriggeren ligger et
@@ -607,6 +609,16 @@ function ADSmartPickup.getActivePickup(vehicle)
return {markerName = pickup.markerName, fillType = pickup.fillType}
end
-- Udkørslens opsamlingsrunde skifter kilde midt i en tur: grebet ("stå og læs ved markøren")
-- følger med til den nye kilde. choice = {station, fillTypes, markerName, fillType} eller nil.
function ADSmartPickup.setActivePickup(vehicle, choice)
if choice == nil or choice.station == nil then
activePickups[vehicle] = nil
return
end
activePickups[vehicle] = {station = choice.station, fillTypes = choice.fillTypes or {}, markerName = choice.markerName, fillType = choice.fillType or (choice.fillTypes or {})[1]}
end
function ADSmartPickup.getIngredientsFor(adEnv, driver)
local run = ADRunsController ~= nil and ADRunsController.getRunForVehicle(driver) or nil
if run ~= nil then
@@ -790,6 +802,24 @@ local function installHook(adEnv)
local originalGetNextPickup = manager.getNextPickup
manager.getNextPickup = function(self, driver, forcedSkip)
-- Udkørsel: turvalg (kilde + mål + varer) eller Wait-punkt fra ADOutbound.
if ADOutbound ~= nil and ADOutbound.isOutboundVehicle(driver) then
local okOut, outChoice = pcall(ADOutbound.choosePickup, adEnv, driver)
if not okOut then
Logging.warning(ADSmartPickup.LOG_PREFIX .. "fejl i udkørsel, bruger AutoDrives rotation: %s", tostring(outChoice))
activePickups[driver] = nil
return originalGetNextPickup(self, driver, forcedSkip)
end
if outChoice == nil then
activePickups[driver] = nil
return originalGetNextPickup(self, driver, forcedSkip)
end
ADSmartPickup.setActivePickup(driver, outChoice)
self.pickups[outChoice.group] = self.pickups[outChoice.group] or {}
self.pickups[outChoice.group].lastTarget = outChoice.markerIndex
self.pickups[outChoice.group].lastVehicle = driver
return outChoice.markerIndex
end
local ok, choice = pcall(ADSmartPickup.choosePickup, adEnv, driver)
if not ok then
Logging.warning(ADSmartPickup.LOG_PREFIX .. "fejl i silo-opslag, bruger AutoDrives rotation: %s", tostring(choice))
@@ -815,8 +845,11 @@ local function installHook(adEnv)
if ADUnloadWait ~= nil then
ADUnloadWait.install(adEnv)
end
if ADOutbound ~= nil and ADOutbound.install ~= nil then
ADOutbound.install(adEnv)
end
Logging.info(ADSmartPickup.LOG_PREFIX .. "aktiv (mindst fyldte silo med varen; flere valgte varer = behovsstyret forsyning; Wait-punkter for rest-læs)")
Logging.info(ADSmartPickup.LOG_PREFIX .. "aktiv (mindst fyldte silo med varen; flere valgte varer = behovsstyret forsyning; Wait-punkter for rest-læs; udkørsel til silo/salg)")
end
-- Når AutoDrive stopper, får køretøjet hele ingredienslisten tilbage i varevalget
@@ -914,6 +947,9 @@ function ADSmartPickup:update(dt)
if ADUnloadWait ~= nil then
pcall(ADUnloadWait.releaseInactive)
end
if ADOutbound ~= nil and ADOutbound.releaseInactive ~= nil then
pcall(ADOutbound.releaseInactive)
end
local ok, err = pcall(restoreStoppedVehicles)
if not ok then
Logging.warning(ADSmartPickup.LOG_PREFIX .. "kunne ikke gendanne varevalg: %s", tostring(err))