fix: siloens læssemarkør = den tættest på triggeren (v1.62.130)
This commit is contained in:
@@ -386,19 +386,45 @@ local function unloadMarkerFor(adEnv, nodes, loadMarkers, allowSkipLoad)
|
||||
return {id = chosen.marker.id, name = tostring(chosen.marker.name), distance = math.floor(chosen.distance + 0.5)}
|
||||
end
|
||||
|
||||
-- Afstand fra et punkt til stationens nærmeste læssetrigger (0 når stationen ingen kendte triggere har).
|
||||
local function stationTriggerDistance(station, x, z)
|
||||
local best = nil
|
||||
for _, trigger in pairs(station.loadTriggers or {}) do
|
||||
local node = trigger.triggerNode or trigger.aiNode
|
||||
local tx, tz = nil, nil
|
||||
if node ~= nil then tx, tz = getNodePosition(node) end
|
||||
if tx ~= nil then
|
||||
local d = math.sqrt((tx - x) ^ 2 + (tz - z) ^ 2)
|
||||
if best == nil or d < best then best = d end
|
||||
end
|
||||
end
|
||||
return best or 0
|
||||
end
|
||||
|
||||
-- Den af to markør-træffere der står tættest på triggeren (ved lighed beholdes den første). a kan være nil.
|
||||
function ADBuildings.closerHit(a, b)
|
||||
if a == nil then return b end
|
||||
if b == nil then return a end
|
||||
return (b.distance or 0) < (a.distance or 0) and b or a
|
||||
end
|
||||
|
||||
-- Silo: den markør hvis STRENGE opslag (trigger bag næsen) rammer siloens læssestation.
|
||||
local function siloLoadMarker(adEnv, farmId, placeable, loadStations)
|
||||
local own = {}
|
||||
for _, station in pairs(loadStations) do
|
||||
if station.owningPlaceable == placeable then own[station] = true end
|
||||
end
|
||||
-- rammer flere markører stationen (AD's triggerafstand er stor, 25 m), vinder den der står tættest på
|
||||
-- læssetriggeren — ikke den tilfældigt første (in-game 9/10: marksiloen ved F9 fik markmarkøren 'F9' 19 m væk
|
||||
-- i stedet for 'F9 Silo' 11 m; vognen stod uden for boksen)
|
||||
local best = nil
|
||||
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do
|
||||
if not ADSupplyPlanner.isWaitMarker(marker) then
|
||||
local station = ADSmartPickup.getLoadStationAtWayPointId(adEnv, marker.id, farmId)
|
||||
if station ~= nil and own[station] then
|
||||
best = {id = marker.id, name = tostring(marker.name), distance = 0}
|
||||
break
|
||||
local wayPoint = adEnv.ADGraphManager:getWayPointById(marker.id)
|
||||
local distance = wayPoint ~= nil and stationTriggerDistance(station, wayPoint.x, wayPoint.z) or 0
|
||||
best = ADBuildings.closerHit(best, {id = marker.id, name = tostring(marker.name), distance = math.floor(distance + 0.5)})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.129.0</version>
|
||||
<version>1.62.130.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user