feat(mp): etape 1 - automatik kun på serveren, fælles gård via ADUtil.farmId, klienter skriver aldrig modens filer
This commit is contained in:
@@ -368,7 +368,7 @@ function ADAutoCrop.tick(adEnv, dt)
|
||||
if ADSettings == nil or ADSettings.get("autoAll") ~= 1 then return end
|
||||
if not changed then return ADAutoCrop.tickNeeds(adEnv) end
|
||||
logInfo("ADSmartPickup: Alt automatisk: gårdens marker er ændret — planen laves om")
|
||||
local result = ADAutoCrop.applyAll(g_currentMission:getFarmId(), adEnv, {enableIds = added, replan = true})
|
||||
local result = ADAutoCrop.applyAll(ADUtil.farmId(), adEnv, {enableIds = added, replan = true})
|
||||
-- mislykket (gården kunne ikke læses, scanning): prøv igen ved næste tjek
|
||||
if result == nil or result.failed ~= nil or result.scanning then
|
||||
ADAutoCrop.knownFields = previous
|
||||
@@ -431,5 +431,5 @@ function ADAutoCrop.tickNeeds(adEnv)
|
||||
logInfo("ADSmartPickup: Alt automatisk: gårdens behov er ændret (%s -> %s) — planen laves om",
|
||||
describeSignature(ADAutoCrop.knownNeeds), describeSignature(now))
|
||||
-- lykkes det ikke, står knownNeeds uændret, og der prøves igen ved næste tjek
|
||||
ADAutoCrop.applyAll(g_currentMission:getFarmId(), adEnv, {enableIds = {}, replan = true})
|
||||
ADAutoCrop.applyAll(ADUtil.farmId(), adEnv, {enableIds = {}, replan = true})
|
||||
end
|
||||
|
||||
@@ -1014,6 +1014,6 @@ function ADBuildings.tickDump(adEnv, dt)
|
||||
dumpState.done = true
|
||||
local path = getUserProfileAppPath ~= nil and (getUserProfileAppPath() .. "modSettings/FS25_ADSmartPickup/dumpTriggers.txt") or nil
|
||||
if path == nil or fileExists == nil or not fileExists(path) then return end
|
||||
local ok, err = pcall(ADBuildings.dumpTriggers, adEnv, g_currentMission:getFarmId())
|
||||
local ok, err = pcall(ADBuildings.dumpTriggers, adEnv, ADUtil.farmId())
|
||||
if not ok then Logging.warning("ADSmartPickup: TRIGGER-dump fejlede: %s", tostring(err)) end
|
||||
end
|
||||
|
||||
@@ -306,7 +306,7 @@ end
|
||||
-- ---- evaluering ----
|
||||
|
||||
local function farmId()
|
||||
return g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
return ADUtil.farmId()
|
||||
end
|
||||
|
||||
local function plan(data, state)
|
||||
|
||||
@@ -230,7 +230,7 @@ local function start(adEnv, entry, enabled)
|
||||
if harvest and entry.mission ~= nil then
|
||||
-- høst: læssene skal til kontraktens salgssted (ADFieldWork.chooseStore)
|
||||
local placeable, where, station = sellPlaceableOf(entry.mission)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
changes.contractSellIds = placeable ~= nil and sellMarkerIds(adEnv, placeable, farmId) or {}
|
||||
-- uden AutoDrive-vej kører spillets hjælper læssene hertil (ADFieldWork beginUnloader)
|
||||
changes.contractStation = station
|
||||
@@ -289,7 +289,9 @@ function ADContracts.onAnswer(_, yes, entry)
|
||||
end
|
||||
|
||||
local function ask(entry)
|
||||
if YesNoDialog == nil or YesNoDialog.show == nil then
|
||||
-- dedikeret server (ingen skærm): ingen at spørge -> rør den ikke, som uden dialog (multiplayer etape 1;
|
||||
-- spørgsmålet til en spiller kommer i etape 4)
|
||||
if YesNoDialog == nil or YesNoDialog.show == nil or (g_client == nil and g_server ~= nil) then
|
||||
-- kan ikke spørge: rør den ikke (spilleren kan vælge "moden altid" under Indstillinger)
|
||||
start(ADContracts.adEnv, entry, false)
|
||||
return
|
||||
@@ -372,7 +374,7 @@ function ADContracts.tick(adEnv, nowMs)
|
||||
local decision = ADContracts.decision(ADSettings ~= nil and ADSettings.get("contracts") or nil)
|
||||
if lastScanAt ~= nil and nowMs - lastScanAt < ADContracts.SCAN_MS then return end
|
||||
lastScanAt = nowMs
|
||||
local farmId = g_currentMission ~= nil and g_currentMission:getFarmId() or nil
|
||||
local farmId = ADUtil.farmId()
|
||||
if farmId == nil then return end
|
||||
local okCollect, errCollect = pcall(collectFinished, farmId, nowMs)
|
||||
if not okCollect then Logging.warning("ADSmartPickup: indkassering af kontrakter: %s", tostring(errCollect)) end
|
||||
|
||||
@@ -140,7 +140,7 @@ end
|
||||
-- gælder. En gyllevogn/spreder foretrækkes, når gården har mindst minSharePercent af markens behov for DENS vare.
|
||||
function ADFieldFertilizer.preferCandidate(farmId, areaHa)
|
||||
if not ADFieldFertilizer.isEnabled() then return nil end
|
||||
farmId = farmId or (g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId()) or 1
|
||||
farmId = farmId or ADUtil.farmId()
|
||||
local minStock = ADFieldWork ~= nil and ADFieldWork.MIN_REFILL_STOCK_L or 500
|
||||
local share = ADFieldFertilizer.minSharePercent()
|
||||
return function(candidate)
|
||||
|
||||
@@ -956,7 +956,7 @@ function ADFieldJobs.tick(adEnv, dt)
|
||||
ADFieldJobs.timer = ADFieldJobs.timer + dt
|
||||
if ADFieldJobs.loaded then
|
||||
-- markscanningen kører et lille stykke HVERT frame (arbejdskø), aldrig en hel mark i ét frame
|
||||
local okScan, errScan = pcall(ADFields.scanStep, adEnv, g_currentMission:getFarmId(), ADFieldJobs.now)
|
||||
local okScan, errScan = pcall(ADFields.scanStep, adEnv, ADUtil.farmId(), ADFieldJobs.now)
|
||||
if not okScan then Logging.warning(ADFieldJobs.LOG_PREFIX .. "markscanning: %s", tostring(errScan)) end
|
||||
end
|
||||
if ADFieldJobs.timer < ADFieldJobs.TICK_MS then return end
|
||||
|
||||
@@ -74,7 +74,7 @@ end
|
||||
-- ---- spil-input ----
|
||||
|
||||
local function farmId()
|
||||
return g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
return ADUtil.farmId()
|
||||
end
|
||||
|
||||
local function position(node)
|
||||
|
||||
@@ -858,7 +858,7 @@ function ADFieldWork.dispatchPool(adEnv, field, info, role, roleAccept, decision
|
||||
return (implement.width or 0) <= 0 or ADFieldModel.checkWidth(role, implement.width, required)
|
||||
end
|
||||
-- gylle som gødning gælder også puljens redskaber (in-game 17/10: MEGA valgt, Supercis stod klar i puljen)
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or nil
|
||||
local farmId = ADUtil.farmId()
|
||||
local pair, why, args = ADPool.pairFor(role, info.x, info.z, implements, tractors, ADPool.blocked(now()), accept,
|
||||
fertilizerPrefer(role, farmId, info))
|
||||
if pair == nil then
|
||||
|
||||
@@ -43,7 +43,7 @@ end
|
||||
|
||||
function ADFleetNames.apply(adEnv)
|
||||
local vehicles, byId, parkUse = {}, {}, {}
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, any in pairs(g_currentMission.vehicleSystem.vehicles) do
|
||||
local index = any.advd ~= nil and any.advd.parkDestination or nil
|
||||
if type(index) == "number" and index >= 1 and any.getOwnerFarmId ~= nil and any:getOwnerFarmId() == farmId then
|
||||
|
||||
@@ -451,7 +451,7 @@ local function guessFor(adEnv, run, vehicle, tractorId)
|
||||
local taken = {}
|
||||
for _, id in ipairs(ADRuns.wagonIdsOf(run)) do taken[id] = true end
|
||||
local candidates = {}
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, any in pairs(g_currentMission.vehicleSystem.vehicles) do
|
||||
local index = any.advd ~= nil and any.advd.parkDestination or nil
|
||||
local attached = any.getAttacherVehicle ~= nil and any:getAttacherVehicle() ~= nil
|
||||
|
||||
@@ -107,7 +107,7 @@ end
|
||||
|
||||
function ADLivestock.survey(adEnv)
|
||||
local lines = {}
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local placeables = g_currentMission.placeableSystem ~= nil and g_currentMission.placeableSystem.placeables or {}
|
||||
for _, placeable in ipairs(placeables) do
|
||||
local okPlaceable, errPlaceable = pcall(function()
|
||||
@@ -921,7 +921,7 @@ function ADLivestock.load()
|
||||
end
|
||||
|
||||
local function planJobs(adEnv)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
-- gemte "læsset af os"-mærker: knyttes til vognene, når de findes efter indlæsningen
|
||||
-- kreaturvogne er ikke i AD's køretøjsliste: søg i spillets (review). Kun hvis vognen ikke har FLERE dyr end
|
||||
-- ved gemningen (spilleren har ikke sat sine egne ind)
|
||||
|
||||
@@ -1131,7 +1131,7 @@ local function describeLoadFailure(adEnv, vehicle, task, state, source)
|
||||
local parts = {}
|
||||
local marker = adEnv.ADGraphManager.getMapMarkerByWayPointId ~= nil and adEnv.ADGraphManager:getMapMarkerByWayPointId(state.current) or nil
|
||||
table.insert(parts, string.format("markør '%s' (%s)", marker ~= nil and tostring(marker.name) or "?", tostring(state.current)))
|
||||
local ok, products = pcall(ADSources.getProducts, adEnv, source, g_currentMission:getFarmId())
|
||||
local ok, products = pcall(ADSources.getProducts, adEnv, source, ADUtil.farmId())
|
||||
local wanted = {}
|
||||
for _, fillType in ipairs(state.trip.fillTypes) do wanted[fillType] = true end
|
||||
for _, item in ipairs(ok and products or {}) do
|
||||
|
||||
@@ -82,7 +82,7 @@ end
|
||||
-- Frakoblede redskaber med rollen. Returnerer det nærmeste uden AutoDrive-parkering (spilleren kobler det på) og
|
||||
-- om der findes et MED parkering — det henter puljen selv (også når det er i brug), så spilleren spørges ikke.
|
||||
local function looseImplement(adEnv, role, x, z, required, roleAccept, only)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local best, bestD, parkedExists = nil, nil, false
|
||||
for _, vehicle in pairs(g_currentMission.vehicleSystem.vehicles) do
|
||||
local owned = vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() == farmId
|
||||
|
||||
@@ -671,7 +671,7 @@ end
|
||||
-- isBusy(vehicle): markarbejdets optaget-regel (opgave, AD/CP kører, lånt af marksilo, på hjemtur).
|
||||
function ADPool.collect(adEnv, isBusy)
|
||||
local markers = adEnv.ADGraphManager:getMapMarkers()
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local implements, tractors = {}, {}
|
||||
local targeted = connectTargets(adEnv)
|
||||
-- spillets egen liste: frakoblede redskaber er ikke nødvendigvis i AutoDrive's køretøjsliste
|
||||
@@ -730,7 +730,7 @@ end
|
||||
-- spilleren kan se hvorfor) og alle traktorer uden egen arbejdsrolle, der ikke hører til et flow.
|
||||
function ADPool.overview(adEnv)
|
||||
local markers = adEnv.ADGraphManager:getMapMarkers()
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local nowMs = ADFieldJobs.now or 0
|
||||
local implements, tractors = {}, {}
|
||||
for _, vehicle in pairs(g_currentMission.vehicleSystem.vehicles) do
|
||||
|
||||
@@ -122,7 +122,7 @@ end
|
||||
|
||||
-- Spillerens gård ejer placeablen; ukendt ejer = regnes som egen (afleveringer til egne anlæg er ikke salg).
|
||||
function ADPrices.isOwnedByPlayer(placeable)
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
local farmId = ADUtil.farmId()
|
||||
if getOwner(placeable) == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ function ADRunsController.getVehicleId(vehicle)
|
||||
end
|
||||
|
||||
function ADRunsController.getFarmVehicles(adEnv)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local result = {}
|
||||
for _, vehicle in pairs(adEnv.AutoDrive.getAllVehicles()) do
|
||||
-- kun motoriserede (traktorer, høstere); AD-spec'en sidder også på redskaber
|
||||
@@ -197,7 +197,7 @@ function ADRunsController.canStoreAt(adEnv, building, goods)
|
||||
if building.unloadMarker == nil or ADLoadSwap == nil or ADLoadSwap.isStoreTarget == nil then
|
||||
return false
|
||||
end
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
local farmId = ADUtil.farmId()
|
||||
local station = ADSmartPickup.getUnloadStationAtWayPointId(adEnv, building.unloadMarker.id, farmId)
|
||||
if station == nil then
|
||||
return false
|
||||
@@ -215,7 +215,7 @@ end
|
||||
function ADRunsController.getStoreBuildings(adEnv, run)
|
||||
local result = {}
|
||||
if ADBuildings == nil or run == nil then return result end
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, buildingId in ipairs(run.storeBuildingIds or {}) do
|
||||
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
||||
if building ~= nil then table.insert(result, building) end
|
||||
@@ -227,7 +227,7 @@ end
|
||||
function ADRunsController.getFeedBuildings(adEnv, run)
|
||||
local result = {}
|
||||
if ADBuildings == nil or run == nil then return result end
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, buildingId in ipairs(run.feedBuildingIds or {}) do
|
||||
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
||||
if building ~= nil then table.insert(result, building) end
|
||||
@@ -239,7 +239,7 @@ end
|
||||
function ADRunsController.getStoreMarkers(adEnv, run)
|
||||
local result = {}
|
||||
if ADBuildings == nil or run == nil then return result end
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, buildingId in ipairs(run.storeBuildingIds or {}) do
|
||||
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
||||
if building ~= nil and building.unloadMarker ~= nil then
|
||||
@@ -485,7 +485,7 @@ end
|
||||
|
||||
-- Alle varer målet tager (uanset vogn) — afkrydsningslisten i GUI'et. {index, name, title}, sorteret på titel.
|
||||
function ADRunsController.getTargetAcceptedFillTypes(adEnv, run)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local stations = getTargetStations(adEnv, run, farmId)
|
||||
if #stations == 0 then
|
||||
return {}
|
||||
@@ -615,7 +615,7 @@ function ADRunsController.resolveMarkers(adEnv, run)
|
||||
if ADBuildings == nil or run == nil then
|
||||
return {missing = missing}
|
||||
end
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local role = run.kind == "outbound" and "load" or "unload"
|
||||
local buildingIds = run.kind == "outbound" and run.sourceBuildingIds or run.targetBuildingIds
|
||||
local existing = run.kind == "outbound" and run.sourceWayPointIds or ADRunsController.getRunTargets(run)
|
||||
@@ -709,7 +709,7 @@ function ADRunsController.migrateBuildings(adEnv)
|
||||
if ADBuildings == nil then
|
||||
return
|
||||
end
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, run in ipairs(ADRunsController.store.runs) do
|
||||
local role = run.kind == "outbound" and "load" or "unload"
|
||||
local ids = copyList(run.kind == "outbound" and run.sourceBuildingIds or run.targetBuildingIds)
|
||||
@@ -734,7 +734,7 @@ end
|
||||
|
||||
-- Data til én række i flow-tavlen (GUI'et formaterer teksten).
|
||||
function ADRunsController.getFlowRow(adEnv, run)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local row = {productNames = {}, productAuto = false, fromNames = {}, toNames = {}, fromAllSilos = run.kind ~= "outbound", missing = {}, policies = {}, vehicleNames = {}, collectRound = run.collectRound == true, sellAtPercent = run.sellAtPercent, storeAbovePercent = run.storeAbovePercent, loops = run.loops, kind = run.kind}
|
||||
local ids = run.kind == "outbound" and run.sourceBuildingIds or run.targetBuildingIds
|
||||
local names = run.kind == "outbound" and row.fromNames or row.toNames
|
||||
@@ -862,7 +862,7 @@ end
|
||||
-- Alle varer kilderne rummer/producerer med run'ets politik (uanset vogn) — til fanen Udkørsel.
|
||||
-- {fillType, name, title, policy, isPallet, available, level, capacity}, sorteret på titel.
|
||||
function ADRunsController.getRunProducts(adEnv, run, includeEmpty)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local byName, result = {}, {}
|
||||
for _, source in ipairs(getRunSources(adEnv, run, farmId)) do
|
||||
for _, item in ipairs(ADSources.getProducts(adEnv, source, farmId, includeEmpty)) do
|
||||
@@ -1745,7 +1745,7 @@ end
|
||||
-- Niveauer pr. mål for run'ets varer: {{wayPointId, name, levels = {{fillType, level, capacity, free}}}}
|
||||
-- i samme rangering som valget bruger (trug som én trang, fodervægt som prioritet); fulde sidst.
|
||||
function ADRunsController.getTargetsLevels(adEnv, run)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local fillTypes = {}
|
||||
if run.ingredientMode == "manual" then
|
||||
for _, name in ipairs(run.ingredients) do
|
||||
|
||||
@@ -10,6 +10,9 @@ ADRunsStorage.LOG_PREFIX = "ADSmartPickup: "
|
||||
|
||||
-- Samme opslag som AutoDrive.getXMLFile_new: mappen kendes efter første gem, ellers via indeks.
|
||||
function ADRunsStorage.getPath()
|
||||
-- multiplayer-klient: serveren ejer modens data; en klient må aldrig skrive (fallback-stien ville ramme spillerens
|
||||
-- egen lokale savegameN med samme nummer). Alle modens filer går gennem denne sti (ADUtil.savePath).
|
||||
if ADUtil ~= nil and ADUtil.isMpClient() then return nil end
|
||||
local info = g_currentMission ~= nil and g_currentMission.missionInfo or nil
|
||||
if info == nil then
|
||||
return nil
|
||||
|
||||
@@ -575,7 +575,7 @@ end
|
||||
local function plan(adEnv)
|
||||
if ADSettings == nil or ADSettings.get("autoSalt") ~= 1 then return end
|
||||
if not ADSaltRoute.shouldStart(snowHeight(), ADSaltRoute.lastDone, currentDay()) then return end
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local spreaders = findSpreaders(adEnv, farmId)
|
||||
if #spreaders == 0 then
|
||||
warnOnce("noSpreader", "der ligger sne, men ingen ledig saltspreder (købt, med P-plads og Connect-markør) — der saltes ikke")
|
||||
|
||||
@@ -74,7 +74,7 @@ end
|
||||
-- Alle salgssteder med AD-markør -> {{id, names}} (markørens navn først: det spilleren ser i AutoDrive).
|
||||
local function sellStations(adEnv)
|
||||
local list, byId = {}, {}
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do
|
||||
local station = ADSmartPickup.getUnloadStationAtWayPointId(adEnv, marker.id, farmId)
|
||||
local id = station ~= nil and ADPrices.isSellingStation(station) and stationId(station) or nil
|
||||
|
||||
@@ -13,6 +13,10 @@ ADSettings.LOG_PREFIX = "ADSmartPickup: indstilling: "
|
||||
|
||||
-- nøgle -> {default, min, max, text}. Nye indstillinger tilføjes her, så de får standardværdi, grænser og hjælpetekst.
|
||||
ADSettings.KEYS = {
|
||||
-- dedikeret server (multiplayer): gården ADSmartPickup kører for; 0 = automatisk (gården med flest AD-køretøjer).
|
||||
-- Uden valg-liste, så den ikke står i indstillingsfanen; sættes i singleplayer med spuSet serverFarmId 2 (gemmes i
|
||||
-- ADSmartPickup_settings.xml og følger savegamet over på serveren) eller direkte i den fil
|
||||
serverFarmId = {default = 0, min = 0, max = 16, text = "dedikeret server: gården ADSmartPickup kører for (0 = automatisk)"},
|
||||
stableSiloRange = {default = 80, min = 10, max = 500, perBuilding = true, choices = {40, 60, 80, 100, 120, 150, 200, 300}, format = "%s m",
|
||||
text = "m: en silo inden for denne afstand af en stald er staldens egen silo (forsyning henter der først)"},
|
||||
waitHomeMinutes = {default = 0, min = 0, max = 240, perBuilding = true, choices = {0, 5, 10, 15, 20, 30, 45, 60, 90, 120}, format = "%s min",
|
||||
@@ -228,10 +232,10 @@ local function findBuilding(name)
|
||||
local adEnv = ADFieldSilos ~= nil and ADFieldSilos.adEnv or nil
|
||||
if adEnv == nil or ADBuildings == nil or g_currentMission == nil then return nil end
|
||||
local wanted = string.lower(name)
|
||||
for _, building in ipairs(ADBuildings.list(adEnv, g_currentMission:getFarmId()) or {}) do
|
||||
for _, building in ipairs(ADBuildings.list(adEnv, ADUtil.farmId()) or {}) do
|
||||
if string.lower(tostring(building.name)) == wanted then return building end
|
||||
end
|
||||
for _, building in ipairs(ADBuildings.list(adEnv, g_currentMission:getFarmId()) or {}) do
|
||||
for _, building in ipairs(ADBuildings.list(adEnv, ADUtil.farmId()) or {}) do
|
||||
if string.find(string.lower(tostring(building.name)), wanted, 1, true) then return building end
|
||||
end
|
||||
return nil
|
||||
|
||||
@@ -1993,11 +1993,21 @@ function ADSmartPickup:loadMap()
|
||||
end
|
||||
end
|
||||
|
||||
-- Multiplayer etape 1: al automatik og indlæsning/gemning kun på serveren (den har AD/CP og køretøjerne). Singleplayer
|
||||
-- og værten er server; en MP-klient viser kun HUD'en (status fra serveren kommer i etape 2).
|
||||
function ADSmartPickup.isServer()
|
||||
return ADUtil.isServer()
|
||||
end
|
||||
|
||||
function ADSmartPickup:update(dt)
|
||||
if ADProfiler ~= nil and ADProfiler.installed then
|
||||
local now = ADProfiler.clock()
|
||||
if now ~= nil then pcall(ADProfiler.frame, now) end
|
||||
end
|
||||
if not ADSmartPickup.isServer() then
|
||||
if ADStatusHud ~= nil then pcall(ADStatusHud.update, dt, getAutoDriveEnv()) end
|
||||
return
|
||||
end
|
||||
if not isHooked then
|
||||
local adEnv = getAutoDriveEnv()
|
||||
if adEnv ~= nil and g_currentMission ~= nil and g_currentMission.storageSystem ~= nil then
|
||||
|
||||
@@ -514,7 +514,7 @@ local function getSiloProducts(source, includeEmpty)
|
||||
-- storageRadius: tanken selv kan være tom mens puljen er fuld. Læssestationens tal er det man kan hente.
|
||||
local station = source.station
|
||||
if station ~= nil and station.getAllFillLevels ~= nil then
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
local farmId = ADUtil.farmId()
|
||||
local ok, pooled, pooledCapacity = pcall(station.getAllFillLevels, station, farmId)
|
||||
if ok and type(pooled) == "table" then
|
||||
for fillType, level in pairs(pooled) do
|
||||
@@ -631,7 +631,7 @@ end
|
||||
|
||||
local function getHusbandryProducts(adEnv, source)
|
||||
local placeable, station = source.placeable, source.station
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
local farmId = ADUtil.farmId()
|
||||
if station == nil then
|
||||
-- kilde via staldens pallespawner (hønsehus: æg): kun pallevarerne
|
||||
return getHusbandryPalletProducts(source, farmId)
|
||||
@@ -656,7 +656,7 @@ local function getHusbandryProducts(adEnv, source)
|
||||
-- en siloExtension inden for storageRadius). getHusbandryFillLevel ser kun staldens egen beholder.
|
||||
local stationLevels = nil
|
||||
if station ~= nil and station.getAllFillLevels ~= nil then
|
||||
local ok, levels = pcall(station.getAllFillLevels, station, g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1)
|
||||
local ok, levels = pcall(station.getAllFillLevels, station, ADUtil.farmId())
|
||||
if ok and type(levels) == "table" then stationLevels = levels end
|
||||
end
|
||||
local products = {}
|
||||
@@ -678,7 +678,7 @@ local function getStationProducts(source)
|
||||
if station == nil or station.getAllFillLevels == nil then
|
||||
return {}
|
||||
end
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
||||
local farmId = ADUtil.farmId()
|
||||
local ok, levels, capacity = pcall(station.getAllFillLevels, station, farmId)
|
||||
if not ok or type(levels) ~= "table" then
|
||||
return {}
|
||||
@@ -1530,7 +1530,7 @@ local function getHusbandryStationLevels(placeable)
|
||||
if storage == nil or storage.getLoadingStations == nil then return result end
|
||||
for _, station in pairs(storage:getLoadingStations()) do
|
||||
if station.owningPlaceable == placeable and station.getAllFillLevels ~= nil then
|
||||
local ok, levels = pcall(station.getAllFillLevels, station, g_currentMission:getFarmId())
|
||||
local ok, levels = pcall(station.getAllFillLevels, station, ADUtil.farmId())
|
||||
for fillType, level in pairs(ok and type(levels) == "table" and levels or {}) do
|
||||
result[fillType] = math.max(result[fillType] or 0, level or 0)
|
||||
end
|
||||
|
||||
@@ -285,7 +285,7 @@ end
|
||||
function ADStatusHud.stuckEntries()
|
||||
local entries = {}
|
||||
if ADStuckDiag == nil or ADStuckDiag.stillVehicles == nil then return entries end
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or nil
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, still in ipairs(ADStuckDiag.stillVehicles(ADStatusHud.STUCK_WARN_MS)) do
|
||||
local vehicle = still.vehicle
|
||||
local owned = not isGone(vehicle) and (farmId == nil or (vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() == farmId))
|
||||
|
||||
@@ -108,7 +108,7 @@ function ADStrayUnload.tick(adEnv, dt)
|
||||
timerMs = 0
|
||||
if adEnv == nil or ADUnloadWait == nil or ADFlowWagons == nil or ADRunsController == nil or ADSmartPickup == nil then return end
|
||||
local minutes = ADSettings ~= nil and ADSettings.get("strayFullMinutes") or 5
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or nil
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, vehicle in pairs(g_currentMission.vehicleSystem.vehicles or {}) do
|
||||
local mine = farmId == nil or (vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() == farmId)
|
||||
local ok, stuck, targetName, rest, fillType, targetId = false, false, nil, nil, nil, nil
|
||||
|
||||
@@ -452,7 +452,7 @@ local function updateWaiting(adEnv, task, wait, dt)
|
||||
wait.isRejected = isRejected
|
||||
-- ventetid ved Wait (ADSettings "waitHomeMinutes", pr. stald): udløbet -> resten køres hjem i gårdens lager
|
||||
wait.waitedMs = (wait.waitedMs or 0) + (dt or 0)
|
||||
local homeBuilding = ADBuildings ~= nil and ADBuildings.byMarker ~= nil and ADBuildings.byMarker(adEnv, g_currentMission:getFarmId(), home, "unload") or nil
|
||||
local homeBuilding = ADBuildings ~= nil and ADBuildings.byMarker ~= nil and ADBuildings.byMarker(adEnv, ADUtil.farmId(), home, "unload") or nil
|
||||
local waitMinutes = ADSettings ~= nil and ADSettings.get("waitHomeMinutes", homeBuilding ~= nil and homeBuilding.id or nil) or 0
|
||||
if ADUnloadWait.waitHomeDue(wait.waitedMs, waitMinutes) and ADLoadSwap ~= nil and ADLoadSwap.findDumpMarker ~= nil then
|
||||
local marker = ADLoadSwap.findDumpMarker(adEnv, vehicle, fillType, rest, home, function(markerId) return hasRouteTo(adEnv, vehicle, markerId) end)
|
||||
|
||||
@@ -7,6 +7,58 @@ local function logInfo(...) return (ADLog or Logging).info(...) end
|
||||
|
||||
ADUtil = {}
|
||||
|
||||
-- Gården ADSmartPickup kører for (multiplayer etape 1; én fælles gård, brugerens valg 25/10). Med lokal spiller
|
||||
-- (singleplayer/vært) spillerens gård. På en dedikeret server er der ingen spiller (tilskuer-gården): så den
|
||||
-- indstillede gård (serverFarmId), ellers gården med flest AutoDrive-køretøjer, ellers 1.
|
||||
-- Server/klient (multiplayer): singleplayer og værten er server; en MP-klient er klient uden server.
|
||||
function ADUtil.isServer() return g_server ~= nil end
|
||||
function ADUtil.isMpClient() return g_client ~= nil and g_server == nil end
|
||||
|
||||
ADUtil.FARM_CACHE_MS = 60000
|
||||
local farmCache = {id = nil, atMs = -math.huge}
|
||||
|
||||
function ADUtil.resetFarmCache() farmCache = {id = nil, atMs = -math.huge} end
|
||||
|
||||
function ADUtil.configuredFarmId()
|
||||
local value = ADSettings ~= nil and ADSettings.get ~= nil and tonumber(ADSettings.get("serverFarmId")) or 0
|
||||
return math.floor(value)
|
||||
end
|
||||
|
||||
local function spectatorFarmId()
|
||||
return FarmManager ~= nil and FarmManager.SPECTATOR_FARM_ID or 0
|
||||
end
|
||||
|
||||
local function dominantFarmId()
|
||||
local counts, best, bestCount = {}, nil, 0
|
||||
local system = g_currentMission ~= nil and g_currentMission.vehicleSystem or nil
|
||||
for _, vehicle in ipairs(system ~= nil and system.vehicles or {}) do
|
||||
if vehicle.ad ~= nil and vehicle.getOwnerFarmId ~= nil then
|
||||
local farm = vehicle:getOwnerFarmId()
|
||||
if farm ~= nil and farm ~= spectatorFarmId() then
|
||||
counts[farm] = (counts[farm] or 0) + 1
|
||||
if counts[farm] > bestCount or (counts[farm] == bestCount and farm < best) then best, bestCount = farm, counts[farm] end
|
||||
end
|
||||
end
|
||||
end
|
||||
return best
|
||||
end
|
||||
|
||||
function ADUtil.farmId()
|
||||
local mission = g_currentMission
|
||||
if mission ~= nil and mission.getFarmId ~= nil then
|
||||
local own = mission:getFarmId()
|
||||
if own ~= nil and own ~= spectatorFarmId() then return own end
|
||||
end
|
||||
local configured = ADUtil.configuredFarmId()
|
||||
if configured ~= nil and configured > 0 then return configured end
|
||||
if mission == nil then return 1 end
|
||||
local nowMs = ADUtil.now()
|
||||
if farmCache.id == nil or nowMs - farmCache.atMs > ADUtil.FARM_CACHE_MS or nowMs < farmCache.atMs then
|
||||
farmCache = {id = dominantFarmId() or 1, atMs = nowMs}
|
||||
end
|
||||
return farmCache.id
|
||||
end
|
||||
|
||||
-- Spiltid i ms (g_currentMission.time); uden spil (tests) processorens tid.
|
||||
function ADUtil.now()
|
||||
if g_currentMission ~= nil and type(g_currentMission.time) == "number" then return g_currentMission.time end
|
||||
|
||||
@@ -64,7 +64,7 @@ end
|
||||
-- Siloer der tager markens vare: marksilo først, gæringssiloer, så de nærmeste (samme regel som før).
|
||||
function SmartPickupFrame:fieldStoreContext(adEnv, info, plan, chosenIds)
|
||||
local fillType = fieldFillType(info, plan)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local fieldSilos, silosById = {}, {}
|
||||
for _, building in ipairs(ADFields.fieldSilos(adEnv, farmId, info)) do
|
||||
local markers = ADBuildings.getMarkers ~= nil and ADBuildings.getMarkers(building, "unload") or {}
|
||||
|
||||
@@ -83,7 +83,7 @@ function SmartPickupFrame:fillFieldSiloRows(adEnv)
|
||||
end
|
||||
|
||||
self:addTextRow(i18n:getText("spu_fs_storesTitle"))
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
for _, building in ipairs(ADBuildings.list(adEnv, farmId)) do
|
||||
if building.kind == "silo" then
|
||||
local option = self:addToggleRow("fsStore", ADBuildings.labelWithPlace(building), onOff, ADFieldSiloConfig.hasStore(cfg, building.id))
|
||||
|
||||
@@ -398,7 +398,7 @@ end
|
||||
function SmartPickupFrame:onAutoAllResult(yes)
|
||||
self:safe(function(frame)
|
||||
if not yes then return end
|
||||
local result = ADAutoCrop.applyAll(g_currentMission:getFarmId(), frame.getAdEnv(), {resetUser = frame.autoAllResetUser == true})
|
||||
local result = ADAutoCrop.applyAll(ADUtil.farmId(), frame.getAdEnv(), {resetUser = frame.autoAllResetUser == true})
|
||||
if result.scanning then
|
||||
frame.statusOverride = frame.i18n:getText("spu_field_autoAllScanning")
|
||||
frame.statusOverrideTicks = SmartPickupFrame.STATUS_OVERRIDE_TICKS
|
||||
|
||||
@@ -174,7 +174,7 @@ end
|
||||
-- og kan bære flowets varer. Bedste først (navnematch, så "Disponibel"). In-game 29/9: flowet kunne ikke oprettes
|
||||
-- uden at omdøbe en vogns parkering til flowets navn.
|
||||
function SmartPickupFrame:flowWagonContext(adEnv, preview)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local markers = adEnv.ADGraphManager:getMapMarkers()
|
||||
local wanted = flowFillTypes(adEnv, preview)
|
||||
local candidates = {}
|
||||
@@ -242,7 +242,7 @@ end
|
||||
|
||||
-- draft: kladden (eller selve run'et — samme feltnavne).
|
||||
function SmartPickupFrame:flowGuideContext(adEnv, draft)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local preview = ADFlowGuide.previewRun(draft, function(buildingId, role)
|
||||
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
||||
local ids = {}
|
||||
|
||||
@@ -14,7 +14,7 @@ SmartPickupFrame.SELL_MARKERS_CACHE_MS = 30000
|
||||
function SmartPickupFrame:getSellMarkersCached(adEnv)
|
||||
local time = g_time or (os.clock ~= nil and os.clock() * 1000) or 0
|
||||
if self.sellMarkersCache == nil or (time - (self.sellMarkersCacheTime or 0)) > SmartPickupFrame.SELL_MARKERS_CACHE_MS then
|
||||
self.sellMarkersCache = ADSources.getSellMarkers(adEnv, g_currentMission:getFarmId())
|
||||
self.sellMarkersCache = ADSources.getSellMarkers(adEnv, ADUtil.farmId())
|
||||
self.sellMarkersCacheTime = time
|
||||
end
|
||||
return self.sellMarkersCache
|
||||
|
||||
@@ -36,7 +36,7 @@ end
|
||||
-- silo). Fast rækkefølge også for ens navne (sted, så id — review)
|
||||
local function collectBarns(adEnv)
|
||||
local barns, animalBarns = {}, {}
|
||||
for _, building in ipairs(ADBuildings.list(adEnv, g_currentMission:getFarmId()) or {}) do
|
||||
for _, building in ipairs(ADBuildings.list(adEnv, ADUtil.farmId()) or {}) do
|
||||
if building.kind == "husbandry" then table.insert(barns, building) end
|
||||
if building.kind == "husbandry" or (building.placeable ~= nil and building.placeable.spec_husbandryAnimals ~= nil) then
|
||||
table.insert(animalBarns, building)
|
||||
|
||||
@@ -50,7 +50,7 @@ function SmartPickupFrame:getInventory(adEnv)
|
||||
if ADSources == nil or ADSources.getFarmInventory == nil then
|
||||
return {}
|
||||
end
|
||||
return ADSources.getFarmInventory(adEnv, g_currentMission:getFarmId())
|
||||
return ADSources.getFarmInventory(adEnv, ADUtil.farmId())
|
||||
end
|
||||
|
||||
-- ---- detaljer for den valgte bygning ----
|
||||
@@ -71,7 +71,7 @@ end
|
||||
|
||||
-- Beregner stats for alle varer i bygningen (gårdens totaler og rater regnes én gang pr. opdatering).
|
||||
function SmartPickupFrame:computeBuildingStats(adEnv, entry, inventory)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local totals = ADStorageStats.farmTotals(inventory)
|
||||
local rates = ADSources.getFarmRates ~= nil and ADSources.getFarmRates(adEnv, farmId) or {}
|
||||
local stats = {}
|
||||
@@ -120,7 +120,7 @@ end
|
||||
function SmartPickupFrame:storageLabels(inventory, adEnv)
|
||||
local counts, seen, labels = {}, {}, {}
|
||||
for _, entry in ipairs(inventory) do counts[entry.name] = (counts[entry.name] or 0) + 1 end
|
||||
local farmId = g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or nil
|
||||
local farmId = ADUtil.farmId()
|
||||
for index, entry in ipairs(inventory) do
|
||||
seen[entry.name] = (seen[entry.name] or 0) + 1
|
||||
local base = counts[entry.name] > 1 and string.format("%s #%d", entry.name, seen[entry.name]) or entry.name
|
||||
|
||||
@@ -77,7 +77,7 @@ end
|
||||
-- Fanens varer med statistik; gårdens totaler/kapacitet/rater regnes over HELE gården.
|
||||
function SmartPickupFrame:computeItemStats(adEnv, inventory, fullInventory)
|
||||
self.lastFullInventory = fullInventory -- til "kræver handling" -> flow (hvem bruger varen)
|
||||
local farmId = g_currentMission:getFarmId()
|
||||
local farmId = ADUtil.farmId()
|
||||
local totals = ADStorageStats.farmTotals(fullInventory)
|
||||
local capacities = ADStorageStats.farmCapacities(fullInventory)
|
||||
local rates = ADSources.getFarmRates ~= nil and ADSources.getFarmRates(adEnv, farmId) or {}
|
||||
|
||||
Reference in New Issue
Block a user