fix(markarbejde): påfyldning også ved købestationer (buyingStation, ingen lagerbeholdning) — 'Liquid Buy Station' blev aldrig fundet; markør inden for 30 m af trigger eller 40 m af bygningen (v1.29.3.0)
This commit is contained in:
@@ -387,26 +387,79 @@ end
|
|||||||
-- Nærmeste påfyldning af varen: en læssestation gården har adgang til, med varen på lager, en AutoDrive-
|
-- Nærmeste påfyldning af varen: en læssestation gården har adgang til, med varen på lager, en AutoDrive-
|
||||||
-- markør ved triggeren og vej fra traktoren. (AutoDrives eget "automatiske påfyldningsmål" er slået fra i
|
-- markør ved triggeren og vej fra traktoren. (AutoDrives eget "automatiske påfyldningsmål" er slået fra i
|
||||||
-- AutoDrive — AutoDrive.automaticPickupTarget = false — så vi finder stedet selv, som silovalget.)
|
-- AutoDrive — AutoDrive.automaticPickupTarget = false — så vi finder stedet selv, som silovalget.)
|
||||||
|
-- Sælger købestationen varen? (placeable.spec_buyingStation.buyingStation; FS25-felter varierer, så flere
|
||||||
|
-- opslag: udbudte varer, triggernes varer, AI-varer.)
|
||||||
|
function ADFieldWork.buyingSupports(station, fillType)
|
||||||
|
if station == nil or fillType == nil then return false end
|
||||||
|
local ok, result = pcall(function()
|
||||||
|
for _, key in ipairs({"providedFillTypes", "supportedFillTypes", "fillTypes"}) do
|
||||||
|
local set = station[key]
|
||||||
|
if type(set) == "table" and set[fillType] then return true end
|
||||||
|
end
|
||||||
|
for _, trigger in pairs(station.loadTriggers or {}) do
|
||||||
|
if type(trigger.fillTypes) == "table" and trigger.fillTypes[fillType] then return true end
|
||||||
|
end
|
||||||
|
if station.getAISupportedFillTypes ~= nil then
|
||||||
|
local set = station:getAISupportedFillTypes()
|
||||||
|
if type(set) == "table" and set[fillType] then return true end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end)
|
||||||
|
return ok and result == true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- AD-markøren ved stationen: AutoDrives eget opslag (30 m fra triggeren), ellers nærmeste ikke-Wait
|
||||||
|
-- markør inden for 40 m af bygningen ("Liquid Buy Station" står ved tanken, ikke ved triggeren).
|
||||||
|
local function markerAtStation(adEnv, vehicle, station, placeable)
|
||||||
|
local okAd, wayPointId = pcall(function() return adEnv.ADTriggerManager:getMarkerAtStation(station, vehicle, 30) end)
|
||||||
|
if okAd and wayPointId ~= nil and wayPointId > 0 then return wayPointId end
|
||||||
|
local node = placeable ~= nil and placeable.rootNode or nil
|
||||||
|
if node == nil then return nil end
|
||||||
|
local px, _, pz = getWorldTranslation(node)
|
||||||
|
local best, bestDistance = nil, 40 * 40
|
||||||
|
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do
|
||||||
|
local isWait = ADSupplyPlanner ~= nil and ADSupplyPlanner.isWaitMarker ~= nil and ADSupplyPlanner.isWaitMarker(marker)
|
||||||
|
local wayPoint = not isWait and adEnv.ADGraphManager:getWayPointById(marker.id) or nil
|
||||||
|
if wayPoint ~= nil then
|
||||||
|
local d = (wayPoint.x - px) ^ 2 + (wayPoint.z - pz) ^ 2
|
||||||
|
if d < bestDistance then best, bestDistance = marker.id, d end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return best
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Nærmeste påfyldning af varen med AD-markør og vej: lagre/siloer med varen, og købestationer (købes
|
||||||
|
-- efter behov — ingen lagerbeholdning, så de fandtes ikke før; in-game 26/9 "Liquid Buy Station").
|
||||||
function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z)
|
function ADFieldWork.findRefillMarker(adEnv, vehicle, fillType, x, z)
|
||||||
local farmId = vehicle:getOwnerFarmId()
|
local farmId = vehicle:getOwnerFarmId()
|
||||||
local best, bestDistance = nil, math.huge
|
local best, bestDistance = nil, math.huge
|
||||||
local ok = pcall(function()
|
local function consider(wayPointId)
|
||||||
|
local wayPoint = wayPointId ~= nil and wayPointId > 0 and adEnv.ADGraphManager:getWayPointById(wayPointId) or nil
|
||||||
|
if wayPoint == nil then return end
|
||||||
|
local distance = (wayPoint.x - x) ^ 2 + (wayPoint.z - z) ^ 2
|
||||||
|
if distance < bestDistance and ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId) then
|
||||||
|
best, bestDistance = wayPointId, distance
|
||||||
|
end
|
||||||
|
end
|
||||||
|
pcall(function()
|
||||||
for _, station in pairs(g_currentMission.storageSystem:getLoadingStations()) do
|
for _, station in pairs(g_currentMission.storageSystem:getLoadingStations()) do
|
||||||
local supported = station.getAISupportedFillTypes ~= nil and station:getAISupportedFillTypes() or {}
|
local supported = station.getAISupportedFillTypes ~= nil and station:getAISupportedFillTypes() or {}
|
||||||
if g_currentMission.accessHandler:canFarmAccess(farmId, station) and supported[fillType]
|
if g_currentMission.accessHandler:canFarmAccess(farmId, station) and supported[fillType]
|
||||||
and (station:getFillLevel(fillType, farmId) or 0) > 0 then
|
and (station:getFillLevel(fillType, farmId) or 0) > 0 then
|
||||||
local wayPointId = adEnv.ADTriggerManager:getMarkerAtStation(station, vehicle, 10)
|
consider(markerAtStation(adEnv, vehicle, station, station.owningPlaceable))
|
||||||
local wayPoint = wayPointId ~= nil and wayPointId > 0 and adEnv.ADGraphManager:getWayPointById(wayPointId) or nil
|
|
||||||
if wayPoint ~= nil then
|
|
||||||
local distance = (wayPoint.x - x) ^ 2 + (wayPoint.z - z) ^ 2
|
|
||||||
if distance < bestDistance and ADUnloadWait.hasRouteTo(adEnv, vehicle, wayPointId) then
|
|
||||||
best, bestDistance = wayPointId, distance
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
return ok and best or nil
|
pcall(function()
|
||||||
|
for _, placeable in pairs(g_currentMission.placeableSystem.placeables) do
|
||||||
|
local spec = placeable.spec_buyingStation
|
||||||
|
local station = spec ~= nil and spec.buyingStation or nil
|
||||||
|
if station ~= nil and ADFieldWork.buyingSupports(station, fillType) then
|
||||||
|
consider(markerAtStation(adEnv, vehicle, station, placeable))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
return best
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Påfyldning undervejs (såmaskine/sprøjte/spreder): AutoDrive LOAD med hjælper = Courseplay. Når CP melder
|
-- Påfyldning undervejs (såmaskine/sprøjte/spreder): AutoDrive LOAD med hjælper = Courseplay. Når CP melder
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
<modDesc descVersion="107">
|
<modDesc descVersion="107">
|
||||||
<author>masterdraco</author>
|
<author>masterdraco</author>
|
||||||
<version>1.29.2.0</version>
|
<version>1.29.3.0</version>
|
||||||
<title>
|
<title>
|
||||||
<en>AD Smart Pickup</en>
|
<en>AD Smart Pickup</en>
|
||||||
</title>
|
</title>
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
-- Kør: luajit tests/test_adFieldWorkBuying.lua (fra repo-roden)
|
||||||
|
-- Påfyldning ved købestation (in-game 26/9: "Liquid Buy Station", FarmFillStations buyingStationConfigurable):
|
||||||
|
-- ingen lagerbeholdning, så varen læses fra udbud/triggere/AI-varer.
|
||||||
|
local failures = 0
|
||||||
|
local function check(name, actual, expected)
|
||||||
|
if actual == expected then print("OK " .. name) else
|
||||||
|
failures = failures + 1
|
||||||
|
print(string.format("FAIL %s: forventede %s, fik %s", name, tostring(expected), tostring(actual)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Logging = {info = function() end, warning = function() end}
|
||||||
|
dofile("FS25_ADSmartPickup/adFieldWork.lua")
|
||||||
|
local HERBICIDE, LIME, SEEDS = 20, 21, 22
|
||||||
|
local W = ADFieldWork
|
||||||
|
check("BS1 udbudte varer", W.buyingSupports({providedFillTypes = {[HERBICIDE] = true}}, HERBICIDE), true)
|
||||||
|
check("BS2 triggerens varer", W.buyingSupports({loadTriggers = {{fillTypes = {[HERBICIDE] = true}}}}, HERBICIDE), true)
|
||||||
|
check("BS3 AI-varer", W.buyingSupports({getAISupportedFillTypes = function() return {[SEEDS] = true} end}, SEEDS), true)
|
||||||
|
check("BS4 sælger ikke kalk", W.buyingSupports({providedFillTypes = {[HERBICIDE] = true}}, LIME), false)
|
||||||
|
check("BS5 fejl i opslag = nej", W.buyingSupports({getAISupportedFillTypes = function() error("x") end}, LIME), false)
|
||||||
|
check("BS6 ingen station", W.buyingSupports(nil, LIME), false)
|
||||||
|
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
|
||||||
|
os.exit(failures == 0 and 0 or 1)
|
||||||
Reference in New Issue
Block a user