fix: stald-markør giver kun varerne fra sit eget læssepunkt (mælk vs. gylle i hver sin ende) (v1.13.4.0)

This commit is contained in:
2026-09-24 00:39:33 +02:00
parent 86b76f4ee1
commit 25332184a8
3 changed files with 59 additions and 6 deletions
+32 -3
View File
@@ -323,12 +323,41 @@ local function getObjectStorageProducts(source)
end end
-- Stald: det læssestationen udleverer (mælk, gylle ...) med staldens eget niveau/kapacitet. -- Stald: det læssestationen udleverer (mælk, gylle ...) med staldens eget niveau/kapacitet.
local function getHusbandryProducts(source) -- Varerne det læssepunkt udleverer som står nærmest markøren (en stald kan have mælk i den ene ende
-- og gylle i den anden på samme station). nil når punktet ikke opgiver sine varer.
local function getNearestTriggerFillTypes(adEnv, source)
local station = source.station
local wayPoint = adEnv.ADGraphManager:getWayPointById(source.wayPointId)
if station == nil or wayPoint == nil or station.loadTriggers == nil then
return nil
end
local best, bestDistance = nil, math.huge
for _, trigger in pairs(station.loadTriggers) do
local x, z = getNodePosition(trigger.triggerNode)
if x ~= nil then
local d = distance2(wayPoint.x, wayPoint.z, x, z)
if d < bestDistance then best, bestDistance = trigger, d end
end
end
if best == nil or type(best.fillTypes) ~= "table" or next(best.fillTypes) == nil then
return nil
end
local list = {}
for key, value in pairs(best.fillTypes) do
-- FS25 gemmer som sæt {[ft] = true}; nogle mods som liste {ft, ...}
if value == true then table.insert(list, key) elseif type(value) == "number" then table.insert(list, value) end
end
return #list > 0 and list or nil
end
local function getHusbandryProducts(adEnv, source)
local placeable, station = source.placeable, source.station local placeable, station = source.placeable, source.station
local fillTypes = {} local fillTypes = getNearestTriggerFillTypes(adEnv, source) or {}
if #fillTypes == 0 then
for fillType, supported in pairs(station ~= nil and station.supportedFillTypes or {}) do for fillType, supported in pairs(station ~= nil and station.supportedFillTypes or {}) do
if supported == true then table.insert(fillTypes, fillType) end if supported == true then table.insert(fillTypes, fillType) end
end end
end
if #fillTypes == 0 and station ~= nil and station.getIsFillTypeSupported ~= nil and g_fillTypeManager ~= nil then if #fillTypes == 0 and station ~= nil and station.getIsFillTypeSupported ~= nil and g_fillTypeManager ~= nil then
for _, name in ipairs({"MILK", "GOATMILK", "BUFFALOMILK", "SHEEPMILK", "LIQUIDMANURE", "MANURE", "DIGESTATE"}) do for _, name in ipairs({"MILK", "GOATMILK", "BUFFALOMILK", "SHEEPMILK", "LIQUIDMANURE", "MANURE", "DIGESTATE"}) do
local fillType = g_fillTypeManager.getFillTypeIndexByName ~= nil and g_fillTypeManager:getFillTypeIndexByName(name) or nil local fillType = g_fillTypeManager.getFillTypeIndexByName ~= nil and g_fillTypeManager:getFillTypeIndexByName(name) or nil
@@ -358,7 +387,7 @@ function ADSources.getProducts(adEnv, source, farmId)
elseif source.kind == "silo" then elseif source.kind == "silo" then
return getSiloProducts(source) return getSiloProducts(source)
elseif source.kind == "husbandry" then elseif source.kind == "husbandry" then
return getHusbandryProducts(source) return getHusbandryProducts(adEnv, source)
elseif source.kind == "objectStorage" then elseif source.kind == "objectStorage" then
return getObjectStorageProducts(source) return getObjectStorageProducts(source)
end end
+1 -1
View File
@@ -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.13.3.0</version> <version>1.13.4.0</version>
<title> <title>
<en>AD Smart Pickup</en> <en>AD Smart Pickup</en>
</title> </title>
+24
View File
@@ -359,5 +359,29 @@ looseAt[13] = siloStation
check("S16 silo aldrig via løst opslag", ADSources.identify(adEnv, 13, 1), nil) check("S16 silo aldrig via løst opslag", ADSources.identify(adEnv, 13, 1), nil)
check("S16 forklaring nævner den løse station", ADSources.explainMarker(adEnv, 13, 1):find("silo", 1, true) ~= nil, true) check("S16 forklaring nævner den løse station", ADSources.explainMarker(adEnv, 13, 1):find("silo", 1, true) ~= nil, true)
-- S17: stald med ÉN station og TO læssepunkter (mælk i den ene ende, gylle i den anden): hver markør
-- giver kun de varer dens nærmeste læssepunkt udleverer (in-game 24/9, LargerAnimalBarns cowBarnBig)
local SLURRY = 13
DESC[SLURRY] = {index = SLURRY, name = "LIQUIDMANURE", title = "Gylle"}
barnLevels[SLURRY] = 9000
local twoEndBarn = {
rootNode = {x = 2500, z = 2500}, ownerFarmId = 1, getOwnerFarmId = function() return 1 end, getName = function() return "Stor kostald" end,
getHusbandryFillLevel = function(self, ft) return barnLevels[ft] or 0 end,
getHusbandryCapacity = function() return 25000 end,
}
local twoEndStation = {owningPlaceable = twoEndBarn, supportedFillTypes = {[MILK] = true, [SLURRY] = true},
loadTriggers = {{triggerNode = {x = 2500, z = 2470}, fillTypes = {[MILK] = true}}, {triggerNode = {x = 2500, z = 2530}, fillTypes = {[SLURRY] = true}}}}
addMarker(40, "Cow Milk", 2500, 2465); loadAt[40] = twoEndStation
addMarker(41, "Cow Slurry", 2500, 2535); loadAt[41] = twoEndStation
local milkEnd = ADSources.getProducts(adEnv, ADSources.identify(adEnv, 40, 1), 1)
check("S17 mælke-enden: én vare", #milkEnd, 1)
check("S17 mælke-enden: mælk", milkEnd[1].fillType, MILK)
local slurryEnd = ADSources.getProducts(adEnv, ADSources.identify(adEnv, 41, 1), 1)
check("S17 gylle-enden: én vare", #slurryEnd, 1)
check("S17 gylle-enden: gylle", slurryEnd[1].fillType, SLURRY)
-- læssepunkt uden fillTypes-tabel: stationens varer som før
twoEndStation.loadTriggers[1].fillTypes = nil
check("S17 uden punkt-varer: stationens varer", #ADSources.getProducts(adEnv, ADSources.identify(adEnv, 40, 1), 1), 2)
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1) os.exit(failures == 0 and 0 or 1)