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 ADSettings == nil or ADSettings.get("autoAll") ~= 1 then return end
|
||||||
if not changed then return ADAutoCrop.tickNeeds(adEnv) end
|
if not changed then return ADAutoCrop.tickNeeds(adEnv) end
|
||||||
logInfo("ADSmartPickup: Alt automatisk: gårdens marker er ændret — planen laves om")
|
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
|
-- 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
|
if result == nil or result.failed ~= nil or result.scanning then
|
||||||
ADAutoCrop.knownFields = previous
|
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",
|
logInfo("ADSmartPickup: Alt automatisk: gårdens behov er ændret (%s -> %s) — planen laves om",
|
||||||
describeSignature(ADAutoCrop.knownNeeds), describeSignature(now))
|
describeSignature(ADAutoCrop.knownNeeds), describeSignature(now))
|
||||||
-- lykkes det ikke, står knownNeeds uændret, og der prøves igen ved næste tjek
|
-- 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
|
end
|
||||||
|
|||||||
@@ -1014,6 +1014,6 @@ function ADBuildings.tickDump(adEnv, dt)
|
|||||||
dumpState.done = true
|
dumpState.done = true
|
||||||
local path = getUserProfileAppPath ~= nil and (getUserProfileAppPath() .. "modSettings/FS25_ADSmartPickup/dumpTriggers.txt") or nil
|
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
|
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
|
if not ok then Logging.warning("ADSmartPickup: TRIGGER-dump fejlede: %s", tostring(err)) end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ end
|
|||||||
-- ---- evaluering ----
|
-- ---- evaluering ----
|
||||||
|
|
||||||
local function farmId()
|
local function farmId()
|
||||||
return g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
return ADUtil.farmId()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function plan(data, state)
|
local function plan(data, state)
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ local function start(adEnv, entry, enabled)
|
|||||||
if harvest and entry.mission ~= nil then
|
if harvest and entry.mission ~= nil then
|
||||||
-- høst: læssene skal til kontraktens salgssted (ADFieldWork.chooseStore)
|
-- høst: læssene skal til kontraktens salgssted (ADFieldWork.chooseStore)
|
||||||
local placeable, where, station = sellPlaceableOf(entry.mission)
|
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 {}
|
changes.contractSellIds = placeable ~= nil and sellMarkerIds(adEnv, placeable, farmId) or {}
|
||||||
-- uden AutoDrive-vej kører spillets hjælper læssene hertil (ADFieldWork beginUnloader)
|
-- uden AutoDrive-vej kører spillets hjælper læssene hertil (ADFieldWork beginUnloader)
|
||||||
changes.contractStation = station
|
changes.contractStation = station
|
||||||
@@ -289,7 +289,9 @@ function ADContracts.onAnswer(_, yes, entry)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function ask(entry)
|
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)
|
-- kan ikke spørge: rør den ikke (spilleren kan vælge "moden altid" under Indstillinger)
|
||||||
start(ADContracts.adEnv, entry, false)
|
start(ADContracts.adEnv, entry, false)
|
||||||
return
|
return
|
||||||
@@ -372,7 +374,7 @@ function ADContracts.tick(adEnv, nowMs)
|
|||||||
local decision = ADContracts.decision(ADSettings ~= nil and ADSettings.get("contracts") or nil)
|
local decision = ADContracts.decision(ADSettings ~= nil and ADSettings.get("contracts") or nil)
|
||||||
if lastScanAt ~= nil and nowMs - lastScanAt < ADContracts.SCAN_MS then return end
|
if lastScanAt ~= nil and nowMs - lastScanAt < ADContracts.SCAN_MS then return end
|
||||||
lastScanAt = nowMs
|
lastScanAt = nowMs
|
||||||
local farmId = g_currentMission ~= nil and g_currentMission:getFarmId() or nil
|
local farmId = ADUtil.farmId()
|
||||||
if farmId == nil then return end
|
if farmId == nil then return end
|
||||||
local okCollect, errCollect = pcall(collectFinished, farmId, nowMs)
|
local okCollect, errCollect = pcall(collectFinished, farmId, nowMs)
|
||||||
if not okCollect then Logging.warning("ADSmartPickup: indkassering af kontrakter: %s", tostring(errCollect)) end
|
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.
|
-- 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)
|
function ADFieldFertilizer.preferCandidate(farmId, areaHa)
|
||||||
if not ADFieldFertilizer.isEnabled() then return nil end
|
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 minStock = ADFieldWork ~= nil and ADFieldWork.MIN_REFILL_STOCK_L or 500
|
||||||
local share = ADFieldFertilizer.minSharePercent()
|
local share = ADFieldFertilizer.minSharePercent()
|
||||||
return function(candidate)
|
return function(candidate)
|
||||||
|
|||||||
@@ -956,7 +956,7 @@ function ADFieldJobs.tick(adEnv, dt)
|
|||||||
ADFieldJobs.timer = ADFieldJobs.timer + dt
|
ADFieldJobs.timer = ADFieldJobs.timer + dt
|
||||||
if ADFieldJobs.loaded then
|
if ADFieldJobs.loaded then
|
||||||
-- markscanningen kører et lille stykke HVERT frame (arbejdskø), aldrig en hel mark i ét frame
|
-- 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
|
if not okScan then Logging.warning(ADFieldJobs.LOG_PREFIX .. "markscanning: %s", tostring(errScan)) end
|
||||||
end
|
end
|
||||||
if ADFieldJobs.timer < ADFieldJobs.TICK_MS then return end
|
if ADFieldJobs.timer < ADFieldJobs.TICK_MS then return end
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ end
|
|||||||
-- ---- spil-input ----
|
-- ---- spil-input ----
|
||||||
|
|
||||||
local function farmId()
|
local function farmId()
|
||||||
return g_currentMission ~= nil and g_currentMission.getFarmId ~= nil and g_currentMission:getFarmId() or 1
|
return ADUtil.farmId()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function position(node)
|
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)
|
return (implement.width or 0) <= 0 or ADFieldModel.checkWidth(role, implement.width, required)
|
||||||
end
|
end
|
||||||
-- gylle som gødning gælder også puljens redskaber (in-game 17/10: MEGA valgt, Supercis stod klar i puljen)
|
-- 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,
|
local pair, why, args = ADPool.pairFor(role, info.x, info.z, implements, tractors, ADPool.blocked(now()), accept,
|
||||||
fertilizerPrefer(role, farmId, info))
|
fertilizerPrefer(role, farmId, info))
|
||||||
if pair == nil then
|
if pair == nil then
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ end
|
|||||||
|
|
||||||
function ADFleetNames.apply(adEnv)
|
function ADFleetNames.apply(adEnv)
|
||||||
local vehicles, byId, parkUse = {}, {}, {}
|
local vehicles, byId, parkUse = {}, {}, {}
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
for _, any in pairs(g_currentMission.vehicleSystem.vehicles) do
|
for _, any in pairs(g_currentMission.vehicleSystem.vehicles) do
|
||||||
local index = any.advd ~= nil and any.advd.parkDestination or nil
|
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
|
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 = {}
|
local taken = {}
|
||||||
for _, id in ipairs(ADRuns.wagonIdsOf(run)) do taken[id] = true end
|
for _, id in ipairs(ADRuns.wagonIdsOf(run)) do taken[id] = true end
|
||||||
local candidates = {}
|
local candidates = {}
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
for _, any in pairs(g_currentMission.vehicleSystem.vehicles) do
|
for _, any in pairs(g_currentMission.vehicleSystem.vehicles) do
|
||||||
local index = any.advd ~= nil and any.advd.parkDestination or nil
|
local index = any.advd ~= nil and any.advd.parkDestination or nil
|
||||||
local attached = any.getAttacherVehicle ~= nil and any:getAttacherVehicle() ~= nil
|
local attached = any.getAttacherVehicle ~= nil and any:getAttacherVehicle() ~= nil
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ end
|
|||||||
|
|
||||||
function ADLivestock.survey(adEnv)
|
function ADLivestock.survey(adEnv)
|
||||||
local lines = {}
|
local lines = {}
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local placeables = g_currentMission.placeableSystem ~= nil and g_currentMission.placeableSystem.placeables or {}
|
local placeables = g_currentMission.placeableSystem ~= nil and g_currentMission.placeableSystem.placeables or {}
|
||||||
for _, placeable in ipairs(placeables) do
|
for _, placeable in ipairs(placeables) do
|
||||||
local okPlaceable, errPlaceable = pcall(function()
|
local okPlaceable, errPlaceable = pcall(function()
|
||||||
@@ -921,7 +921,7 @@ function ADLivestock.load()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function planJobs(adEnv)
|
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
|
-- 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
|
-- 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)
|
-- ved gemningen (spilleren har ikke sat sine egne ind)
|
||||||
|
|||||||
@@ -1131,7 +1131,7 @@ local function describeLoadFailure(adEnv, vehicle, task, state, source)
|
|||||||
local parts = {}
|
local parts = {}
|
||||||
local marker = adEnv.ADGraphManager.getMapMarkerByWayPointId ~= nil and adEnv.ADGraphManager:getMapMarkerByWayPointId(state.current) or nil
|
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)))
|
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 = {}
|
local wanted = {}
|
||||||
for _, fillType in ipairs(state.trip.fillTypes) do wanted[fillType] = true end
|
for _, fillType in ipairs(state.trip.fillTypes) do wanted[fillType] = true end
|
||||||
for _, item in ipairs(ok and products or {}) do
|
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
|
-- 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.
|
-- 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 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
|
local best, bestD, parkedExists = nil, nil, false
|
||||||
for _, vehicle in pairs(g_currentMission.vehicleSystem.vehicles) do
|
for _, vehicle in pairs(g_currentMission.vehicleSystem.vehicles) do
|
||||||
local owned = vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() == farmId
|
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).
|
-- isBusy(vehicle): markarbejdets optaget-regel (opgave, AD/CP kører, lånt af marksilo, på hjemtur).
|
||||||
function ADPool.collect(adEnv, isBusy)
|
function ADPool.collect(adEnv, isBusy)
|
||||||
local markers = adEnv.ADGraphManager:getMapMarkers()
|
local markers = adEnv.ADGraphManager:getMapMarkers()
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local implements, tractors = {}, {}
|
local implements, tractors = {}, {}
|
||||||
local targeted = connectTargets(adEnv)
|
local targeted = connectTargets(adEnv)
|
||||||
-- spillets egen liste: frakoblede redskaber er ikke nødvendigvis i AutoDrive's køretøjsliste
|
-- 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.
|
-- spilleren kan se hvorfor) og alle traktorer uden egen arbejdsrolle, der ikke hører til et flow.
|
||||||
function ADPool.overview(adEnv)
|
function ADPool.overview(adEnv)
|
||||||
local markers = adEnv.ADGraphManager:getMapMarkers()
|
local markers = adEnv.ADGraphManager:getMapMarkers()
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local nowMs = ADFieldJobs.now or 0
|
local nowMs = ADFieldJobs.now or 0
|
||||||
local implements, tractors = {}, {}
|
local implements, tractors = {}, {}
|
||||||
for _, vehicle in pairs(g_currentMission.vehicleSystem.vehicles) do
|
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).
|
-- Spillerens gård ejer placeablen; ukendt ejer = regnes som egen (afleveringer til egne anlæg er ikke salg).
|
||||||
function ADPrices.isOwnedByPlayer(placeable)
|
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
|
if getOwner(placeable) == nil then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function ADRunsController.getVehicleId(vehicle)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ADRunsController.getFarmVehicles(adEnv)
|
function ADRunsController.getFarmVehicles(adEnv)
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local result = {}
|
local result = {}
|
||||||
for _, vehicle in pairs(adEnv.AutoDrive.getAllVehicles()) do
|
for _, vehicle in pairs(adEnv.AutoDrive.getAllVehicles()) do
|
||||||
-- kun motoriserede (traktorer, høstere); AD-spec'en sidder også på redskaber
|
-- 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
|
if building.unloadMarker == nil or ADLoadSwap == nil or ADLoadSwap.isStoreTarget == nil then
|
||||||
return false
|
return false
|
||||||
end
|
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)
|
local station = ADSmartPickup.getUnloadStationAtWayPointId(adEnv, building.unloadMarker.id, farmId)
|
||||||
if station == nil then
|
if station == nil then
|
||||||
return false
|
return false
|
||||||
@@ -215,7 +215,7 @@ end
|
|||||||
function ADRunsController.getStoreBuildings(adEnv, run)
|
function ADRunsController.getStoreBuildings(adEnv, run)
|
||||||
local result = {}
|
local result = {}
|
||||||
if ADBuildings == nil or run == nil then return result end
|
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
|
for _, buildingId in ipairs(run.storeBuildingIds or {}) do
|
||||||
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
||||||
if building ~= nil then table.insert(result, building) end
|
if building ~= nil then table.insert(result, building) end
|
||||||
@@ -227,7 +227,7 @@ end
|
|||||||
function ADRunsController.getFeedBuildings(adEnv, run)
|
function ADRunsController.getFeedBuildings(adEnv, run)
|
||||||
local result = {}
|
local result = {}
|
||||||
if ADBuildings == nil or run == nil then return result end
|
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
|
for _, buildingId in ipairs(run.feedBuildingIds or {}) do
|
||||||
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
||||||
if building ~= nil then table.insert(result, building) end
|
if building ~= nil then table.insert(result, building) end
|
||||||
@@ -239,7 +239,7 @@ end
|
|||||||
function ADRunsController.getStoreMarkers(adEnv, run)
|
function ADRunsController.getStoreMarkers(adEnv, run)
|
||||||
local result = {}
|
local result = {}
|
||||||
if ADBuildings == nil or run == nil then return result end
|
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
|
for _, buildingId in ipairs(run.storeBuildingIds or {}) do
|
||||||
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
||||||
if building ~= nil and building.unloadMarker ~= nil then
|
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.
|
-- Alle varer målet tager (uanset vogn) — afkrydsningslisten i GUI'et. {index, name, title}, sorteret på titel.
|
||||||
function ADRunsController.getTargetAcceptedFillTypes(adEnv, run)
|
function ADRunsController.getTargetAcceptedFillTypes(adEnv, run)
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local stations = getTargetStations(adEnv, run, farmId)
|
local stations = getTargetStations(adEnv, run, farmId)
|
||||||
if #stations == 0 then
|
if #stations == 0 then
|
||||||
return {}
|
return {}
|
||||||
@@ -615,7 +615,7 @@ function ADRunsController.resolveMarkers(adEnv, run)
|
|||||||
if ADBuildings == nil or run == nil then
|
if ADBuildings == nil or run == nil then
|
||||||
return {missing = missing}
|
return {missing = missing}
|
||||||
end
|
end
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local role = run.kind == "outbound" and "load" or "unload"
|
local role = run.kind == "outbound" and "load" or "unload"
|
||||||
local buildingIds = run.kind == "outbound" and run.sourceBuildingIds or run.targetBuildingIds
|
local buildingIds = run.kind == "outbound" and run.sourceBuildingIds or run.targetBuildingIds
|
||||||
local existing = run.kind == "outbound" and run.sourceWayPointIds or ADRunsController.getRunTargets(run)
|
local existing = run.kind == "outbound" and run.sourceWayPointIds or ADRunsController.getRunTargets(run)
|
||||||
@@ -709,7 +709,7 @@ function ADRunsController.migrateBuildings(adEnv)
|
|||||||
if ADBuildings == nil then
|
if ADBuildings == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
for _, run in ipairs(ADRunsController.store.runs) do
|
for _, run in ipairs(ADRunsController.store.runs) do
|
||||||
local role = run.kind == "outbound" and "load" or "unload"
|
local role = run.kind == "outbound" and "load" or "unload"
|
||||||
local ids = copyList(run.kind == "outbound" and run.sourceBuildingIds or run.targetBuildingIds)
|
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).
|
-- Data til én række i flow-tavlen (GUI'et formaterer teksten).
|
||||||
function ADRunsController.getFlowRow(adEnv, run)
|
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 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 ids = run.kind == "outbound" and run.sourceBuildingIds or run.targetBuildingIds
|
||||||
local names = run.kind == "outbound" and row.fromNames or row.toNames
|
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.
|
-- 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.
|
-- {fillType, name, title, policy, isPallet, available, level, capacity}, sorteret på titel.
|
||||||
function ADRunsController.getRunProducts(adEnv, run, includeEmpty)
|
function ADRunsController.getRunProducts(adEnv, run, includeEmpty)
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local byName, result = {}, {}
|
local byName, result = {}, {}
|
||||||
for _, source in ipairs(getRunSources(adEnv, run, farmId)) do
|
for _, source in ipairs(getRunSources(adEnv, run, farmId)) do
|
||||||
for _, item in ipairs(ADSources.getProducts(adEnv, source, farmId, includeEmpty)) 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}}}}
|
-- 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.
|
-- i samme rangering som valget bruger (trug som én trang, fodervægt som prioritet); fulde sidst.
|
||||||
function ADRunsController.getTargetsLevels(adEnv, run)
|
function ADRunsController.getTargetsLevels(adEnv, run)
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local fillTypes = {}
|
local fillTypes = {}
|
||||||
if run.ingredientMode == "manual" then
|
if run.ingredientMode == "manual" then
|
||||||
for _, name in ipairs(run.ingredients) do
|
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.
|
-- Samme opslag som AutoDrive.getXMLFile_new: mappen kendes efter første gem, ellers via indeks.
|
||||||
function ADRunsStorage.getPath()
|
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
|
local info = g_currentMission ~= nil and g_currentMission.missionInfo or nil
|
||||||
if info == nil then
|
if info == nil then
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -575,7 +575,7 @@ end
|
|||||||
local function plan(adEnv)
|
local function plan(adEnv)
|
||||||
if ADSettings == nil or ADSettings.get("autoSalt") ~= 1 then return end
|
if ADSettings == nil or ADSettings.get("autoSalt") ~= 1 then return end
|
||||||
if not ADSaltRoute.shouldStart(snowHeight(), ADSaltRoute.lastDone, currentDay()) 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)
|
local spreaders = findSpreaders(adEnv, farmId)
|
||||||
if #spreaders == 0 then
|
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")
|
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).
|
-- Alle salgssteder med AD-markør -> {{id, names}} (markørens navn først: det spilleren ser i AutoDrive).
|
||||||
local function sellStations(adEnv)
|
local function sellStations(adEnv)
|
||||||
local list, byId = {}, {}
|
local list, byId = {}, {}
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do
|
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do
|
||||||
local station = ADSmartPickup.getUnloadStationAtWayPointId(adEnv, marker.id, farmId)
|
local station = ADSmartPickup.getUnloadStationAtWayPointId(adEnv, marker.id, farmId)
|
||||||
local id = station ~= nil and ADPrices.isSellingStation(station) and stationId(station) or nil
|
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.
|
-- nøgle -> {default, min, max, text}. Nye indstillinger tilføjes her, så de får standardværdi, grænser og hjælpetekst.
|
||||||
ADSettings.KEYS = {
|
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",
|
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)"},
|
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",
|
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
|
local adEnv = ADFieldSilos ~= nil and ADFieldSilos.adEnv or nil
|
||||||
if adEnv == nil or ADBuildings == nil or g_currentMission == nil then return nil end
|
if adEnv == nil or ADBuildings == nil or g_currentMission == nil then return nil end
|
||||||
local wanted = string.lower(name)
|
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
|
if string.lower(tostring(building.name)) == wanted then return building end
|
||||||
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
|
if string.find(string.lower(tostring(building.name)), wanted, 1, true) then return building end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1993,11 +1993,21 @@ function ADSmartPickup:loadMap()
|
|||||||
end
|
end
|
||||||
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)
|
function ADSmartPickup:update(dt)
|
||||||
if ADProfiler ~= nil and ADProfiler.installed then
|
if ADProfiler ~= nil and ADProfiler.installed then
|
||||||
local now = ADProfiler.clock()
|
local now = ADProfiler.clock()
|
||||||
if now ~= nil then pcall(ADProfiler.frame, now) end
|
if now ~= nil then pcall(ADProfiler.frame, now) end
|
||||||
end
|
end
|
||||||
|
if not ADSmartPickup.isServer() then
|
||||||
|
if ADStatusHud ~= nil then pcall(ADStatusHud.update, dt, getAutoDriveEnv()) end
|
||||||
|
return
|
||||||
|
end
|
||||||
if not isHooked then
|
if not isHooked then
|
||||||
local adEnv = getAutoDriveEnv()
|
local adEnv = getAutoDriveEnv()
|
||||||
if adEnv ~= nil and g_currentMission ~= nil and g_currentMission.storageSystem ~= nil then
|
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.
|
-- storageRadius: tanken selv kan være tom mens puljen er fuld. Læssestationens tal er det man kan hente.
|
||||||
local station = source.station
|
local station = source.station
|
||||||
if station ~= nil and station.getAllFillLevels ~= nil then
|
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)
|
local ok, pooled, pooledCapacity = pcall(station.getAllFillLevels, station, farmId)
|
||||||
if ok and type(pooled) == "table" then
|
if ok and type(pooled) == "table" then
|
||||||
for fillType, level in pairs(pooled) do
|
for fillType, level in pairs(pooled) do
|
||||||
@@ -631,7 +631,7 @@ end
|
|||||||
|
|
||||||
local function getHusbandryProducts(adEnv, source)
|
local function getHusbandryProducts(adEnv, source)
|
||||||
local placeable, station = source.placeable, source.station
|
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
|
if station == nil then
|
||||||
-- kilde via staldens pallespawner (hønsehus: æg): kun pallevarerne
|
-- kilde via staldens pallespawner (hønsehus: æg): kun pallevarerne
|
||||||
return getHusbandryPalletProducts(source, farmId)
|
return getHusbandryPalletProducts(source, farmId)
|
||||||
@@ -656,7 +656,7 @@ local function getHusbandryProducts(adEnv, source)
|
|||||||
-- en siloExtension inden for storageRadius). getHusbandryFillLevel ser kun staldens egen beholder.
|
-- en siloExtension inden for storageRadius). getHusbandryFillLevel ser kun staldens egen beholder.
|
||||||
local stationLevels = nil
|
local stationLevels = nil
|
||||||
if station ~= nil and station.getAllFillLevels ~= nil then
|
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
|
if ok and type(levels) == "table" then stationLevels = levels end
|
||||||
end
|
end
|
||||||
local products = {}
|
local products = {}
|
||||||
@@ -678,7 +678,7 @@ local function getStationProducts(source)
|
|||||||
if station == nil or station.getAllFillLevels == nil then
|
if station == nil or station.getAllFillLevels == nil then
|
||||||
return {}
|
return {}
|
||||||
end
|
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)
|
local ok, levels, capacity = pcall(station.getAllFillLevels, station, farmId)
|
||||||
if not ok or type(levels) ~= "table" then
|
if not ok or type(levels) ~= "table" then
|
||||||
return {}
|
return {}
|
||||||
@@ -1530,7 +1530,7 @@ local function getHusbandryStationLevels(placeable)
|
|||||||
if storage == nil or storage.getLoadingStations == nil then return result end
|
if storage == nil or storage.getLoadingStations == nil then return result end
|
||||||
for _, station in pairs(storage:getLoadingStations()) do
|
for _, station in pairs(storage:getLoadingStations()) do
|
||||||
if station.owningPlaceable == placeable and station.getAllFillLevels ~= nil then
|
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
|
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)
|
result[fillType] = math.max(result[fillType] or 0, level or 0)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ end
|
|||||||
function ADStatusHud.stuckEntries()
|
function ADStatusHud.stuckEntries()
|
||||||
local entries = {}
|
local entries = {}
|
||||||
if ADStuckDiag == nil or ADStuckDiag.stillVehicles == nil then return entries end
|
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
|
for _, still in ipairs(ADStuckDiag.stillVehicles(ADStatusHud.STUCK_WARN_MS)) do
|
||||||
local vehicle = still.vehicle
|
local vehicle = still.vehicle
|
||||||
local owned = not isGone(vehicle) and (farmId == nil or (vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() == farmId))
|
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
|
timerMs = 0
|
||||||
if adEnv == nil or ADUnloadWait == nil or ADFlowWagons == nil or ADRunsController == nil or ADSmartPickup == nil then return end
|
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 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
|
for _, vehicle in pairs(g_currentMission.vehicleSystem.vehicles or {}) do
|
||||||
local mine = farmId == nil or (vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() == farmId)
|
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
|
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
|
wait.isRejected = isRejected
|
||||||
-- ventetid ved Wait (ADSettings "waitHomeMinutes", pr. stald): udløbet -> resten køres hjem i gårdens lager
|
-- 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)
|
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
|
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
|
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)
|
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 = {}
|
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.
|
-- Spiltid i ms (g_currentMission.time); uden spil (tests) processorens tid.
|
||||||
function ADUtil.now()
|
function ADUtil.now()
|
||||||
if g_currentMission ~= nil and type(g_currentMission.time) == "number" then return g_currentMission.time end
|
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).
|
-- 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)
|
function SmartPickupFrame:fieldStoreContext(adEnv, info, plan, chosenIds)
|
||||||
local fillType = fieldFillType(info, plan)
|
local fillType = fieldFillType(info, plan)
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local fieldSilos, silosById = {}, {}
|
local fieldSilos, silosById = {}, {}
|
||||||
for _, building in ipairs(ADFields.fieldSilos(adEnv, farmId, info)) do
|
for _, building in ipairs(ADFields.fieldSilos(adEnv, farmId, info)) do
|
||||||
local markers = ADBuildings.getMarkers ~= nil and ADBuildings.getMarkers(building, "unload") or {}
|
local markers = ADBuildings.getMarkers ~= nil and ADBuildings.getMarkers(building, "unload") or {}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ function SmartPickupFrame:fillFieldSiloRows(adEnv)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self:addTextRow(i18n:getText("spu_fs_storesTitle"))
|
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
|
for _, building in ipairs(ADBuildings.list(adEnv, farmId)) do
|
||||||
if building.kind == "silo" then
|
if building.kind == "silo" then
|
||||||
local option = self:addToggleRow("fsStore", ADBuildings.labelWithPlace(building), onOff, ADFieldSiloConfig.hasStore(cfg, building.id))
|
local option = self:addToggleRow("fsStore", ADBuildings.labelWithPlace(building), onOff, ADFieldSiloConfig.hasStore(cfg, building.id))
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ end
|
|||||||
function SmartPickupFrame:onAutoAllResult(yes)
|
function SmartPickupFrame:onAutoAllResult(yes)
|
||||||
self:safe(function(frame)
|
self:safe(function(frame)
|
||||||
if not yes then return end
|
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
|
if result.scanning then
|
||||||
frame.statusOverride = frame.i18n:getText("spu_field_autoAllScanning")
|
frame.statusOverride = frame.i18n:getText("spu_field_autoAllScanning")
|
||||||
frame.statusOverrideTicks = SmartPickupFrame.STATUS_OVERRIDE_TICKS
|
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
|
-- 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.
|
-- uden at omdøbe en vogns parkering til flowets navn.
|
||||||
function SmartPickupFrame:flowWagonContext(adEnv, preview)
|
function SmartPickupFrame:flowWagonContext(adEnv, preview)
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local markers = adEnv.ADGraphManager:getMapMarkers()
|
local markers = adEnv.ADGraphManager:getMapMarkers()
|
||||||
local wanted = flowFillTypes(adEnv, preview)
|
local wanted = flowFillTypes(adEnv, preview)
|
||||||
local candidates = {}
|
local candidates = {}
|
||||||
@@ -242,7 +242,7 @@ end
|
|||||||
|
|
||||||
-- draft: kladden (eller selve run'et — samme feltnavne).
|
-- draft: kladden (eller selve run'et — samme feltnavne).
|
||||||
function SmartPickupFrame:flowGuideContext(adEnv, draft)
|
function SmartPickupFrame:flowGuideContext(adEnv, draft)
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local preview = ADFlowGuide.previewRun(draft, function(buildingId, role)
|
local preview = ADFlowGuide.previewRun(draft, function(buildingId, role)
|
||||||
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
local building = ADBuildings.find(adEnv, farmId, buildingId)
|
||||||
local ids = {}
|
local ids = {}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ SmartPickupFrame.SELL_MARKERS_CACHE_MS = 30000
|
|||||||
function SmartPickupFrame:getSellMarkersCached(adEnv)
|
function SmartPickupFrame:getSellMarkersCached(adEnv)
|
||||||
local time = g_time or (os.clock ~= nil and os.clock() * 1000) or 0
|
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
|
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
|
self.sellMarkersCacheTime = time
|
||||||
end
|
end
|
||||||
return self.sellMarkersCache
|
return self.sellMarkersCache
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ end
|
|||||||
-- silo). Fast rækkefølge også for ens navne (sted, så id — review)
|
-- silo). Fast rækkefølge også for ens navne (sted, så id — review)
|
||||||
local function collectBarns(adEnv)
|
local function collectBarns(adEnv)
|
||||||
local barns, animalBarns = {}, {}
|
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" then table.insert(barns, building) end
|
||||||
if building.kind == "husbandry" or (building.placeable ~= nil and building.placeable.spec_husbandryAnimals ~= nil) then
|
if building.kind == "husbandry" or (building.placeable ~= nil and building.placeable.spec_husbandryAnimals ~= nil) then
|
||||||
table.insert(animalBarns, building)
|
table.insert(animalBarns, building)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ function SmartPickupFrame:getInventory(adEnv)
|
|||||||
if ADSources == nil or ADSources.getFarmInventory == nil then
|
if ADSources == nil or ADSources.getFarmInventory == nil then
|
||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
return ADSources.getFarmInventory(adEnv, g_currentMission:getFarmId())
|
return ADSources.getFarmInventory(adEnv, ADUtil.farmId())
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ---- detaljer for den valgte bygning ----
|
-- ---- 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).
|
-- Beregner stats for alle varer i bygningen (gårdens totaler og rater regnes én gang pr. opdatering).
|
||||||
function SmartPickupFrame:computeBuildingStats(adEnv, entry, inventory)
|
function SmartPickupFrame:computeBuildingStats(adEnv, entry, inventory)
|
||||||
local farmId = g_currentMission:getFarmId()
|
local farmId = ADUtil.farmId()
|
||||||
local totals = ADStorageStats.farmTotals(inventory)
|
local totals = ADStorageStats.farmTotals(inventory)
|
||||||
local rates = ADSources.getFarmRates ~= nil and ADSources.getFarmRates(adEnv, farmId) or {}
|
local rates = ADSources.getFarmRates ~= nil and ADSources.getFarmRates(adEnv, farmId) or {}
|
||||||
local stats = {}
|
local stats = {}
|
||||||
@@ -120,7 +120,7 @@ end
|
|||||||
function SmartPickupFrame:storageLabels(inventory, adEnv)
|
function SmartPickupFrame:storageLabels(inventory, adEnv)
|
||||||
local counts, seen, labels = {}, {}, {}
|
local counts, seen, labels = {}, {}, {}
|
||||||
for _, entry in ipairs(inventory) do counts[entry.name] = (counts[entry.name] or 0) + 1 end
|
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
|
for index, entry in ipairs(inventory) do
|
||||||
seen[entry.name] = (seen[entry.name] or 0) + 1
|
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
|
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.
|
-- Fanens varer med statistik; gårdens totaler/kapacitet/rater regnes over HELE gården.
|
||||||
function SmartPickupFrame:computeItemStats(adEnv, inventory, fullInventory)
|
function SmartPickupFrame:computeItemStats(adEnv, inventory, fullInventory)
|
||||||
self.lastFullInventory = fullInventory -- til "kræver handling" -> flow (hvem bruger varen)
|
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 totals = ADStorageStats.farmTotals(fullInventory)
|
||||||
local capacities = ADStorageStats.farmCapacities(fullInventory)
|
local capacities = ADStorageStats.farmCapacities(fullInventory)
|
||||||
local rates = ADSources.getFarmRates ~= nil and ADSources.getFarmRates(adEnv, farmId) or {}
|
local rates = ADSources.getFarmRates ~= nil and ADSources.getFarmRates(adEnv, farmId) or {}
|
||||||
|
|||||||
Reference in New Issue
Block a user