fix: paller til palleskur køres til unload-markøren frem for load (v1.62.57)

This commit is contained in:
2026-10-07 17:05:00 +02:00
parent 6761babc8c
commit ab47ac70b3
3 changed files with 18 additions and 2 deletions
+16 -1
View File
@@ -760,7 +760,22 @@ function ADSources.findPalletStore(adEnv, vehicle, fillType, excludedPlaceables,
table.insert(candidates, {marker = marker, source = source, distance = distance2(x, z, wayPoint.x, wayPoint.z)})
end
end
table.sort(candidates, function(a, b) return a.distance < b.distance end)
-- nærmeste skur først; ved samme skur går en "unload"-markør forud for "load" (in-game 7/10: Pallebil 1 kørte æg
-- til "Palleskur 1 load", der lå nærmest)
local nearestOf = {}
for _, candidate in ipairs(candidates) do
local placeable = candidate.source.placeable
nearestOf[placeable] = math.min(nearestOf[placeable] or math.huge, candidate.distance)
end
local function isUnload(candidate)
return ADBuildings ~= nil and ADBuildings.nameRole ~= nil and ADBuildings.nameRole(candidate.marker.name) == "unload"
end
table.sort(candidates, function(a, b)
local da, db = nearestOf[a.source.placeable], nearestOf[b.source.placeable]
if da ~= db then return da < db end
if isUnload(a) ~= isUnload(b) then return isUnload(a) end
return a.distance < b.distance
end)
for _, candidate in ipairs(candidates) do
if isReachable == nil or isReachable(candidate.marker.id) then
return {wayPointId = candidate.marker.id, name = tostring(candidate.marker.name), free = ADSources.objectStorageFreeSlots(candidate.source.placeable)}