feat: adBuildings — gårdens bygninger med automatisk markør ved læsse-/aflæsningstrigger
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
-- Kør: luajit tests/test_adBuildings.lua (fra repo-roden)
|
||||
-- Bygninger gården kan bruge + automatisk markør ved læsse-/aflæsningstrigger (≤ 40 m, Wait udelukket,
|
||||
-- siloer strengt), omvendt opslag markør -> bygning, id-fallback, cache.
|
||||
|
||||
local SUGAR, FORAGE, MILK, BASKET = 5, 6, 12, 7
|
||||
local DESC = {[SUGAR] = {name = "SUGAR", title = "Sukker", isPalletType = true}, [FORAGE] = {name = "FORAGE", title = "TMR"}, [MILK] = {name = "MILK", title = "Mælk"}, [BASKET] = {name = "STRAW_BASKET", title = "Kurve", palletFilename = "x"}}
|
||||
g_fillTypeManager = {getFillTypeByIndex = function(_, i) return DESC[i] end, getFillTypeNameByIndex = function(_, i) return DESC[i] and DESC[i].name end, getFillTypeTitleByIndex = function(_, i) return DESC[i] and DESC[i].title end}
|
||||
Logging = {info = function() end, warning = function() end}
|
||||
getWorldTranslation = function(node) return node.x, 0, node.z end
|
||||
SellingStation = {}
|
||||
dofile("FS25_ADSmartPickup/adSupplyPlanner.lua")
|
||||
dofile("FS25_ADSmartPickup/adPrices.lua")
|
||||
dofile("FS25_ADSmartPickup/adBuildings.lua")
|
||||
|
||||
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 markers, wayPoints = {}, {}
|
||||
local function addMarker(id, name, group, x, z)
|
||||
wayPoints[id] = {id = id, x = x, z = z}
|
||||
table.insert(markers, {id = id, markerIndex = #markers + 1, name = name, group = group})
|
||||
end
|
||||
local loadStations, unloadStations = {}, {}
|
||||
local adEnv = {ADGraphManager = {
|
||||
getWayPointById = function(_, id) return wayPoints[id] end,
|
||||
getMapMarkers = function() return markers end,
|
||||
getMapMarkerByWayPointId = function(_, id) for _, m in ipairs(markers) do if m.id == id then return m end end end,
|
||||
}}
|
||||
local strictLoadAt = {}
|
||||
ADSmartPickup = {getLoadStationAtWayPointId = function(_, id) return strictLoadAt[id] end}
|
||||
g_currentMission = {
|
||||
placeableSystem = {placeables = {}},
|
||||
storageSystem = {getLoadingStations = function() return loadStations end, getUnloadingStations = function() return unloadStations end},
|
||||
accessHandler = {canFarmAccess = function() return true end},
|
||||
getFarmId = function() return 1 end,
|
||||
}
|
||||
local function placeable(uid, name, x, z, extra)
|
||||
local p = {uniqueId = uid, rootNode = {x = x, z = z}, ownerFarmId = 1, getOwnerFarmId = function() return 1 end, getName = function() return name end}
|
||||
for k, v in pairs(extra or {}) do p[k] = v end
|
||||
table.insert(g_currentMission.placeableSystem.placeables, p)
|
||||
return p
|
||||
end
|
||||
|
||||
-- verden: kostald med mælketank (load) og foder (unload), sukkerfabrik (unload + pallespawner), to siloer i række, objektlager, salgssted
|
||||
local barn = placeable("barn1", "Kostald 1", 0, 0, {getHusbandryFillLevel = function() return 0 end})
|
||||
local milkStation = {owningPlaceable = barn, loadTriggers = {{triggerNode = {x = 20, z = 0}}}}
|
||||
local barnUnload = {owningPlaceable = barn, unloadTriggers = {{exactFillRootNode = {x = -20, z = 0}}}}
|
||||
table.insert(loadStations, milkStation); table.insert(unloadStations, barnUnload)
|
||||
local mill = placeable("mill", "Sukkerfabrik", 500, 0, {spec_productionPoint = {productionPoint = {productions = {}, storage = {}, palletSpawner = {spawnPlaces = {{startNode = {x = 520, z = 0}}}}, unloadingStation = nil}}})
|
||||
local millUnload = {owningPlaceable = mill, unloadTriggers = {{exactFillRootNode = {x = 480, z = 0}}}, isa = function() return true end, isSellingPoint = true}
|
||||
table.insert(unloadStations, millUnload)
|
||||
local silo1 = placeable("silo1", "Silo 1", 1000, 0, {spec_silo = {}})
|
||||
local silo2 = placeable("silo2", "Silo 2", 1015, 0, {spec_silo = {}})
|
||||
local silo1Station = {owningPlaceable = silo1, loadTriggers = {{triggerNode = {x = 1000, z = 5}}}}
|
||||
local silo2Station = {owningPlaceable = silo2, loadTriggers = {{triggerNode = {x = 1015, z = 5}}}}
|
||||
table.insert(loadStations, silo1Station); table.insert(loadStations, silo2Station)
|
||||
table.insert(unloadStations, {owningPlaceable = silo1, unloadTriggers = {{exactFillRootNode = {x = 1000, z = 5}}}})
|
||||
table.insert(unloadStations, {owningPlaceable = silo2, unloadTriggers = {{exactFillRootNode = {x = 1015, z = 5}}}})
|
||||
local shed = placeable("shed", "Palleskur", 2000, 0, {spec_objectStorage = {objectInfos = {}, capacity = 100}})
|
||||
local sellPoint = placeable("sell", "Mejeri", 3000, 0, {})
|
||||
local sellStation = {owningPlaceable = sellPoint, unloadTriggers = {{exactFillRootNode = {x = 3000, z = 10}}}, isa = function() return true end, isSellingPoint = true}
|
||||
table.insert(unloadStations, sellStation)
|
||||
local other = placeable("otherfarm", "Naboens", 4000, 0, {spec_silo = {}, ownerFarmId = 2, getOwnerFarmId = function() return 2 end})
|
||||
|
||||
addMarker(1, "cow 1 milk", "Milk", 25, 0) -- 5 m fra mælketriggeren
|
||||
addMarker(2, "Cow 1 food", "Cow food", -30, 0) -- 10 m fra fodertriggeren
|
||||
addMarker(3, "cow wait 1", "cow wait", 22, 0) -- Wait: må ALDRIG vælges (tættere end mælkemarkøren)
|
||||
addMarker(4, "Suger Load", "Pickup", 525, 0) -- 5 m fra pallespawneren
|
||||
addMarker(5, "sugar offload", "production", 470, 0)
|
||||
addMarker(6, "silo 1", "silo", 1000, 12) -- strengt: silo1
|
||||
addMarker(7, "silo 2", "silo", 1015, 12) -- strengt: silo2 (7 m fra silo1's trigger-node på x-aksen? nej: 15 m)
|
||||
strictLoadAt[6] = silo1Station; strictLoadAt[7] = silo2Station
|
||||
addMarker(8, "Storage pickup", "Pickup", 2010, 0)
|
||||
addMarker(9, "Mejeri", "selling", 3000, 20)
|
||||
addMarker(10, "Langt væk", "All", 9000, 9000)
|
||||
|
||||
-- B1: liste, kind og markører
|
||||
local list = ADBuildings.list(adEnv, 1)
|
||||
local byId = {}
|
||||
for _, b in ipairs(list) do byId[b.id] = b end
|
||||
check("B1 antal (naboens silo udeladt)", #list, 6)
|
||||
check("B1 stald", byId.barn1.kind, "husbandry")
|
||||
check("B1 stald læssemarkør = mælk (ikke Wait, som er tættere)", byId.barn1.loadMarker.id, 1)
|
||||
check("B1 stald aflæsningsmarkør = foder", byId.barn1.unloadMarker.id, 2)
|
||||
check("B1 stald afstand", byId.barn1.loadMarker.distance, 5)
|
||||
check("B1 fabrik læssemarkør via pallespawner", byId.mill.loadMarker.id, 4)
|
||||
check("B1 fabrik aflæsningsmarkør", byId.mill.unloadMarker.id, 5)
|
||||
check("B1 fabrik er ikke salgssted", byId.mill.canSell, false)
|
||||
check("B1 objektlager markør via rootNode", byId.shed.loadMarker.id, 8)
|
||||
check("B1 salgssted", byId.sell.kind, "sell")
|
||||
check("B1 salgssted markør", byId.sell.unloadMarker.id, 9)
|
||||
check("B1 salgssted canSell", byId.sell.canSell, true)
|
||||
check("B1 stald kan være kilde og mål", byId.barn1.canBeSource and byId.barn1.canBeTarget, true)
|
||||
check("B1 silo kilde, ikke mål", byId.silo1.canBeSource and not byId.silo1.canBeTarget, true)
|
||||
|
||||
-- B2: siloer i række: strengt opslag giver hver sin markør
|
||||
check("B2 silo 1 markør", byId.silo1.loadMarker.id, 6)
|
||||
check("B2 silo 2 markør", byId.silo2.loadMarker.id, 7)
|
||||
strictLoadAt[7] = nil
|
||||
ADBuildings.invalidate()
|
||||
check("B2 silo uden strengt match: ingen læssemarkør", ADBuildings.find(adEnv, 1, "silo2").loadMarker, nil)
|
||||
strictLoadAt[7] = silo2Station
|
||||
ADBuildings.invalidate()
|
||||
|
||||
-- B3: byMarker (omvendt opslag)
|
||||
check("B3 mælkemarkør -> stald (load)", ADBuildings.byMarker(adEnv, 1, 1, "load").id, "barn1")
|
||||
check("B3 fodermarkør -> stald (unload)", ADBuildings.byMarker(adEnv, 1, 2, "unload").id, "barn1")
|
||||
check("B3 fodermarkør er ikke load", ADBuildings.byMarker(adEnv, 1, 2, "load"), nil)
|
||||
check("B3 fjern markør -> nil", ADBuildings.byMarker(adEnv, 1, 10, "load"), nil)
|
||||
|
||||
-- B4: id-fallback uden uniqueId
|
||||
check("B4 id fra position", ADBuildings.getId({rootNode = {x = 12.6, z = -3.2}}), "pos:13:-3")
|
||||
check("B4 id fra uniqueId", ADBuildings.getId(barn), "barn1")
|
||||
|
||||
-- B5: cache: samme tabel inden for CACHE_MS, ny efter invalidate
|
||||
local first = ADBuildings.list(adEnv, 1)
|
||||
check("B5 cachet", ADBuildings.list(adEnv, 1) == first, true)
|
||||
ADBuildings.invalidate()
|
||||
check("B5 ny efter invalidate", ADBuildings.list(adEnv, 1) ~= first, true)
|
||||
|
||||
-- B6: sortering: fabrik, stald, objektlager, silo, salg; navn inden for slags
|
||||
local order = {}
|
||||
for _, b in ipairs(ADBuildings.list(adEnv, 1)) do table.insert(order, b.kind) end
|
||||
check("B6 rækkefølge", table.concat(order, ","), "factory,husbandry,objectStorage,silo,silo,sell")
|
||||
|
||||
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
|
||||
os.exit(failures == 0 and 0 or 1)
|
||||
Reference in New Issue
Block a user