fix: salgsmarkør skal køre gennem stationens trigger (v1.62.50)
This commit is contained in:
@@ -753,7 +753,7 @@ end
|
||||
ADFieldWork.THROUGH_TRIGGER_M = 3 -- AD-vejen før markøren kører gennem triggeren, hvis et punkt er så tæt på
|
||||
|
||||
-- Kører AD-vejen ind til markøren gennem en af triggerne? marker.approach = {{x, z}} (punkter bagud fra markøren).
|
||||
local function drivesThrough(marker, points)
|
||||
function ADFieldWork.drivesThrough(marker, points)
|
||||
local limit = ADFieldWork.THROUGH_TRIGGER_M ^ 2
|
||||
for _, p in ipairs(marker.approach or {}) do
|
||||
for _, point in ipairs(points) do
|
||||
@@ -777,7 +777,7 @@ function ADFieldWork.nearestStationMarker(markers, points, maxDistance)
|
||||
nearest = math.min(nearest, (marker.x - point.x) ^ 2 + (marker.z - point.z) ^ 2)
|
||||
end
|
||||
if nearest <= maxDistance * maxDistance then
|
||||
local through = drivesThrough(marker, points)
|
||||
local through = ADFieldWork.drivesThrough(marker, points)
|
||||
if (through and not bestThrough) or (through == bestThrough and nearest < bestDistance) then
|
||||
best, bestDistance, bestThrough = marker.id, nearest, through
|
||||
end
|
||||
@@ -805,7 +805,7 @@ end
|
||||
ADFieldWork.APPROACH_M = 40 -- så langt bagud ad AD-vejen ledes der efter triggeren
|
||||
|
||||
-- Punkterne AD kører igennem ind til markøren (bagud ad incoming, op til APPROACH_M).
|
||||
local function approachPoints(adEnv, startId)
|
||||
function ADFieldWork.approachPoints(adEnv, startId)
|
||||
local points, seen, queue = {}, {[startId] = true}, {{id = startId, d = 0}}
|
||||
local head = 1
|
||||
while head <= #queue and #points < 600 do
|
||||
@@ -841,7 +841,7 @@ local function markerList(adEnv, points, nearM)
|
||||
local entry = {id = marker.id, name = marker.name, group = marker.group, x = wayPoint.x, z = wayPoint.z}
|
||||
for _, point in ipairs(points or {}) do
|
||||
if (wayPoint.x - point.x) ^ 2 + (wayPoint.z - point.z) ^ 2 <= (nearM or 0) ^ 2 then
|
||||
entry.approach = approachPoints(adEnv, marker.id)
|
||||
entry.approach = ADFieldWork.approachPoints(adEnv, marker.id)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
@@ -227,6 +227,22 @@ local function getUnloadCandidates()
|
||||
return list
|
||||
end
|
||||
|
||||
-- Stationens aflæsningstriggere i verden -> {{x, z}}
|
||||
function ADSmartPickup.unloadTriggerPoints(station)
|
||||
local points = {}
|
||||
for _, trigger in pairs(station ~= nil and station.unloadTriggers or {}) do
|
||||
for _, field in ipairs(UNLOAD_TRIGGER_NODE_FIELDS) do
|
||||
local node = trigger[field]
|
||||
if node ~= nil and entityExists(node) then
|
||||
local x, _, z = getWorldTranslation(node)
|
||||
table.insert(points, {x = x, z = z})
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
return points
|
||||
end
|
||||
|
||||
local function getUnloadStationAtMarker(adEnv, wayPoint, farmId)
|
||||
return getClosestStation(adEnv, getUnloadCandidates(), "unloadTriggers", UNLOAD_TRIGGER_NODE_FIELDS, wayPoint, farmId)
|
||||
end
|
||||
|
||||
@@ -654,15 +654,34 @@ function ADSources.getSellMarkers(adEnv, farmId)
|
||||
return cacheGet("sellMarkers", tostring(farmId), 10000, function() return ADSources.findSellMarkers(adEnv, farmId) end)
|
||||
end
|
||||
|
||||
function ADSources.findSellMarkers(adEnv, farmId)
|
||||
-- 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.
|
||||
function ADSources.pickStationMarkers(entries)
|
||||
local hasThrough = {}
|
||||
for _, entry in ipairs(entries) do
|
||||
if entry.through then hasThrough[entry.station] = true end
|
||||
end
|
||||
local result = {}
|
||||
for _, entry in ipairs(entries) do
|
||||
if entry.through or not hasThrough[entry.station] then table.insert(result, entry) end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function ADSources.findSellMarkers(adEnv, farmId)
|
||||
local entries = {}
|
||||
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do
|
||||
local station = ADSmartPickup.getUnloadStationAtWayPointId(adEnv, marker.id, farmId)
|
||||
if station ~= nil and ADPrices.isSellingStation(station) and not ADSources.isSellBlocked(station) then
|
||||
table.insert(result, {marker = marker, station = station})
|
||||
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})
|
||||
end
|
||||
end
|
||||
return result
|
||||
return ADSources.pickStationMarkers(entries)
|
||||
end
|
||||
|
||||
-- ---- paller til lager: objektlager (palleskur) som mål ----
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.49.0</version>
|
||||
<version>1.62.50.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user