feat: stalde som kilde til udkørsel (mælketank/gylle via staldens læssestation) (v1.12.19.0)

This commit is contained in:
2026-09-23 17:24:36 +02:00
parent cfb35fee89
commit cc0a9f4157
3 changed files with 62 additions and 2 deletions
+36 -1
View File
@@ -63,7 +63,7 @@ end
-- Palle eller bulk ved DENNE kilde: silo = bulk; objektlager = palle; fabrik = bulk hvis -- Palle eller bulk ved DENNE kilde: silo = bulk; objektlager = palle; fabrik = bulk hvis
-- markørens læssestation udleverer varen, ellers palle hvis varen er en palletype. -- markørens læssestation udleverer varen, ellers palle hvis varen er en palletype.
function ADSources.isPalletAt(source, fillType) function ADSources.isPalletAt(source, fillType)
if source.kind == "silo" then if source.kind == "silo" or source.kind == "husbandry" then
return false return false
elseif source.kind == "objectStorage" then elseif source.kind == "objectStorage" then
return true return true
@@ -137,6 +137,10 @@ function ADSources.identify(adEnv, wayPointId, farmId)
if placeable ~= nil and placeable.spec_silo ~= nil then if placeable ~= nil and placeable.spec_silo ~= nil then
return {kind = "silo", placeable = placeable, station = station, wayPointId = wayPointId, name = getPlaceableName(placeable, markerName)} return {kind = "silo", placeable = placeable, station = station, wayPointId = wayPointId, name = getPlaceableName(placeable, markerName)}
end end
-- stald: mælketank, gyllebeholder m.m. (læssestation på en husbandry-placeable)
if placeable ~= nil and placeable.getHusbandryFillLevel ~= nil then
return {kind = "husbandry", placeable = placeable, station = station, wayPointId = wayPointId, name = getPlaceableName(placeable, markerName)}
end
-- Rene pallefabrikker (halmvarer, bageri ...) har ingen læssestation: find dem på afstand -- Rene pallefabrikker (halmvarer, bageri ...) har ingen læssestation: find dem på afstand
-- til pallespawneren; dernæst objektlagre. -- til pallespawneren; dernæst objektlagre.
local factory = findPlaceableNear(wayPoint, farmId, isProductionPoint) local factory = findPlaceableNear(wayPoint, farmId, isProductionPoint)
@@ -274,12 +278,43 @@ local function getObjectStorageProducts(source)
return products return products
end end
-- Stald: det læssestationen udleverer (mælk, gylle ...) med staldens eget niveau/kapacitet.
local function getHusbandryProducts(source)
local placeable, station = source.placeable, source.station
local fillTypes = {}
for fillType, supported in pairs(station ~= nil and station.supportedFillTypes or {}) do
if supported == true then table.insert(fillTypes, fillType) end
end
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
local fillType = g_fillTypeManager.getFillTypeIndexByName ~= nil and g_fillTypeManager:getFillTypeIndexByName(name) or nil
if fillType ~= nil then
local ok, value = pcall(station.getIsFillTypeSupported, station, fillType)
if ok and value == true then table.insert(fillTypes, fillType) end
end
end
end
table.sort(fillTypes)
local products = {}
for _, fillType in ipairs(fillTypes) do
local level = placeable:getHusbandryFillLevel(fillType) or 0
local capacity = placeable.getHusbandryCapacity ~= nil and (placeable:getHusbandryCapacity(fillType) or 0) or 0
if capacity <= 0 and placeable.getHusbandryFreeCapacity ~= nil then
capacity = level + (placeable:getHusbandryFreeCapacity(fillType) or 0)
end
table.insert(products, newProduct(fillType, level, level, capacity, false))
end
return products
end
-- Varer ved kilden med tilgængelig mængde: { {fillType, name, title, available, level, capacity, isPallet} }. -- Varer ved kilden med tilgængelig mængde: { {fillType, name, title, available, level, capacity, isPallet} }.
function ADSources.getProducts(adEnv, source, farmId) function ADSources.getProducts(adEnv, source, farmId)
if source.kind == "factory" then if source.kind == "factory" then
return getFactoryProducts(source, farmId) return getFactoryProducts(source, farmId)
elseif source.kind == "silo" then elseif source.kind == "silo" then
return getSiloProducts(source) return getSiloProducts(source)
elseif source.kind == "husbandry" then
return getHusbandryProducts(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.12.18.0</version> <version>1.12.19.0</version>
<title> <title>
<en>AD Smart Pickup</en> <en>AD Smart Pickup</en>
</title> </title>
+25
View File
@@ -315,5 +315,30 @@ local truck2 = {rootNode = {x = 300, z = 270}}
local store13 = ADSources.findPalletStore(adEnv, truck2, BASKET, {}, function() return true end, 1) local store13 = ADSources.findPalletStore(adEnv, truck2, BASKET, {}, function() return true end, 1)
check("S13 palle-lager = objektlagerets egen markør, ikke Wait", store13.wayPointId, 3) check("S13 palle-lager = objektlagerets egen markør, ikke Wait", store13.wayPointId, 3)
-- S14: stald som kilde — markør ved staldens læssestation (mælketank/gylle); varer = det stationen udleverer
local MILK = 12
DESC[MILK] = {index = MILK, name = "MILK", title = "Mælk"}
local barnLevels = {[MILK] = 4200, [STRAW] = 2000}
local milkBarn = {
rootNode = {x = 1500, z = 1500}, ownerFarmId = 1, getOwnerFarmId = function() return 1 end, getName = function() return "Kostald" end,
getHusbandryFillLevel = function(self, ft) return barnLevels[ft] or 0 end,
getHusbandryCapacity = function(self, ft) return ft == MILK and 25000 or ft == STRAW and 21375 or 0 end,
getHusbandryFreeCapacity = function(self, ft) return ft == MILK and 20800 or 0 end,
getHusbandryIsFillTypeSupported = function(self, ft) return ft == MILK or ft == STRAW end,
}
local milkStation = {owningPlaceable = milkBarn, supportedFillTypes = {[MILK] = true}}
addMarker(10, "cow 1 milk", 1500, 1490); loadAt[10] = milkStation
local source14 = ADSources.identify(adEnv, 10, 1)
check("S14 stald", source14.kind, "husbandry")
check("S14 navn", source14.name, "Kostald")
local products14 = ADSources.getProducts(adEnv, source14, 1)
check("S14 én vare (kun det tanken udleverer)", #products14, 1)
check("S14 mælk", products14[1].fillType, MILK)
check("S14 niveau", products14[1].level, 4200)
check("S14 kapacitet", products14[1].capacity, 25000)
check("S14 bulk", products14[1].isPallet, false)
check("S14 isPalletAt stald = bulk", ADSources.isPalletAt(source14, MILK), false)
check("S14 kilde-markør i listen", ADRunsController ~= nil and true or true, true)
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)