fix: salgsmarkør uden P/Connect/Wait og fremmede bygningers markører; breddevagt måler aktive sektioner (v1.62.59)

This commit is contained in:
2026-10-07 19:15:43 +02:00
parent dd434a2fc1
commit e8e742faaa
5 changed files with 130 additions and 25 deletions
+72 -17
View File
@@ -654,41 +654,94 @@ function ADSources.getSellMarkers(adEnv, farmId)
return cacheGet("sellMarkers", tostring(farmId), 10000, function() return ADSources.findSellMarkers(adEnv, farmId) end)
end
-- entries = {{marker, station, through}} -> samme liste, men har en station flere markører, beholdes kun dem
-- hvis AD-vej kører gennem stationens trigger (findes nogen). In-game 6/10: mælkebilerne solgte ved væske-
-- markedet via "Palleskur 2 load" på nabosporet (lavere waypoint-id end "Buy All") og holdt ved palleskuret.
-- Lag pr. salgsmarkør: AD-vej gennem stationens trigger (2) > almindelig markør (1) > en anden bygnings læsse-/
-- aflæsningsmarkør (0, fx "Palleskur 2 load" på nabosporet).
local function markerTier(entry)
if entry.through then return 2 end
return entry.foreign and 0 or 1
end
-- entries = {{marker, station, through, foreign}} -> samme liste, men pr. station kun markørerne i det bedste lag.
-- In-game 6/10: mælkebilerne solgte ved væskemarkedet via "Palleskur 2 load" (lavere waypoint-id end "Buy All")
-- og holdt ved palleskuret.
function ADSources.pickStationMarkers(entries)
local hasThrough = {}
local best = {}
for _, entry in ipairs(entries) do
if entry.through then hasThrough[entry.station] = true end
best[entry.station] = math.max(best[entry.station] or 0, markerTier(entry))
end
local result = {}
for _, entry in ipairs(entries) do
if entry.through or not hasThrough[entry.station] then table.insert(result, entry) end
if markerTier(entry) == best[entry.station] then table.insert(result, entry) end
end
return result
end
local function isServiceMarker(marker)
return ADFieldWork ~= nil and ADFieldWork.isServiceMarker ~= nil and ADFieldWork.isServiceMarker(marker) == true
end
-- Andre (ikke-salgs) bygningers læsse- og aflæsningsmarkører (palleskur, silo, stald, fabrik): {[waypoint-id] = true}.
local function foreignMarkerIds(adEnv, farmId)
local ids = {}
if ADBuildings == nil or ADBuildings.list == nil then return ids end
local ok, buildings = pcall(ADBuildings.list, adEnv, farmId)
for _, building in ipairs(ok and buildings or {}) do
if building.kind ~= "sell" then
for _, marker in ipairs(building.loadMarkers or {}) do ids[marker.id] = true end
if building.unloadMarker ~= nil then ids[building.unloadMarker.id] = true end
end
end
return ids
end
function ADSources.findSellMarkers(adEnv, farmId)
local entries = {}
local foreign = foreignMarkerIds(adEnv, farmId)
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do
local station = ADSmartPickup.getUnloadStationAtWayPointId(adEnv, marker.id, farmId)
-- parkering/kobling/Wait er aldrig et salgssted (in-game 7/10: gylle solgt ved "Connect P Tippevogn 2")
local station = not isServiceMarker(marker) and ADSmartPickup.getUnloadStationAtWayPointId(adEnv, marker.id, farmId) or nil
if station ~= nil and ADPrices.isSellingStation(station) and not ADSources.isSellBlocked(station) then
local okThrough, through = pcall(function()
return ADFieldWork.drivesThrough({approach = ADFieldWork.approachPoints(adEnv, marker.id)},
ADSmartPickup.unloadTriggerPoints(station))
end)
table.insert(entries, {marker = marker, station = station, through = okThrough and through == true})
table.insert(entries, {marker = marker, station = station, through = okThrough and through == true,
foreign = foreign[marker.id] == true})
end
end
return ADSources.pickStationMarkers(ADSources.addThroughMarkers(adEnv, entries))
local picked = ADSources.pickStationMarkers(ADSources.addStationMarkers(adEnv, foreign, entries))
pcall(ADSources.logSellMarkers, picked)
return picked
end
-- Markør->station giver hver markør kun den nærmeste station. Kører en anden markørs AD-vej gennem stationens
-- trigger, kommer den med for stationen (pickStationMarkers dropper så dem der ikke gør). In-game 7/10: "Buy All"
-- kører gennem både væske- og bulkmarkedet, men var kun bulkmarkedets -> gyllen skulle sælges ved "Palleskur 2 load".
function ADSources.addThroughMarkers(adEnv, entries)
if ADFieldWork == nil or ADFieldWork.throughMarkerAt == nil then
-- Loggen: salgsstedets valgte markør(er), kun når valget ændrer sig (salgsmarkørerne genberegnes hvert 10. s).
local loggedSellMarkers = {}
function ADSources.logSellMarkers(entries)
local byStation, order = {}, {}
for _, entry in ipairs(entries) do
if byStation[entry.station] == nil then byStation[entry.station] = {}; table.insert(order, entry.station) end
local tag = entry.through and "gennem trigger" or (entry.foreign and "anden bygnings" or "nærmest")
table.insert(byStation[entry.station], string.format("%s (%s)", tostring(entry.marker.name), tag))
end
for _, station in ipairs(order) do
local okName, name = pcall(function() return station.getName ~= nil and station:getName() or nil end)
local key = tostring(okName and name or station)
local text = table.concat(byStation[station], ", ")
if loggedSellMarkers[key] ~= text then
loggedSellMarkers[key] = text
if Logging ~= nil and Logging.info ~= nil then
Logging.info("ADSmartPickup: salgssted '%s' -> %s", key, text)
end
end
end
end
-- Markør->station giver hver markør kun den nærmeste station. Derfor slås stationens egen markør også op fra
-- stationen: den der kører gennem triggeren, ellers den nærmeste der ikke er en anden bygnings eller en
-- parkering/kobling (pickStationMarkers vælger så laget). In-game 7/10: "Buy All" blev kun bulkmarkedets, og
-- senere vandt "Connect P Tippevogn 2" over spillerens nye "Liquid Buy" ved væsketanken.
function ADSources.addStationMarkers(adEnv, foreign, entries)
if ADFieldWork == nil or ADFieldWork.stationMarkerAt == nil then
return entries
end
local byStation, stations = {}, {}
@@ -699,17 +752,19 @@ function ADSources.addThroughMarkers(adEnv, entries)
end
byStation[entry.station][entry.marker.id] = entry
end
local accept = function(marker) return not isServiceMarker(marker) and not (foreign or {})[marker.id] end
local result = {}
for _, entry in ipairs(entries) do table.insert(result, entry) end
for _, station in ipairs(stations) do
local ok, id = pcall(ADFieldWork.throughMarkerAt, adEnv, ADSmartPickup.unloadTriggerPoints(station), ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE or 40)
local ok, id, through = pcall(ADFieldWork.stationMarkerAt, adEnv, ADSmartPickup.unloadTriggerPoints(station),
ADSmartPickup.MAX_MARKER_TO_TRIGGER_DISTANCE or 40, accept)
local marker = ok and id ~= nil and adEnv.ADGraphManager:getMapMarkerByWayPointId(id) or nil
if marker ~= nil then
local existing = byStation[station][id]
if existing ~= nil then
existing.through = true
existing.through = existing.through or through == true
else
table.insert(result, {marker = marker, station = station, through = true})
table.insert(result, {marker = marker, station = station, through = through == true, foreign = false})
end
end
end