feat: markarbejdet henter og skifter skærebord på transporthjul selv (hent, montér, høst, bag på, hjem) — 1.62.162
This commit is contained in:
@@ -89,6 +89,19 @@ function ADHeaderSwap.foldStep(s)
|
||||
return "wait"
|
||||
end
|
||||
|
||||
-- Parkeret skærebord til marken: det nærmeste, der kan høste afgrøden og ikke allerede er taget (taken: to
|
||||
-- mejetærskere sendt ud i samme omgang). options = {{x, z, fruits = {[fruit] = true}, taken}}
|
||||
function ADHeaderSwap.pickHeader(options, fruit, x, z)
|
||||
local best, bestDistance = nil, math.huge
|
||||
for _, option in ipairs(options or {}) do
|
||||
if fruit ~= nil and not option.taken and option.fruits ~= nil and option.fruits[fruit] then
|
||||
local d = (option.x - x) ^ 2 + (option.z - z) ^ 2
|
||||
if d < bestDistance then best, bestDistance = option, d end
|
||||
end
|
||||
end
|
||||
return best
|
||||
end
|
||||
|
||||
-- ---- spil ----
|
||||
|
||||
local active = {}
|
||||
@@ -507,6 +520,53 @@ function ADHeaderSwap.mountRear(adEnv, combine, onDone)
|
||||
return true
|
||||
end
|
||||
|
||||
-- Kan mejetærskeren bære et skærebord på transporthjul (cutter-krog foran og trailer-krog bag)?
|
||||
function ADHeaderSwap.canTowHeader(combine)
|
||||
if combine == nil or combine.spec_combine == nil or combine.spec_attacherJoints == nil then return false end
|
||||
local cutterType, trailerType = jointTypes()
|
||||
return cutterType ~= nil and combineJoint(combine, cutterType, true) ~= nil and combineJoint(combine, trailerType, false) ~= nil
|
||||
end
|
||||
|
||||
-- Frakoblede skærebord på transporthjul med AD-parkering og Connect-markør (som maskinpuljens redskaber), ikke
|
||||
-- reserveret. -> {{vehicle, id, name, connectId, parkName, fruits, x, z}}
|
||||
function ADHeaderSwap.parkedHeaders(adEnv, farmId)
|
||||
local result = {}
|
||||
if g_currentMission == nil or g_currentMission.vehicleSystem == nil or adEnv == nil then return result end
|
||||
local graph = adEnv.ADGraphManager
|
||||
local markers = graph:getMapMarkers()
|
||||
for _, object in pairs(g_currentMission.vehicleSystem.vehicles or {}) do
|
||||
if isTransportHeader(object) and object.rootNode ~= nil
|
||||
and (object.getAttacherVehicle == nil or object:getAttacherVehicle() == nil)
|
||||
and (farmId == nil or object.getOwnerFarmId == nil or object:getOwnerFarmId() == farmId) then
|
||||
local index = object.advd ~= nil and object.advd.parkDestination or nil
|
||||
local park = type(index) == "number" and index >= 1 and graph:getMapMarkerById(index) or nil
|
||||
local connect = park ~= nil and ADPool ~= nil and ADPool.connectFor(park.name, markers) or nil
|
||||
local id = ADRunsController ~= nil and ADRunsController.getVehicleId(object) or nil
|
||||
if connect ~= nil and id ~= nil and not (ADPool.isReserved ~= nil and ADPool.isReserved(id)) then
|
||||
local x, _, z = getWorldTranslation(object.rootNode)
|
||||
local okW, width = pcall(ADCpBridge.getWorkWidth, object)
|
||||
table.insert(result, {vehicle = object, id = id, name = vehicleName(object), connectId = connect.id, parkName = park.name,
|
||||
fruits = ADCpBridge.harvestFruitSet(object.spec_cutter), x = x, z = z, width = okW and tonumber(width) or nil})
|
||||
end
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
-- Afbryd et skift (opgaven er sluppet): AD stoppes, onDone kaldes ikke. -> true hvis der var et.
|
||||
function ADHeaderSwap.cancel(combine)
|
||||
local swap = active[combine]
|
||||
if swap == nil then return false end
|
||||
active[combine] = nil
|
||||
swap.onDone = nil
|
||||
local taskModule = combine.ad ~= nil and combine.ad.taskModule or nil
|
||||
if taskModule ~= nil then pcall(taskModule.abortAllTasks, taskModule) end
|
||||
stopDriving(combine)
|
||||
if combine.stopAutoDrive ~= nil then pcall(combine.stopAutoDrive, combine) end
|
||||
Logging.info(ADHeaderSwap.LOG_PREFIX .. "'%s': skiftet afbrudt", vehicleName(combine))
|
||||
return true
|
||||
end
|
||||
|
||||
function ADHeaderSwap.isBusy(combine)
|
||||
return liveSwap(combine) ~= nil
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user