fix(review): palle/bulk pr. kilde, pallefabrikker uden læssestation, hold-omdirigering, last ved Start, tomme kilder udelukkes, færre rutetjek, advarsler huskes, paller kun Fra/Salg
This commit is contained in:
@@ -21,6 +21,10 @@ ADOutbound.SPAWN_STALL_MS = 30000
|
||||
-- UAL kan først læsse når vognen holder helt stille (AutoDrives egen grænse).
|
||||
ADOutbound.MAX_SPEED_FOR_LOADING = 0.0005
|
||||
ADOutbound.NOTIFICATION_MS = 8000
|
||||
-- Tom vogn ved kilden så længe uden at få noget = kilden har ikke varen alligevel (paller ikke
|
||||
-- spawnet, forkert farm, ...): kilden udelukkes for varen i EMPTY_SOURCE_TTL_MS og turen afsluttes.
|
||||
ADOutbound.EMPTY_SOURCE_MS = 30000
|
||||
ADOutbound.EMPTY_SOURCE_TTL_MS = 300000
|
||||
|
||||
-- køretøj -> {run, trip, sources, queue, visited, current, lastFill, noProgressMs, spawn, done}
|
||||
local trips = setmetatable({}, {__mode = "k"})
|
||||
@@ -30,8 +34,17 @@ local holds = setmetatable({}, {__mode = "k"})
|
||||
local status = {}
|
||||
-- køretøj -> {[nøgle] = tekst} (advarsler vises én gang pr. ændret tekst)
|
||||
local warned = setmetatable({}, {__mode = "k"})
|
||||
-- "kilde-id:fillType" -> tidspunkt (ms) hvor udelukkelsen udløber
|
||||
local emptyUntil = {}
|
||||
local isInstalled = false
|
||||
|
||||
local function now()
|
||||
if g_currentMission ~= nil and type(g_currentMission.time) == "number" then
|
||||
return g_currentMission.time
|
||||
end
|
||||
return os.clock() * 1000
|
||||
end
|
||||
|
||||
local function getRun(vehicle)
|
||||
return ADRunsController ~= nil and ADRunsController.getRunForVehicle ~= nil and ADRunsController.getRunForVehicle(vehicle) or nil
|
||||
end
|
||||
@@ -95,33 +108,50 @@ end
|
||||
local function wantsSell(policy) return policy == "sell" or policy == "sellElseStore" end
|
||||
local function wantsStore(policy) return policy == "store" or policy == "sellElseStore" end
|
||||
|
||||
-- Bedste NÅELIGE salgssted for varen; unreachableName = navnet på det bedste der ikke kan nås.
|
||||
local function findSellQuote(adEnv, vehicle, product, farmId)
|
||||
local quotes, unreachableName = {}, nil
|
||||
local homeId = product.sources[1] ~= nil and product.sources[1].wayPointId or nil
|
||||
for _, entry in ipairs(ADSources.getSellMarkers(adEnv, farmId)) do
|
||||
-- Bedste salgssted for varen. Rutetjek (A*) laves kun for stationer over pristærsklen, bedste
|
||||
-- først, og stopper ved den første nåelige. Er ingen over tærsklen, returneres det bedste
|
||||
-- (unåelighed er ligegyldig, turen kører alligevel ikke) — til begrundelse og UI.
|
||||
-- unreachableName = det bedst betalende over tærsklen, når intet over tærsklen kan nås.
|
||||
local function findSellQuote(adEnv, vehicle, product, sellMarkers, sellAtPercent, homeId)
|
||||
local quotes = {}
|
||||
for _, entry in ipairs(sellMarkers) do
|
||||
if ADSources.stationAccepts(entry.station, product.fillType) then
|
||||
local quote = ADPrices.getQuote(entry.station, product.fillType)
|
||||
if quote ~= nil then
|
||||
local reachable = homeId == nil or ADWaitPool.hasRouteBothWays(adEnv, vehicle, entry.marker.id, homeId)
|
||||
if reachable then
|
||||
table.insert(quotes, {percent = quote.percent, price = quote.price, top = quote.top, wayPointId = entry.marker.id, stationName = tostring(entry.marker.name)})
|
||||
elseif unreachableName == nil then
|
||||
unreachableName = tostring(entry.marker.name)
|
||||
end
|
||||
table.insert(quotes, {percent = quote.percent, price = quote.price, top = quote.top, wayPointId = entry.marker.id, stationName = tostring(entry.marker.name)})
|
||||
end
|
||||
end
|
||||
end
|
||||
return ADPrices.bestQuote(quotes), unreachableName
|
||||
table.sort(quotes, function(a, b)
|
||||
if a.percent ~= b.percent then return a.percent > b.percent end
|
||||
if a.price ~= b.price then return a.price > b.price end
|
||||
return a.wayPointId < b.wayPointId
|
||||
end)
|
||||
local unreachableName = nil
|
||||
for _, quote in ipairs(quotes) do
|
||||
if quote.percent < (sellAtPercent or 90) then
|
||||
break
|
||||
end
|
||||
if homeId == nil or ADWaitPool.hasRouteBothWays(adEnv, vehicle, quote.wayPointId, homeId) then
|
||||
return quote, nil
|
||||
end
|
||||
unreachableName = unreachableName or quote.stationName
|
||||
end
|
||||
if unreachableName ~= nil then
|
||||
return nil, unreachableName
|
||||
end
|
||||
return quotes[1], nil
|
||||
end
|
||||
|
||||
local function findStoreMarker(adEnv, vehicle, product, capacity, sources)
|
||||
local function findStoreMarker(adEnv, vehicle, product, capacity, sources, litersOverride)
|
||||
if product.isPallet or ADLoadSwap == nil or ADLoadSwap.findDumpMarker == nil then
|
||||
return nil
|
||||
end
|
||||
local available = 0
|
||||
for _, source in ipairs(product.sources) do
|
||||
available = available + (source.available or 0)
|
||||
local available = litersOverride or 0
|
||||
if litersOverride == nil then
|
||||
for _, source in ipairs(product.sources) do
|
||||
available = available + (source.available or 0)
|
||||
end
|
||||
end
|
||||
local liters = math.max(1, math.min(available, capacity or available))
|
||||
local isReachable = function(markerId)
|
||||
@@ -154,11 +184,14 @@ function ADOutbound.buildPlanInput(adEnv, run, vehicle)
|
||||
end
|
||||
end
|
||||
local byName, products = {}, {}
|
||||
local time = now()
|
||||
for _, source in ipairs(sources) do
|
||||
for _, item in ipairs(ADSources.getProducts(adEnv, source, farmId)) do
|
||||
local policy = ADRuns.getProductPolicy(run, item.name)
|
||||
local canCarry = (item.isPallet and hasAutoload) or (not item.isPallet and carriable[item.fillType] == true)
|
||||
if policy ~= "off" and canCarry then
|
||||
local emptyKey = tostring(source.wayPointId) .. ":" .. tostring(item.fillType)
|
||||
local isMarkedEmpty = emptyUntil[emptyKey] ~= nil and emptyUntil[emptyKey] > time
|
||||
if policy ~= "off" and canCarry and not isMarkedEmpty then
|
||||
local product = byName[item.name]
|
||||
if product == nil then
|
||||
product = {fillType = item.fillType, name = item.name, policy = policy, isPallet = item.isPallet, sources = {}}
|
||||
@@ -170,9 +203,12 @@ function ADOutbound.buildPlanInput(adEnv, run, vehicle)
|
||||
end
|
||||
end
|
||||
table.sort(products, function(a, b) return a.name < b.name end)
|
||||
-- salgsstederne findes én gang pr. plan (opslag over alle markører × stationer)
|
||||
local sellMarkers = ADSources.getSellMarkers(adEnv, farmId)
|
||||
for _, product in ipairs(products) do
|
||||
if wantsSell(product.policy) then
|
||||
local quote, unreachableName = findSellQuote(adEnv, vehicle, product, farmId)
|
||||
local homeId = product.sources[1] ~= nil and product.sources[1].wayPointId or nil
|
||||
local quote, unreachableName = findSellQuote(adEnv, vehicle, product, sellMarkers, run.sellAtPercent, homeId)
|
||||
product.quote = quote
|
||||
if quote == nil and unreachableName ~= nil then
|
||||
warnOnce(adEnv, vehicle, "sell:" .. product.name, string.format("'%s' kan ikke nå salgssted '%s' for %s – tjek vejnettet", tostring(vehicle:getName()), unreachableName, product.name))
|
||||
@@ -195,6 +231,38 @@ function ADOutbound.buildPlanInput(adEnv, run, vehicle)
|
||||
return input, sourcesById, sources
|
||||
end
|
||||
|
||||
-- Mål for last der ALLEREDE er på vognen (ved Start efter genindlæsning/stop): salgssted hvis
|
||||
-- prisen holder, ellers silo hvis politikken tillader lager. nil = intet mål (Start afvises).
|
||||
function ADOutbound.planCargoTarget(adEnv, run, vehicle, fillType, liters)
|
||||
local name = fillTypeName(fillType)
|
||||
local policy = ADRuns.getProductPolicy(run, name)
|
||||
if policy == "off" then
|
||||
return nil
|
||||
end
|
||||
local farmId = ADSmartPickup.getFarmId(vehicle)
|
||||
local capacity = getVehicleCapacity(adEnv, vehicle)
|
||||
local sources = {}
|
||||
for _, wayPointId in ipairs(run.sourceWayPointIds or {}) do
|
||||
local source = ADSources.identify(adEnv, wayPointId, farmId)
|
||||
if source ~= nil then table.insert(sources, source) end
|
||||
end
|
||||
local product = {fillType = fillType, name = name, policy = policy, isPallet = false, sources = {}}
|
||||
if wantsSell(policy) then
|
||||
local homeId = run.sourceWayPointIds ~= nil and run.sourceWayPointIds[1] or nil
|
||||
local quote = findSellQuote(adEnv, vehicle, product, ADSources.getSellMarkers(adEnv, farmId), run.sellAtPercent, homeId)
|
||||
if quote ~= nil and quote.percent >= (run.sellAtPercent or 90) then
|
||||
return quote.wayPointId
|
||||
end
|
||||
end
|
||||
if wantsStore(policy) then
|
||||
local store = findStoreMarker(adEnv, vehicle, product, capacity, sources, liters or capacity)
|
||||
if store ~= nil then
|
||||
return store.wayPointId
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- ---- tur ----
|
||||
|
||||
local function copyList(list)
|
||||
@@ -301,8 +369,15 @@ function ADOutbound.choosePickup(adEnv, vehicle)
|
||||
end
|
||||
releaseHold(vehicle)
|
||||
runStatus.warning = nil
|
||||
warned[vehicle] = nil
|
||||
applyTrip(adEnv, vehicle, run, trip, sourcesById)
|
||||
-- Prisgrundlaget logges, så det kan holdes op mod spillets Priser-menu (I5 i review).
|
||||
if trip.kind == "sell" then
|
||||
for _, product in ipairs(input.products) do
|
||||
if product.fillType == trip.fillTypes[1] and product.quote ~= nil then
|
||||
Logging.info(ADOutbound.LOG_PREFIX .. "'%s' pris %s: %.0f kr/1000 l ved %s, årets top %.0f -> %d %% (kræver %d)", tostring(vehicle:getName()), product.name, (product.quote.price or 0) * 1000, tostring(product.quote.stationName), (product.quote.top or 0) * 1000, product.quote.percent or 0, run.sellAtPercent or 90)
|
||||
end
|
||||
end
|
||||
end
|
||||
local marker = getMarker(adEnv, trip.sourceIds[1])
|
||||
if marker == nil then
|
||||
return nil
|
||||
@@ -346,6 +421,13 @@ local function updateHold(adEnv, task, hold, dt)
|
||||
local state = trips[vehicle]
|
||||
if state ~= nil then
|
||||
goToSource(adEnv, state, task, state.current)
|
||||
return true
|
||||
end
|
||||
-- stadig hold, men ved en anden markør (et Wait-punkt blev ledigt): kør derhen
|
||||
local newHold = holds[vehicle]
|
||||
if newHold ~= nil and newHold.markerId ~= task.destinationID then
|
||||
ADWaitPool.redirect(task, newHold.markerId)
|
||||
task.activatedUALLoading = false
|
||||
end
|
||||
return true
|
||||
end
|
||||
@@ -384,7 +466,8 @@ local function updateSpawn(adEnv, state, task, source, dt)
|
||||
if spawn.pending ~= nil then
|
||||
spawn.pending.ms = spawn.pending.ms + (dt or 0)
|
||||
local stored, loaded = ADSources.countStored(source, fillType), countLoaded(task.trailers)
|
||||
if stored < spawn.pending.stored and loaded > spawn.pending.loaded then
|
||||
local level = adEnv.AutoDrive.getAllFillLevels(task.trailers) or 0
|
||||
if stored < spawn.pending.stored and (loaded > spawn.pending.loaded or level > spawn.pending.level) then
|
||||
spawn.pending = nil
|
||||
elseif spawn.pending.ms > ADOutbound.SPAWN_STALL_MS then
|
||||
warnOnce(adEnv, vehicle, "spawn", string.format("'%s': objektlageret %s spawner ikke %s (30 s uden fremdrift); kører med det der er", tostring(vehicle:getName()), tostring(source.name), fillTypeName(fillType)))
|
||||
@@ -411,7 +494,7 @@ local function updateSpawn(adEnv, state, task, source, dt)
|
||||
end
|
||||
end
|
||||
if ADSources.spawnOne(source, index) then
|
||||
spawn.pending = {stored = ADSources.countStored(source, fillType), loaded = countLoaded(task.trailers), ms = 0}
|
||||
spawn.pending = {stored = ADSources.countStored(source, fillType), loaded = countLoaded(task.trailers), level = adEnv.AutoDrive.getAllFillLevels(task.trailers) or 0, ms = 0}
|
||||
else
|
||||
warnOnce(adEnv, vehicle, "spawn", string.format("'%s': kunne ikke tage %s ud af %s; kører med det der er", tostring(vehicle:getName()), fillTypeName(fillType), tostring(source.name)))
|
||||
state.done = true
|
||||
@@ -445,6 +528,16 @@ function ADOutbound.beforeLoadUpdate(adEnv, task, dt)
|
||||
state.noProgressMs = state.noProgressMs + (dt or 0)
|
||||
end
|
||||
local spawnPending = state.spawn ~= nil and state.spawn.pending ~= nil
|
||||
if level <= 0 and state.noProgressMs > ADOutbound.EMPTY_SOURCE_MS and not spawnPending then
|
||||
local expires = now() + ADOutbound.EMPTY_SOURCE_TTL_MS
|
||||
for _, fillType in ipairs(state.trip.fillTypes) do
|
||||
emptyUntil[tostring(state.current) .. ":" .. tostring(fillType)] = expires
|
||||
end
|
||||
Logging.warning(ADOutbound.LOG_PREFIX .. "'%s': intet at læsse ved %s efter %d s; kilden springes over i %d min", tostring(vehicle:getName()), tostring(source ~= nil and source.name or state.current), math.floor(ADOutbound.EMPTY_SOURCE_MS / 1000), math.floor(ADOutbound.EMPTY_SOURCE_TTL_MS / 60000))
|
||||
state.noProgressMs, state.completed = 0, true
|
||||
task:finished()
|
||||
return true
|
||||
end
|
||||
if state.noProgressMs > ADOutbound.NO_PROGRESS_MS and level > 0 and not spawnPending then
|
||||
Logging.info(ADOutbound.LOG_PREFIX .. "'%s': ingen mere last ved %s; kører med %.0f l", tostring(vehicle:getName()), tostring(source ~= nil and source.name or state.current), level)
|
||||
state.noProgressMs, state.completed = 0, true
|
||||
|
||||
@@ -357,6 +357,18 @@ local function getOutboundFillTypes(adEnv, run, vehicle)
|
||||
return result, chosen, palletCount, canLoadPallets
|
||||
end
|
||||
|
||||
-- Last på vognen ved Start: nil = tom vogn, waypoint-id = mål for lasten, false = intet mål.
|
||||
local function getCargoTarget(adEnv, run, vehicle)
|
||||
if ADUnloadWait == nil or ADUnloadWait.getRestLoad == nil or ADOutbound == nil or ADOutbound.planCargoTarget == nil then
|
||||
return nil
|
||||
end
|
||||
local fillType, liters = ADUnloadWait.getRestLoad(adEnv, vehicle)
|
||||
if fillType == nil or liters < 100 then
|
||||
return nil
|
||||
end
|
||||
return ADOutbound.planCargoTarget(adEnv, run, vehicle, fillType, liters) or false
|
||||
end
|
||||
|
||||
local function validateOutboundVehicle(adEnv, run, vehicle, result)
|
||||
if #getRunSources(adEnv, run, ADSmartPickup.getFarmId(vehicle)) == 0 then
|
||||
result.reason = "noSource"
|
||||
@@ -375,6 +387,15 @@ local function validateOutboundVehicle(adEnv, run, vehicle, result)
|
||||
result.reason = (palletCount == chosen and not canLoadPallets) and "needsAutoload" or "cannotCarry"
|
||||
return result
|
||||
end
|
||||
-- Uden Wait-punkt ville traktoren holde ved kilden og læsse selv om planlæggeren sagde "vent".
|
||||
if ADWaitPool ~= nil and #ADWaitPool.getCandidates(adEnv, run.waitPoolGroup) == 0 then
|
||||
result.reason = "noWaitPoint"
|
||||
return result
|
||||
end
|
||||
if getCargoTarget(adEnv, run, vehicle) == false then
|
||||
result.reason = "cargoNoTarget"
|
||||
return result
|
||||
end
|
||||
if isFarFromNetwork(adEnv, vehicle) then
|
||||
result.reason = "farFromNetwork"
|
||||
return result
|
||||
@@ -523,7 +544,9 @@ local function applyOutboundRunToVehicle(adEnv, run, vehicle)
|
||||
stateModule:setMode(adEnv.AutoDrive.MODE_PICKUPANDDELIVER)
|
||||
local firstId = run.sourceWayPointIds[1]
|
||||
stateModule:setFirstMarkerByWayPointId(firstId)
|
||||
stateModule:setSecondMarkerByWayPointId(firstId)
|
||||
-- Læsset vogn: AD kører først til aflæsning (2. markør) — dér skal lastens mål stå.
|
||||
local cargoTarget = getCargoTarget(adEnv, run, vehicle)
|
||||
stateModule:setSecondMarkerByWayPointId(cargoTarget or firstId)
|
||||
local fillTypes = getOutboundFillTypes(adEnv, run, vehicle)
|
||||
stateModule.selectedFillTypes = copyList(fillTypes)
|
||||
if fillTypes[1] ~= nil then
|
||||
|
||||
@@ -34,24 +34,68 @@ local function getPlaceableName(placeable, fallback)
|
||||
return fallback
|
||||
end
|
||||
|
||||
-- Pallevarer har en pallefil i spillets fillType-definition (halmkurve, mel, brød ...).
|
||||
-- Varer der KAN stå på paller (spillets fillType-definition: isPalletType eller pallefil).
|
||||
-- Sukker og mel er palletyper, men læsses som bulk ved en fabrik med læssestation — så om
|
||||
-- varen er palle eller bulk afgøres pr. kilde i isPalletAt, ikke her.
|
||||
function ADSources.isPalletFillType(fillType)
|
||||
local desc = g_fillTypeManager ~= nil and g_fillTypeManager.getFillTypeByIndex ~= nil and g_fillTypeManager:getFillTypeByIndex(fillType) or nil
|
||||
return desc ~= nil and desc.palletFilename ~= nil
|
||||
return desc ~= nil and (desc.isPalletType == true or desc.palletFilename ~= nil)
|
||||
end
|
||||
|
||||
local function stationSupports(station, fillType)
|
||||
if station == nil then
|
||||
return false
|
||||
end
|
||||
if station.supportedFillTypes ~= nil then
|
||||
return station.supportedFillTypes[fillType] == true
|
||||
end
|
||||
if station.getIsFillTypeSupported ~= nil then
|
||||
local ok, value = pcall(station.getIsFillTypeSupported, station, fillType)
|
||||
return ok and value == true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Palle eller bulk ved DENNE kilde: silo = bulk; objektlager = palle; fabrik = bulk hvis
|
||||
-- markørens læssestation udleverer varen, ellers palle hvis varen er en palletype.
|
||||
function ADSources.isPalletAt(source, fillType)
|
||||
if source.kind == "silo" then
|
||||
return false
|
||||
elseif source.kind == "objectStorage" then
|
||||
return true
|
||||
end
|
||||
if stationSupports(source.station, fillType) then
|
||||
return false
|
||||
end
|
||||
return ADSources.isPalletFillType(fillType)
|
||||
end
|
||||
|
||||
local function getProductionPoint(placeable)
|
||||
return placeable ~= nil and placeable.spec_productionPoint ~= nil and placeable.spec_productionPoint.productionPoint or nil
|
||||
end
|
||||
|
||||
-- Nærmeste objektlager inden for MAX_DISTANCE af waypointet, som farmen må bruge.
|
||||
local function findObjectStorageNear(wayPoint, farmId)
|
||||
-- Placeable'ns "nærmeste punkt" for kildegenkendelse: pallespawnerens første plads (fabrik)
|
||||
-- eller rodnoden.
|
||||
local function getPlaceableAnchor(placeable)
|
||||
local productionPoint = getProductionPoint(placeable)
|
||||
local spawner = productionPoint ~= nil and productionPoint.palletSpawner or nil
|
||||
local place = spawner ~= nil and spawner.spawnPlaces ~= nil and spawner.spawnPlaces[1] or nil
|
||||
local node = place ~= nil and place.startNode or placeable.rootNode
|
||||
local x, z = getNodePosition(node)
|
||||
if x == nil and node ~= placeable.rootNode then
|
||||
x, z = getNodePosition(placeable.rootNode)
|
||||
end
|
||||
return x, z
|
||||
end
|
||||
|
||||
-- Nærmeste placeable inden for MAX_DISTANCE af waypointet som farmen må bruge og predicate godkender.
|
||||
local function findPlaceableNear(wayPoint, farmId, predicate)
|
||||
local placeables = g_currentMission ~= nil and g_currentMission.placeableSystem ~= nil and g_currentMission.placeableSystem.placeables or {}
|
||||
local access = g_currentMission ~= nil and g_currentMission.accessHandler or nil
|
||||
local best, bestDistance = nil, ADSources.MAX_DISTANCE * ADSources.MAX_DISTANCE
|
||||
for _, placeable in pairs(placeables) do
|
||||
if placeable.spec_objectStorage ~= nil and (access == nil or access:canFarmAccess(farmId, placeable)) then
|
||||
local x, z = getNodePosition(placeable.rootNode)
|
||||
if predicate(placeable) and (access == nil or access:canFarmAccess(farmId, placeable)) then
|
||||
local x, z = getPlaceableAnchor(placeable)
|
||||
if x ~= nil then
|
||||
local d = distance2(wayPoint.x, wayPoint.z, x, z)
|
||||
if d < bestDistance then
|
||||
@@ -63,6 +107,14 @@ local function findObjectStorageNear(wayPoint, farmId)
|
||||
return best
|
||||
end
|
||||
|
||||
local function isObjectStorage(placeable)
|
||||
return placeable.spec_objectStorage ~= nil
|
||||
end
|
||||
|
||||
local function isProductionPoint(placeable)
|
||||
return getProductionPoint(placeable) ~= nil
|
||||
end
|
||||
|
||||
-- {kind = "factory"|"silo"|"objectStorage", placeable, station|nil, wayPointId, name} eller nil.
|
||||
function ADSources.identify(adEnv, wayPointId, farmId)
|
||||
local wayPoint = adEnv.ADGraphManager:getWayPointById(wayPointId)
|
||||
@@ -79,7 +131,13 @@ function ADSources.identify(adEnv, wayPointId, farmId)
|
||||
if placeable ~= nil and placeable.spec_silo ~= nil then
|
||||
return {kind = "silo", placeable = placeable, station = station, wayPointId = wayPointId, name = getPlaceableName(placeable, markerName)}
|
||||
end
|
||||
local storage = findObjectStorageNear(wayPoint, farmId)
|
||||
-- Rene pallefabrikker (halmvarer, bageri ...) har ingen læssestation: find dem på afstand
|
||||
-- til pallespawneren; dernæst objektlagre.
|
||||
local factory = findPlaceableNear(wayPoint, farmId, isProductionPoint)
|
||||
if factory ~= nil then
|
||||
return {kind = "factory", placeable = factory, station = nil, wayPointId = wayPointId, name = getPlaceableName(factory, markerName)}
|
||||
end
|
||||
local storage = findPlaceableNear(wayPoint, farmId, isObjectStorage)
|
||||
if storage ~= nil then
|
||||
return {kind = "objectStorage", placeable = storage, station = nil, wayPointId = wayPointId, name = getPlaceableName(storage, markerName)}
|
||||
end
|
||||
@@ -143,7 +201,7 @@ local function getFactoryProducts(source, farmId)
|
||||
seen[fillType] = true
|
||||
local level = storage ~= nil and storage.getFillLevel ~= nil and (storage:getFillLevel(fillType) or 0) or 0
|
||||
local capacity = storage ~= nil and storage.getCapacity ~= nil and (storage:getCapacity(fillType) or 0) or 0
|
||||
local isPallet = ADSources.isPalletFillType(fillType)
|
||||
local isPallet = ADSources.isPalletAt(source, fillType)
|
||||
local available = level + (isPallet and getPalletsNearSpawner(source.placeable, fillType, farmId) or 0)
|
||||
table.insert(products, newProduct(fillType, available, level, capacity, isPallet))
|
||||
end
|
||||
@@ -165,7 +223,7 @@ local function getSiloProducts(source)
|
||||
end
|
||||
local products = {}
|
||||
for fillType, level in pairs(levels) do
|
||||
table.insert(products, newProduct(fillType, level, level, capacities[fillType] or 0, ADSources.isPalletFillType(fillType)))
|
||||
table.insert(products, newProduct(fillType, level, level, capacities[fillType] or 0, false))
|
||||
end
|
||||
table.sort(products, function(a, b) return a.fillType < b.fillType end)
|
||||
return products
|
||||
|
||||
@@ -5,12 +5,24 @@
|
||||
|
||||
-- Bedste pris-% for varen over alle salgssteder (uanset vejnet — det er til visning; turen
|
||||
-- bruger kun nåelige). {percent, stationName} eller nil.
|
||||
SmartPickupFrame.SELL_MARKERS_CACHE_MS = 30000
|
||||
|
||||
-- Salgsstederne slås op over alle markører × stationer; cachet, så det ikke sker pr. vare pr. sekund.
|
||||
function SmartPickupFrame:getSellMarkersCached(adEnv)
|
||||
local time = g_time or (os.clock ~= nil and os.clock() * 1000) or 0
|
||||
if self.sellMarkersCache == nil or (time - (self.sellMarkersCacheTime or 0)) > SmartPickupFrame.SELL_MARKERS_CACHE_MS then
|
||||
self.sellMarkersCache = ADSources.getSellMarkers(adEnv, g_currentMission:getFarmId())
|
||||
self.sellMarkersCacheTime = time
|
||||
end
|
||||
return self.sellMarkersCache
|
||||
end
|
||||
|
||||
function SmartPickupFrame:getProductQuote(adEnv, fillType)
|
||||
if ADSources == nil or ADPrices == nil then
|
||||
return nil
|
||||
end
|
||||
local best = nil
|
||||
for _, entry in ipairs(ADSources.getSellMarkers(adEnv, g_currentMission:getFarmId())) do
|
||||
for _, entry in ipairs(self:getSellMarkersCached(adEnv)) do
|
||||
if ADSources.stationAccepts(entry.station, fillType) then
|
||||
local quote = ADPrices.getQuote(entry.station, fillType)
|
||||
if quote ~= nil and (best == nil or quote.percent > best.percent) then
|
||||
@@ -31,8 +43,15 @@ function SmartPickupFrame:describeProduct(adEnv, product)
|
||||
return string.format(self.i18n:getText("spu_product_row"), tostring(product.title), SmartPickupFrame.formatCompact(product.available or 0), price)
|
||||
end
|
||||
|
||||
function SmartPickupFrame:getPolicyIndex(policy)
|
||||
for index, name in ipairs(SmartPickupFrame.POLICIES) do
|
||||
-- Paller kan ikke lagres i en silo: kun Fra/Salg for pallevarer.
|
||||
SmartPickupFrame.PALLET_POLICIES = {"off", "sell"}
|
||||
|
||||
function SmartPickupFrame.getPoliciesFor(product)
|
||||
return product.isPallet and SmartPickupFrame.PALLET_POLICIES or SmartPickupFrame.POLICIES
|
||||
end
|
||||
|
||||
function SmartPickupFrame.getPolicyIndex(policies, policy)
|
||||
for index, name in ipairs(policies) do
|
||||
if name == policy then
|
||||
return index
|
||||
end
|
||||
@@ -59,16 +78,17 @@ end
|
||||
|
||||
function SmartPickupFrame:fillProductRows(adEnv, run)
|
||||
self.productRows = {}
|
||||
local policyTexts = {}
|
||||
for _, policy in ipairs(SmartPickupFrame.POLICIES) do
|
||||
table.insert(policyTexts, self.i18n:getText("spu_policy_" .. policy))
|
||||
end
|
||||
local products = ADRunsController.getRunProducts(adEnv, run)
|
||||
for _, product in ipairs(products) do
|
||||
local row = self:addRow(self.productPrefab, {kind = "product", name = product.name})
|
||||
local policies = SmartPickupFrame.getPoliciesFor(product)
|
||||
local policyTexts = {}
|
||||
for _, policy in ipairs(policies) do
|
||||
table.insert(policyTexts, self.i18n:getText("spu_policy_" .. policy))
|
||||
end
|
||||
local row = self:addRow(self.productPrefab, {kind = "product", name = product.name, policies = policies})
|
||||
local option = row:getDescendantByName("option")
|
||||
option:setTexts(policyTexts)
|
||||
option:setState(self:getPolicyIndex(product.policy), false)
|
||||
option:setState(SmartPickupFrame.getPolicyIndex(policies, product.policy), false)
|
||||
local title = row:getDescendantByName("title")
|
||||
title:setText(self:describeProduct(adEnv, product))
|
||||
table.insert(self.productRows, {name = product.name, title = title, option = option})
|
||||
@@ -163,7 +183,7 @@ function SmartPickupFrame:onClickProduct(state, element)
|
||||
self:safe(function(frame)
|
||||
local run, data = frame:getRun(), frame.rowData[element]
|
||||
if run == nil or data == nil or data.kind ~= "product" then return end
|
||||
local policy = SmartPickupFrame.POLICIES[state] or "off"
|
||||
local policy = (data.policies or SmartPickupFrame.POLICIES)[state] or "off"
|
||||
ADRunsController.store = ADRuns.setProductPolicy(ADRunsController.store, run.id, data.name, policy)
|
||||
Logging.info(SmartPickupFrame.LOG_PREFIX .. "run '%s': %s=%s", tostring(run.name), tostring(data.name), policy)
|
||||
end)
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
<text name="spu_noProducts" text="Kilderne har ingen varer endnu"/>
|
||||
<text name="spu_reason_noSource" text="ingen genkendt kilde"/>
|
||||
<text name="spu_reason_noProducts" text="ingen vare valgt"/>
|
||||
<text name="spu_reason_noWaitPoint" text="intet Wait-punkt i puljen (markør i en mappe med 'Wait' i navnet)"/>
|
||||
<text name="spu_reason_cargoNoTarget" text="lasten på vognen har intet mål (pris for lav / ingen silo) — tøm vognen"/>
|
||||
<text name="spu_reason_needsAutoload" text="pallevarer kræver Universal Autoload på vognen"/>
|
||||
<text name="spu_product_row" text="%s — %s l — %s"/>
|
||||
<text name="spu_price_pct" text="%d %% af top (%s)"/>
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
<text name="spu_noProducts" text="The sources hold no goods yet"/>
|
||||
<text name="spu_reason_noSource" text="no recognised source"/>
|
||||
<text name="spu_reason_noProducts" text="no good selected"/>
|
||||
<text name="spu_reason_noWaitPoint" text="no Wait point in the pool (marker in a folder with 'Wait' in its name)"/>
|
||||
<text name="spu_reason_cargoNoTarget" text="the load on the trailer has no destination (price too low / no silo) — empty the trailer"/>
|
||||
<text name="spu_reason_needsAutoload" text="pallet goods need Universal Autoload on the trailer"/>
|
||||
<text name="spu_product_row" text="%s — %s l — %s"/>
|
||||
<text name="spu_price_pct" text="%d %% of top (%s)"/>
|
||||
|
||||
Reference in New Issue
Block a user