fix: lange vogntog ruller frem til risten; kobling via båsens bak-stik (v1.62.33)

This commit is contained in:
2026-10-06 09:40:35 +02:00
parent be2630457f
commit e641c8e4d6
5 changed files with 343 additions and 1 deletions
+1
View File
@@ -8,6 +8,7 @@ står i [docs/BRUGERMANUAL.md](docs/BRUGERMANUAL.md) (dansk) og [docs/USER_MANUA
## 1.62 — Kæder slås selv til
- **1.62.33** Rettet: et langt vogntog (fx 724 Vario + 2× Carat) holdt ved siloen med den fulde bageste vogn et par meter før risten og ventede for evigt. Nu ruller traktoren langsomt frem (højst 8 m), til AutoDrive tipper, når en rist der tager varen ligger lige foran en fuld vogns tippested. Rettet: i bak-ind-båse kunne puljetraktoren køre næsen først hen til *Connect* og så ikke koble på (`noAttachable`); har båsen et bak-stik, kører den nu først dertil og bakker ind til vognen.
- **1.62.32** Rettet: i markflåden med *Brug alle ledige maskiner = Ja* gjorde fluebenet ingenting, så en enkelt maskine kunne ikke tages ud. Nu fjerner du fluebenet for at udelukke maskinen (markarbejde og maskinpulje); det gemmes pr. savegame. I *kun med flueben* virker fluebenet som før.
- **1.62.31** Rettet: kæden skiftede marker til **eng** (MEADOW) for at få hø, men eng kan ikke sås i FS25 (F5 og F9 in-game). Både græs og eng giver græsvindue; nu skiftes kun til afgrøden med vinduets navn (græs), eng tæller som udbud, og mål-afgrøder kæden har sat, som ikke kan bruges, ryddes automatisk (dit eget valg røres ikke). Græs- og engmarker tælles nu begge med, så kæden ikke skifter for mange marker.
- **1.62.30** Ændret: marker kører **Auto** som standard (starter selv, når de er klar). Første gang et savegame indlæses med denne version, sættes alle manuelle marker til Auto (én gang); *Gem uden at starte* i markguiden giver stadig Manuel, og det huskes. Fjernes en mål-afgrøde, bevarer marken sin kørsel i stedet for at skifte til Manuel.
+140
View File
@@ -0,0 +1,140 @@
-- AD Hitch Approach
-- Bak-ind-båse (solhallerne i savegame6): banen fra Connect-markøren ud til fordelersporet har tovejs
-- tværspor, så AD kan køre NÆSEN FØRST frem til Connect — krogen vender væk fra vognen, og koblingen
-- fejler med 'noAttachable' (in-game 6/10: Tippevogn 5 og 6). Har båsen et bak-stik (en kant S => J der
-- kun køres baglæns: J står i S.out, men S mangler i J.incoming), køres traktoren først til S og derfra
-- baglæns op ad banen til Connect — samme vej som AD selv parkerer i båsen.
ADHitchApproach = {}
ADHitchApproach.LOG_PREFIX = "ADSmartPickup: kobling: "
ADHitchApproach.MAX_DISTANCE = 40 -- m ad nettet fra Connect til bak-stikkets startknude
ADHitchApproach.ALREADY_THERE = 3 -- m: står traktoren allerede ved S, springes trinnet over
-- ---- ren logik ----
local function contains(list, value)
for _, item in ipairs(list or {}) do
if item == value then return true end
end
return false
end
-- graph = {out(id) -> {id}, incoming(id) -> {id}, pos(id) -> x, z}; avoidId = båsens P-knude (søg ikke den vej).
-- -> startknude S for den nærmeste bak-kant, eller nil
function ADHitchApproach.findBackEntry(graph, connectId, avoidId, maxDistance)
maxDistance = maxDistance or ADHitchApproach.MAX_DISTANCE
local function step(a, b)
local ax, az = graph.pos(a)
local bx, bz = graph.pos(b)
if ax == nil or bx == nil then return math.huge end
return math.sqrt((ax - bx) ^ 2 + (az - bz) ^ 2)
end
local dist, done = {[connectId] = 0}, {}
local best, bestDistance = nil, math.huge
while true do
local current, currentDistance = nil, math.huge
for id, d in pairs(dist) do
if not done[id] and d < currentDistance then current, currentDistance = id, d end
end
if current == nil then break end
done[current] = true
if current ~= connectId then
for _, target in ipairs(graph.out(current) or {}) do
if not contains(graph.incoming(target), current) and currentDistance < bestDistance then
best, bestDistance = current, currentDistance
end
end
end
local neighbours = {}
for _, id in ipairs(graph.out(current) or {}) do table.insert(neighbours, id) end
for _, id in ipairs(graph.incoming(current) or {}) do table.insert(neighbours, id) end
for _, id in ipairs(neighbours) do
if id ~= avoidId and not done[id] then
local d = currentDistance + step(current, id)
if d <= maxDistance and (dist[id] == nil or d < dist[id]) then dist[id] = d end
end
end
end
return best
end
-- "Connect P Tippevogn 5" -> "P Tippevogn 5"
function ADHitchApproach.parkNameOf(connectName)
if type(connectName) ~= "string" then return nil end
return connectName:match("^[Cc]onnect (.+)$")
end
-- ---- spil ----
local function graphOf(adEnv)
local manager = adEnv.ADGraphManager
local function wayPoint(id) return manager:getWayPointById(id) end
return {
out = function(id) local w = wayPoint(id) return w ~= nil and w.out or {} end,
incoming = function(id) local w = wayPoint(id) return w ~= nil and w.incoming or {} end,
pos = function(id) local w = wayPoint(id) if w == nil then return nil end return w.x, w.z end,
}
end
local function parkWayPointId(adEnv, connectName)
local parkName = ADHitchApproach.parkNameOf(connectName)
if parkName == nil then return nil end
for _, marker in pairs(adEnv.ADGraphManager:getMapMarkers()) do
if marker.name == parkName then return marker.id end
end
return nil
end
local function vehicleName(vehicle)
return vehicle ~= nil and vehicle.getName ~= nil and vehicle:getName() or "?"
end
-- Bak-stikkets startknude for traktorens kobl-på-tur, eller nil (ingen tur, intet bak-stik, står der allerede).
local function backEntryFor(adEnv, vehicle, destinationId)
local job = ADHitch ~= nil and ADHitch.pendingAttach ~= nil and ADHitch.pendingAttach(vehicle) or nil
if job == nil or job.markerId ~= destinationId then return nil end
local marker = adEnv.ADGraphManager:getMapMarkerByWayPointId(destinationId)
local entry = ADHitchApproach.findBackEntry(graphOf(adEnv), destinationId,
parkWayPointId(adEnv, marker ~= nil and marker.name or nil))
if entry == nil then return nil end
local wayPoint = adEnv.ADGraphManager:getWayPointById(entry)
if wayPoint ~= nil and vehicle.rootNode ~= nil then
local x, _, z = getWorldTranslation(vehicle.rootNode)
if math.sqrt((x - wayPoint.x) ^ 2 + (z - wayPoint.z) ^ 2) <= ADHitchApproach.ALREADY_THERE then return nil end
end
return entry, marker ~= nil and marker.name or tostring(destinationId)
end
local isInstalled = false
-- DriveToMode:start lægger DriveToDestinationTask(Connect) i køen; et trin til bak-stikket lægges foran.
-- Trinnet melder sig færdigt uden at give besked til mode'en (ellers stopper DriveToMode AD dér).
function ADHitchApproach.install(adEnv)
local mode, taskClass = adEnv ~= nil and adEnv.DriveToMode or nil, adEnv ~= nil and adEnv.DriveToDestinationTask or nil
if isInstalled or mode == nil or mode.start == nil or taskClass == nil or taskClass.new == nil then return end
isInstalled = true
local original = mode.start
mode.start = function(self, ...)
local result = original(self, ...)
local ok, err = pcall(function()
if self.driveToDestinationTask == nil or self.destinationID == nil then return end
local entry, name = backEntryFor(adEnv, self.vehicle, self.destinationID)
if entry == nil then return end
local stage = setmetatable({}, {__index = taskClass:new(self.vehicle, entry)})
local taskModule = adEnv.ADTaskModule
stage.finished = function(task)
task.vehicle.ad.taskModule:setCurrentTaskFinished(taskModule ~= nil and taskModule.DONT_PROPAGATE or 1)
end
local queue = self.vehicle.ad.taskModule.tasks
local items = {}
for _, item in ipairs(queue:GetItems() or {}) do table.insert(items, item) end
queue:Clear()
queue:Enqueue(stage)
for _, item in ipairs(items) do queue:Enqueue(item) end
Logging.info(ADHitchApproach.LOG_PREFIX .. "'%s' kører via båsens bak-stik (vejpunkt %s) og bakker ind til '%s'",
vehicleName(self.vehicle), tostring(entry), tostring(name))
end)
if not ok then Logging.warning(ADHitchApproach.LOG_PREFIX .. "bak-stik-tur: %s", tostring(err)) end
return result
end
end
+7
View File
@@ -1146,12 +1146,19 @@ local function installHook(adEnv)
if ADUnloadWait ~= nil then
ADUnloadWait.install(adEnv)
end
-- efter Wait-logikken: rulningen ligger yderst og springer den over, mens toget ruller frem
if ADUnloadRoll ~= nil and ADUnloadRoll.install ~= nil then
ADUnloadRoll.install(adEnv)
end
if ADOutbound ~= nil and ADOutbound.install ~= nil then
ADOutbound.install(adEnv)
end
if ADHitchCreep ~= nil and ADHitchCreep.install ~= nil then
ADHitchCreep.install(adEnv)
end
if ADHitchApproach ~= nil and ADHitchApproach.install ~= nil then
ADHitchApproach.install(adEnv)
end
if ADLoadDiag ~= nil and ADLoadDiag.install ~= nil then
ADLoadDiag.install(adEnv)
end
+192
View File
@@ -0,0 +1,192 @@
-- AD Unload Roll
-- AutoDrive standser aflæsningen, når traktorens NÆSE når markøren. Med et langt vogntog (724 Vario + 2×
-- Carat 140 TD, in-game 6/10 ved Silo 4) står den fulde bageste vogns tippested så et par meter FØR risten,
-- og AD venter for evigt ("Wait at unload point until unloaded somehow"). Ligger en trigger, der tager varen,
-- lige foran en fuld vogns tippested, ruller traktoren her langsomt frem, til AD selv begynder at tippe.
-- Markørerne må ikke flyttes i stedet: vejen svinger ofte lige efter siloen, og så kender moden ikke længere
-- siloen ved markøren (MAX_TRIGGER_LATERAL_OFFSET).
ADUnloadRoll = {}
ADUnloadRoll.LOG_PREFIX = "ADSmartPickup: aflæsning: "
ADUnloadRoll.MIN_AHEAD = 0.3 -- m: tættere på er tippestedet allerede over triggeren
ADUnloadRoll.MAX_AHEAD = 8 -- m: længere frem rulles ikke — så er det ikke markørens trigger
ADUnloadRoll.MAX_LATERAL = 2 -- m til siden: vognen følger sporet lige frem
ADUnloadRoll.OVERSHOOT = 1.5 -- m forbi planen uden at AD tipper -> giv op
ADUnloadRoll.TIMEOUT_MS = 20000
ADUnloadRoll.SETTLE_MS = 1500 -- målet nået så længe, uden at AD tipper, før der rulles
ADUnloadRoll.ROLL_SPEED = 3 -- km/t
ADUnloadRoll.MIN_FILL = 100 -- l: mindre end det tæller vognen som tom
ADUnloadRoll.SEARCH_RADIUS = 14 -- m fra tippestedet til triggere der overvejes
-- ---- ren logik ----
-- offsets = {{x, z}}: triggere set fra en fuld vogns tippested i traktorens rum (z > 0 = foran).
-- -> meter der skal rulles (nærmeste brugbare), eller nil
function ADUnloadRoll.plan(offsets)
local best = nil
for _, offset in ipairs(offsets or {}) do
if offset.z > ADUnloadRoll.MIN_AHEAD and offset.z <= ADUnloadRoll.MAX_AHEAD
and math.abs(offset.x) <= ADUnloadRoll.MAX_LATERAL and (best == nil or offset.z < best) then
best = offset.z
end
end
return best
end
-- s = {unloading, traveled, planned, elapsedMs} -> "done" | "drive" | "giveUp"
function ADUnloadRoll.step(s)
if s.unloading then return "done" end
if (s.elapsedMs or 0) >= ADUnloadRoll.TIMEOUT_MS then return "giveUp" end
if s.traveled > s.planned + ADUnloadRoll.OVERSHOOT then return "giveUp" end
return "drive"
end
-- ---- spil ----
local rolls = setmetatable({}, {__mode = "k"}) -- køretøj -> {task, start, planned, elapsedMs}
local tried = setmetatable({}, {__mode = "k"}) -- aflæsningsopgave -> true (kun ét forsøg pr. tur)
local settle = setmetatable({}, {__mode = "k"}) -- aflæsningsopgave -> ms med målet nået uden tipning
local function vehicleName(vehicle)
if ADRuns ~= nil and ADRuns.vehicleLabel ~= nil then return tostring(ADRuns.vehicleLabel(vehicle)) end
return vehicle ~= nil and vehicle.getName ~= nil and vehicle:getName() or "?"
end
local function triggerAccepts(trigger, fillType)
if trigger.getIsFillTypeAllowed ~= nil then
local ok, allowed = pcall(trigger.getIsFillTypeAllowed, trigger, fillType)
if ok then return allowed == true end
end
return trigger.fillTypes == nil or trigger.fillTypes[fillType] == true
end
-- Triggere foran de fulde vognes tippesteder, i traktorens rum. -> {{x, z}}
local function offsetsFor(adEnv, vehicle)
local offsets = {}
local storage = g_currentMission ~= nil and g_currentMission.storageSystem or nil
if storage == nil or vehicle.rootNode == nil then return offsets end
local farmId = vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() or nil
for _, unit in ipairs(adEnv.AutoDrive.getAllDischargeableUnits(vehicle) or {}) do
local object = unit.object
local level = object ~= nil and object.getFillUnitFillLevel ~= nil and object:getFillUnitFillLevel(unit.fillUnitIndex) or 0
local dischargeNode = level >= ADUnloadRoll.MIN_FILL and object.getCurrentDischargeNode ~= nil and object:getCurrentDischargeNode() or nil
if dischargeNode ~= nil and dischargeNode.node ~= nil then
local fillType = object:getFillUnitFillType(unit.fillUnitIndex)
local nx, ny, nz = getWorldTranslation(dischargeNode.node)
for _, station in pairs(storage:getUnloadingStations()) do
if ADSmartPickup == nil or ADSmartPickup.canUseStation == nil or ADSmartPickup.canUseStation(farmId, station) then
for _, trigger in pairs(station.unloadTriggers or {}) do
local node = trigger.exactFillRootNode
if node ~= nil and triggerAccepts(trigger, fillType) then
local tx, _, tz = getWorldTranslation(node)
if math.sqrt((tx - nx) ^ 2 + (tz - nz) ^ 2) <= ADUnloadRoll.SEARCH_RADIUS then
local x, _, z = worldDirectionToLocal(vehicle.rootNode, tx - nx, 0, tz - nz)
table.insert(offsets, {x = x, z = z})
end
end
end
end
end
end
end
return offsets
end
local function isAdUnloading(vehicle)
local trailerModule = vehicle.ad ~= nil and vehicle.ad.trailerModule or nil
if trailerModule == nil then return false end
return trailerModule.isUnloading == true or (trailerModule.isActiveAtTrigger ~= nil and trailerModule:isActiveAtTrigger() == true)
end
local function positionOf(vehicle)
local x, _, z = getWorldTranslation(vehicle.rootNode)
return {x = x, z = z}
end
-- Skal opgaven rulle frem nu? -> planlagt afstand eller nil
local function shouldRoll(adEnv, task, dt)
local vehicle = task.vehicle
if tried[task] or task.isContinued or task.state ~= (task.STATE_DRIVING or 2) then return nil end
if vehicle.ad.drivePathModule == nil or not vehicle.ad.drivePathModule:isTargetReached() or isAdUnloading(vehicle) then
settle[task] = 0
return nil
end
if ADUnloadWait ~= nil and ADUnloadWait.getWaitFor ~= nil and ADUnloadWait.getWaitFor(vehicle) ~= nil then return nil end
settle[task] = (settle[task] or 0) + dt
if settle[task] < ADUnloadRoll.SETTLE_MS then return nil end
tried[task] = true
-- fuldt mål: Wait-logikken tager sig af det — at rulle frem hjælper ikke
if ADUnloadWait ~= nil and ADUnloadWait.getRestLoad ~= nil and ADSmartPickup ~= nil and ADSmartPickup.getTargetFreeCapacity ~= nil then
local fillType = ADUnloadWait.getRestLoad(adEnv, vehicle)
local free = fillType ~= nil and ADSmartPickup.getTargetFreeCapacity(adEnv, vehicle, fillType) or nil
if free ~= nil and free < ADUnloadRoll.MIN_FILL then return nil end
end
return ADUnloadRoll.plan(offsetsFor(adEnv, vehicle))
end
local function stop(vehicle, dt)
local sdm = vehicle.ad.specialDrivingModule
if sdm ~= nil and sdm.stopVehicle ~= nil then
sdm:stopVehicle()
if sdm.update ~= nil then sdm:update(dt) end
end
end
-- Ét skridt af rulningen. -> true når den er slut (AD overtager igen)
local function rollStep(adEnv, task, roll, dt)
local vehicle = task.vehicle
roll.elapsedMs = roll.elapsedMs + dt
if vehicle.ad.trailerModule ~= nil then vehicle.ad.trailerModule:update(dt) end
local p = positionOf(vehicle)
local traveled = math.sqrt((p.x - roll.start.x) ^ 2 + (p.z - roll.start.z) ^ 2)
local action = ADUnloadRoll.step({unloading = isAdUnloading(vehicle), traveled = traveled, planned = roll.planned,
elapsedMs = roll.elapsedMs})
if action == "done" then
stop(vehicle, dt)
Logging.info(ADUnloadRoll.LOG_PREFIX .. "'%s' rullede %.1f m frem og tipper nu", vehicleName(vehicle), traveled)
return true
elseif action == "giveUp" then
stop(vehicle, dt)
Logging.warning(ADUnloadRoll.LOG_PREFIX .. "'%s' rullede %.1f m uden at kunne tippe — giver op", vehicleName(vehicle), traveled)
return true
end
local sdm = vehicle.ad.specialDrivingModule
if sdm ~= nil and sdm.releaseVehicle ~= nil then sdm:releaseVehicle() end
if vehicle.startMotor ~= nil and not vehicle:getIsMotorStarted() and vehicle:getCanMotorRun() then vehicle:startMotor() end
local x, y, z = localToWorld(vehicle.rootNode, 0, 0, 10)
local lx, lz = adEnv.AutoDrive.getDriveDirection(vehicle, x, y, z)
adEnv.AutoDrive.driveInDirection(vehicle, dt, 30, 0.3, 0.2, 20, true, true, lx, lz, ADUnloadRoll.ROLL_SPEED, 1)
return false
end
local isInstalled = false
function ADUnloadRoll.install(adEnv)
local task = adEnv ~= nil and adEnv.UnloadAtDestinationTask or nil
if isInstalled or task == nil or task.update == nil or adEnv.AutoDrive == nil
or adEnv.AutoDrive.driveInDirection == nil or adEnv.AutoDrive.getDriveDirection == nil then
return
end
isInstalled = true
local originalUpdate = task.update
task.update = function(self, dt)
local vehicle = self.vehicle
local roll = vehicle ~= nil and rolls[vehicle] or nil
if roll ~= nil and roll.task == self then
local ok, finished = pcall(rollStep, adEnv, self, roll, dt)
if not ok then Logging.warning(ADUnloadRoll.LOG_PREFIX .. "rul frem: %s", tostring(finished)) end
if ok and not finished then return end
rolls[vehicle] = nil
elseif vehicle ~= nil then
local ok, planned = pcall(shouldRoll, adEnv, self, dt)
if not ok then
Logging.warning(ADUnloadRoll.LOG_PREFIX .. "rul frem: %s", tostring(planned))
elseif planned ~= nil then
rolls[vehicle] = {task = self, start = positionOf(vehicle), planned = planned, elapsedMs = 0}
Logging.info(ADUnloadRoll.LOG_PREFIX .. "'%s' står %.1f m før aflæsningen — ruller frem", vehicleName(vehicle), planned)
return
end
end
return originalUpdate(self, dt)
end
end
+3 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107">
<author>masterdraco</author>
<version>1.62.32.0</version>
<version>1.62.33.0</version>
<title>
<en>AD Smart Pickup</en>
</title>
@@ -35,6 +35,7 @@
<sourceFile filename="adLoadDiag.lua"/>
<sourceFile filename="adSellBlock.lua"/>
<sourceFile filename="adUnloadWait.lua"/>
<sourceFile filename="adUnloadRoll.lua"/>
<sourceFile filename="adFieldModel.lua"/>
<sourceFile filename="adFieldFleet.lua"/>
<sourceFile filename="adFieldView.lua"/>
@@ -52,6 +53,7 @@
<sourceFile filename="adCpResume.lua"/>
<sourceFile filename="adHitch.lua"/>
<sourceFile filename="adHitchCreep.lua"/>
<sourceFile filename="adHitchApproach.lua"/>
<sourceFile filename="adPool.lua"/>
<sourceFile filename="adFlowWagons.lua"/>
<sourceFile filename="adFleetNames.lua"/>