-- Kør: luajit tests/test_adFieldSilos.lua (fra repo-roden) dofile("FS25_ADSmartPickup/adFieldSiloPlanner.lua") dofile("FS25_ADSmartPickup/adFieldSiloConfig.lua") dofile("FS25_ADSmartPickup/adFieldSilos.lua") local S = ADFieldSilos 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 local loan = {startedMs = 0, lastProgressMs = 0, lastFill = 0} check("kører, tidligt -> behold", S.releaseReason(loan, {adActive = true, controlled = false, fill = 0, moving = true}, 5000), nil) check("AD slukket -> done", S.releaseReason(loan, {adActive = false, controlled = false, fill = 0}, 5000), "done") check("spiller i vognen -> player", S.releaseReason(loan, {adActive = true, controlled = true, fill = 0}, 5000), "player") check("står stille uden fyld i 120 s -> stuck", S.releaseReason(loan, {adActive = true, controlled = false, fill = 0, moving = false}, 120001), "stuck") check("kører stadig efter 120 s -> behold", S.releaseReason(loan, {adActive = true, controlled = false, fill = 0, moving = true}, 120001), nil) local loading = {startedMs = 0, lastProgressMs = 110000, lastFill = 0} check("fyldning steg for nylig -> behold", S.releaseReason(loading, {adActive = true, controlled = false, fill = 20000, moving = false}, 125000), nil) -- Røgtest af spil-laget med mocks: planNow låner nærmeste tømmevogn, isLoaned = optaget, -- frakobling (setConfig enabled=false) stopper AD og frigiver (Review Focus). do local WHEAT = 1 Logging = {info = function() end, warning = function() end} g_currentMission = {getFarmId = function() return 1 end} g_fillTypeManager = {getFillTypeByIndex = function() return {title = "Hvede"} end} function getWorldTranslation(node) return node.x, 0, node.z end ADRuns = {vehicleLabel = function(v) return v.name end} local function storage(levels, free) return {fillLevels = levels, fillTypes = {[WHEAT] = true}, getFreeCapacity = function() return free end} end local fieldSilo = {id = "fs", name = "Marksilo 1", kind = "silo", placeable = {rootNode = {x = 1000, z = 0}, spec_silo = {storages = {storage({[WHEAT] = 60000}, 0)}}}} local farm = {id = "farm", name = "Gårdsilo", kind = "silo", placeable = {rootNode = {x = 0, z = 0}, spec_silo = {storages = {storage({}, 500000)}}}} ADBuildings = {list = function() return {fieldSilo, farm} end, getMarkers = function(b, role) return {{id = b.id .. "-" .. role}} end} ADFields = {list = function() return {{id = 1}} end, fieldSilos = function() return {fieldSilo, farm} end} local started = {} local function makeVehicle(name, x) local module = {active = false} function module:setMode() end function module:setFirstMarkerByWayPointId(id) self.first = id end function module:setSecondMarkerByWayPointId(id) self.second = id end function module:setFillType() end function module:setLoopsDone() end function module:raiseDirtyFlag() end function module:isActive() return self.active end return {name = name, x = x, lastSpeedReal = 0, ad = {stateModule = module}, stopAutoDrive = function(self) self.ad.stateModule.active = false; self.stopped = true end} end local near, far = makeVehicle("Nær", 900), makeVehicle("Fjern", 5000) local adEnv = {AutoDrive = {MODE_PICKUPANDDELIVER = 2, getAllDischargeableUnits = function() return {{fillUnitIndex = 1, object = { getFillUnitCapacity = function() return 40000 end, getFillUnitSupportedFillTypes = function() return {[WHEAT] = true} end, getFillUnitFillLevel = function() return 0 end, getFillUnitFillType = function() return WHEAT end}}} end, getAllUnits = function() return {} end, getAllFillLevels = function() return 0 end}} ADFieldWork = { getRigs = function() return { {id = "n", vehicle = near, role = "unloader", enabled = true, busy = S.isLoaned(near), controlled = false, x = 900, z = 0}, {id = "f", vehicle = far, role = "unloader", enabled = true, busy = S.isLoaned(far), controlled = false, x = 5000, z = 0}, {id = "h", vehicle = far, role = "harvester", enabled = true, busy = false, controlled = false, x = 1000, z = 0}} end, enableParkAtJobFinished = function() end, startAd = function(_, v, _, first, second, fillType) v.ad.stateModule.active = true; table.insert(started, {v = v, first = first, second = second, fillType = fillType}) end, } S.setConfig(ADFieldSiloConfig.with(ADFieldSiloConfig.toggleStore(ADFieldSiloConfig.new(), "farm"), {enabled = true, maxVehicles = 1})) local plan = S.planNow(adEnv) check("RØG én afsendelse (x=1)", #started, 1) check("RØG nærmeste tømmevogn", started[1] ~= nil and started[1].v.name, "Nær") check("RØG fra marksilo-markør", started[1] ~= nil and started[1].first, "fs-load") check("RØG til gårdlager-markør", started[1] ~= nil and started[1].second, "farm-unload") check("RØG varen med", started[1] ~= nil and started[1].fillType, WHEAT) check("RØG gårdlager er ikke marksilo", #plan.status, 1) check("RØG vognen er lånt", S.isLoaned(near), true) check("RØG x nået -> ingen flere", #S.planNow(adEnv).dispatch, 0) S.setConfig(ADFieldSiloConfig.with(S.config, {enabled = false})) check("RØG frakobling stopper AD", near.stopped, true) check("RØG frakobling frigiver", S.isLoaned(near), false) end print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) os.exit(failures == 0 and 0 or 1)