diff --git a/FS25_ADSmartPickup/adSources.lua b/FS25_ADSmartPickup/adSources.lua index 2819664..84be2df 100644 --- a/FS25_ADSmartPickup/adSources.lua +++ b/FS25_ADSmartPickup/adSources.lua @@ -63,7 +63,7 @@ end -- 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. function ADSources.isPalletAt(source, fillType) - if source.kind == "silo" then + if source.kind == "silo" or source.kind == "husbandry" then return false elseif source.kind == "objectStorage" then return true @@ -137,6 +137,10 @@ function ADSources.identify(adEnv, wayPointId, farmId) if placeable ~= nil and placeable.spec_silo ~= nil then return {kind = "silo", placeable = placeable, station = station, wayPointId = wayPointId, name = getPlaceableName(placeable, markerName)} 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 -- til pallespawneren; dernæst objektlagre. local factory = findPlaceableNear(wayPoint, farmId, isProductionPoint) @@ -274,12 +278,43 @@ local function getObjectStorageProducts(source) return products 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} }. function ADSources.getProducts(adEnv, source, farmId) if source.kind == "factory" then return getFactoryProducts(source, farmId) elseif source.kind == "silo" then return getSiloProducts(source) + elseif source.kind == "husbandry" then + return getHusbandryProducts(source) elseif source.kind == "objectStorage" then return getObjectStorageProducts(source) end diff --git a/FS25_ADSmartPickup/modDesc.xml b/FS25_ADSmartPickup/modDesc.xml index 7144a6d..b7ac4f0 100644 --- a/FS25_ADSmartPickup/modDesc.xml +++ b/FS25_ADSmartPickup/modDesc.xml @@ -1,7 +1,7 @@ masterdraco - 1.12.18.0 + 1.12.19.0 <en>AD Smart Pickup</en> diff --git a/tests/test_adSources.lua b/tests/test_adSources.lua index 1a1e024..45d796a 100644 --- a/tests/test_adSources.lua +++ b/tests/test_adSources.lua @@ -315,5 +315,30 @@ local truck2 = {rootNode = {x = 300, z = 270}} 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) +-- 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")) os.exit(failures == 0 and 0 or 1)