feat(flows): traktor i et kørende flow startes når spilleren selv har kørt den til Connect og koblet dens vogn på (v1.56.2.0)
This commit is contained in:
@@ -39,6 +39,11 @@ function ADFlowWagons.retryFetch(reason, retries)
|
||||
return tostring(reason):find("^stoppedAway") ~= nil and (retries or 0) < ADFlowWagons.FETCH_RETRIES
|
||||
end
|
||||
|
||||
-- s = {flowRunning, ownWagon, adActive} -> start traktoren efter spillerens egen påkobling?
|
||||
function ADFlowWagons.startAfterManualAttach(s)
|
||||
return s.flowRunning == true and s.ownWagon == true and not s.adActive
|
||||
end
|
||||
|
||||
-- Hvorfor "wait" (til loggen). s som startAction.
|
||||
function ADFlowWagons.waitReason(s)
|
||||
if s.tractorBusy then return "tractorBusy" end
|
||||
@@ -421,6 +426,22 @@ function ADFlowWagons.homeVehicle(adEnv, vehicle, runName)
|
||||
end
|
||||
end
|
||||
|
||||
-- ADHitch: spilleren har selv kørt traktoren til Connect og koblet på.
|
||||
function ADFlowWagons.onManualAttach(adEnv, vehicle, wagon)
|
||||
local run = ADRunsController.getRunForVehicle(vehicle)
|
||||
if run == nil then return end
|
||||
local tractorId = ADRunsController.getVehicleId(vehicle)
|
||||
local wagonId = wagon ~= nil and ADRunsController.getVehicleId(wagon) or nil
|
||||
local remembered = (run.wagons or {})[tractorId]
|
||||
local module = vehicle.ad ~= nil and vehicle.ad.stateModule or nil
|
||||
if not ADFlowWagons.startAfterManualAttach({flowRunning = not run.stopped and ADRunsController.runningRuns[run.id] == true,
|
||||
ownWagon = wagonId ~= nil and (remembered == nil or remembered == wagonId),
|
||||
adActive = module ~= nil and module:isActive()}) then return end
|
||||
fetchRetries[vehicle], waiting[vehicle] = nil, nil
|
||||
Logging.info(ADFlowWagons.LOG_PREFIX .. "flow '%s': '%s' har selv hentet sin vogn — startes", tostring(run.name), tostring(ADRuns.vehicleLabel(vehicle)))
|
||||
ADRunsController.startVehicle(adEnv, run, vehicle)
|
||||
end
|
||||
|
||||
function ADFlowWagons.isEmptying(vehicle)
|
||||
return emptying[vehicle] ~= nil
|
||||
end
|
||||
@@ -567,6 +588,7 @@ local emptyTimer = 0
|
||||
|
||||
function ADFlowWagons.tick(adEnv, dt)
|
||||
if adEnv == nil or ADRunsController.store == nil then return end
|
||||
if ADHitch ~= nil and ADHitch.onManualAttach == nil then ADHitch.onManualAttach = ADFlowWagons.onManualAttach end
|
||||
nowMs = nowMs + dt
|
||||
emptyTimer = emptyTimer + dt
|
||||
if emptyTimer >= 2000 then
|
||||
|
||||
@@ -473,7 +473,7 @@ end
|
||||
local DONE_TEXT = {attach = "koblede '%s' på", detach = "koblede '%s' af", arrive = "er fremme%s"}
|
||||
local FAIL_TEXT = {attach = "kunne ikke koble på", detach = "kunne ikke koble af", arrive = "nåede ikke frem"}
|
||||
|
||||
local function finish(vehicle, job, ok, detail)
|
||||
local function finish(vehicle, job, ok, detail, adEnv)
|
||||
jobs[vehicle] = nil
|
||||
if ok then
|
||||
Logging.info(ADHitch.LOG_PREFIX .. "'%s' " .. DONE_TEXT[job.action] .. " ved '%s'", vehicleName(vehicle),
|
||||
@@ -482,7 +482,13 @@ local function finish(vehicle, job, ok, detail)
|
||||
Logging.warning(ADHitch.LOG_PREFIX .. "'%s' %s ved '%s': %s", vehicleName(vehicle), FAIL_TEXT[job.action],
|
||||
job.markerName, tostring(detail))
|
||||
end
|
||||
if job.onDone ~= nil then pcall(job.onDone, vehicle, ok, detail) end
|
||||
if job.onDone ~= nil then
|
||||
pcall(job.onDone, vehicle, ok, detail)
|
||||
elseif ok and job.action == "attach" and ADHitch.onManualAttach ~= nil then
|
||||
-- spillerens egen tur til Connect: lad fx flowet starte traktoren bagefter
|
||||
local okHook, err = pcall(ADHitch.onManualAttach, adEnv, vehicle, detail)
|
||||
if not okHook then Logging.warning(ADHitch.LOG_PREFIX .. "efter manuel kobling: %s", tostring(err)) end
|
||||
end
|
||||
end
|
||||
|
||||
local ACTIONS = {attach = ADHitch.tryAttach, detach = ADHitch.tryDetach, arrive = function() return true, "" end}
|
||||
@@ -508,9 +514,9 @@ function ADHitch.tick(adEnv, dt)
|
||||
if job.crept then state.arriveDistance = ADHitch.ARRIVE_DISTANCE + ADHitch.CREPT_EXTRA_DISTANCE end
|
||||
ADHitch.step(job, state, elapsed, succeeded)
|
||||
if job.state == "done" then
|
||||
finish(vehicle, job, true, detail)
|
||||
finish(vehicle, job, true, detail, adEnv)
|
||||
elseif job.state == "failed" then
|
||||
finish(vehicle, job, false, job.lastReason or job.reason)
|
||||
finish(vehicle, job, false, job.lastReason or job.reason, adEnv)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.56.1.0</version>
|
||||
<version>1.56.2.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user