-- Kør: luajit tests/test_adFieldsPolygon.lua (fra repo-roden) -- FS25-marker har ingen polygonPoints — omridset hentes med field:getDensityMapPolygon():getVerticesList(). -- In-game 26/9 (Dakota 16x, marker på 1,7 x 0,6 km): uden omrids blev kun markskiltet (posX/posZ) prøvet; -- F108 med majs viste "bar jord" og "mangler markør" (markøren stod ved kanten, 890 m fra skiltet). 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 = {warning = function() end, info = function() end} local MAIZE = 10 function getWorldTranslation() return 0, 0, 0 end function getTerrainHeightAtWorldPos() return 0 end -- markskiltet står i marken, men ved en stribe uden afgrøde (x > 1400) function cropAt(x) return x <= 1400 and MAIZE or nil end FSDensityMapUtil = { getFieldDataAtWorldPosition = function() return 1, 2 end, getFruitTypeIndexAtWorldPos = function(x, z) return cropAt(x) end, getFruitArea = function() return 0, 10 end, } FieldDensityMap = {SPRAY_LEVEL = 4, LIME_LEVEL = 5, PLOW_LEVEL = 6} DensityCoordType = {POINT_VECTOR_VECTOR = 1} DensityMapModifier = {new = function() return {setParallelogramWorldCoords = function() end, executeGet = function() return 1, 1 end} end} g_fruitTypeManager = { getFruitTypeByIndex = function() return {name = "MAIZE", fillType = {index = 60, title = "Majs"}, minHarvestingGrowthState = 7, maxHarvestingGrowthState = 7, cutState = 9} end, getConverterDataByName = function() return {} end, } g_fillTypeManager = {getConverterDataByName = function() return {} end, getFillTypeNameByIndex = function() return "X" end} g_farmlandManager = {getFarmlandOwner = function() return 1 end} local polygon = {getVerticesList = function() return {0, 0, 1600, 0, 1600, 600, 0, 600} end} local field = {getId = function() return 108 end, farmland = {id = 108}, posX = 1500, posZ = 50, getDensityMapPolygon = function() return polygon end} g_fieldManager = {getFields = function() return {field} end} g_currentMission = {terrainRootNode = 1, missionInfo = {}, fieldGroundSystem = { getDensityMapData = function() return 1, 0, 2 end, getMaxValue = function() return 2 end}} local adEnv = {ADGraphManager = { getMapMarkers = function() return {{id = 900, name = "F108"}} end, -- markøren står 5 m uden for marken ved den modsatte kant: 1505 m fra skiltet getWayPointById = function() return {x = -5, z = 300} end, }} dofile("FS25_ADSmartPickup/adFields.lua") local now = 0 for _ = 1, 1000 do if ADFields.getInfo(108) ~= nil then break end ADFields.scanStep(adEnv, 1, now) now = now + 16 end local info = ADFields.getInfo(108) check("PG1 marken er scannet", info ~= nil, true) check("PG2 omrids fra getDensityMapPolygon", info and #info.verts, 4) check("PG3 majsen findes trods skiltet på bar stribe", info and info.fruitName, "MAIZE") check("PG4 ikke bar mark", info and info.kind, "harvest") check("PG5 markør ved kanten findes (afstand til omridset)", info and info.markerId, 900) check("PG6 afstand = til kanten", info and info.markerDistance, 5) -- PG7-9: field.fieldState er spillets sandhed (fields.xml: MAIZE growthState 2); jord-bits fra -- getFieldDataAtWorldPosition (2. værdi) er IKKE vækststadie. Høstet mark (cutState) = bar, vist som stub. field.fieldState = {fruitTypeIndex = MAIZE, growthState = 2} FSDensityMapUtil.getFieldDataAtWorldPosition = function() return true, 0 end -- jord-bits 0 lignede "ingen vækst" local function rescan() ADFields.cache, ADFields.listCache, ADFields.activeScan, ADFields.lastScanStart = {}, nil, nil, nil for _ = 1, 2000 do if ADFields.getInfo(108) ~= nil then break end ADFields.scanStep(adEnv, 1, now) now = now + 16 end return ADFields.getInfo(108) end info = rescan() check("PG7 majs i vækst (fieldState), ikke bar", info and info.kind, "harvest") check("PG7 fase vokser", info and info.phase, "growing") field.fieldState = {fruitTypeIndex = MAIZE, growthState = 9} info = rescan() check("PG8 høstet (cutState) = bar", info and info.kind, "bare") check("PG8 stub af majs", info and info.stubbleOf, "Majs") field.fieldState = {fruitTypeIndex = 0, growthState = 0} cropAt = function() return nil end info = rescan() check("PG9 ingen afgrøde = bar uden stub", info and info.kind .. "/" .. tostring(info.stubbleOf), "bare/nil") print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) os.exit(failures == 0 and 0 or 1)