feat: traktor med saltspreder låst til saltruten

This commit is contained in:
2026-10-21 01:08:08 +02:00
parent 9ee581df83
commit 0fc7337242
9 changed files with 46 additions and 8 deletions
+36 -2
View File
@@ -117,8 +117,38 @@ local failedUntil = setmetatable({}, {__mode = "k"}) -- spreder -> ms
local checkTimer, stepTimer = 0, 0
ADSaltRoute.lastDone = nil -- {height, day} for den sidste færdige rute
-- Ren: har maskinen (eller noget koblet på den, to led ned) en saltspreder? attachedOf(v) -> liste af redskaber
function ADSaltRoute.carriesSpreader(vehicle, attachedOf, depth)
if type(vehicle) ~= "table" then return false end
if vehicle.spec_saltSpreader ~= nil then return true end
if (depth or 0) >= 2 then return false end
for _, implement in ipairs(attachedOf(vehicle) or {}) do
if ADSaltRoute.carriesSpreader(implement, attachedOf, (depth or 0) + 1) then return true end
end
return false
end
local function attachedObjects(vehicle)
local list = {}
if vehicle.getAttachedImplements == nil then return list end
local ok, implements = pcall(vehicle.getAttachedImplements, vehicle)
for _, implement in ipairs(ok and implements or {}) do
if type(implement) == "table" and implement.object ~= nil then table.insert(list, implement.object) end
end
return list
end
-- Låst til saltruten (brugerønske 21/10): en traktor med saltsprederen koblet på er kun til saltning — puljen, dyreture,
-- flow-vogne og markarbejde låner den ikke. Saltruten selv spørger med ownCheck (sin egen ledig-regel).
local ownCheck = false
function ADSaltRoute.isDedicated(vehicle)
if ownCheck or vehicle == nil then return false end
local ok, carries = pcall(ADSaltRoute.carriesSpreader, vehicle, attachedObjects, 0)
return ok and carries == true
end
function ADSaltRoute.isBusy(vehicle)
return vehicle ~= nil and busyVehicles[vehicle] ~= nil
return vehicle ~= nil and (busyVehicles[vehicle] ~= nil or ADSaltRoute.isDedicated(vehicle))
end
local function snowHeight()
@@ -163,7 +193,11 @@ local function driverFree(vehicle)
if vehicle.getIsControlled ~= nil and vehicle:getIsControlled() then return false end
if ADPlayerClaim ~= nil and ADPlayerClaim.claims(vehicle) then return false end
if ADHitch.isBusy ~= nil and ADHitch.isBusy(vehicle) then return false end
return not (ADFieldWork ~= nil and ADFieldWork.isBusyVehicle ~= nil and ADFieldWork.isBusyVehicle(vehicle, id))
-- markarbejdets optaget-regel uden saltlåsen (ellers var vores egen salttraktor altid "optaget")
ownCheck = true
local ok, busy = pcall(function() return ADFieldWork ~= nil and ADFieldWork.isBusyVehicle ~= nil and ADFieldWork.isBusyVehicle(vehicle, id) end)
ownCheck = false
return ok and not busy
end
local function freeTractor(adEnv, implement)