feat: genoptag maskiner spilleren tog over, når han står af ved marken (v1.62.17)
This commit is contained in:
@@ -124,6 +124,25 @@ end
|
||||
-- Høsten er færdig, men høsteren har korn i tanken: tøm den på marken før marken går videre (én gang pr. mark).
|
||||
-- s = {fill, near, busy, controlled, tried}
|
||||
ADFieldJobs.emptyAttempts = {}
|
||||
-- Genoptag efter spilleren: en maskine moden frigav fordi spilleren kørte den. s = {controlled, busy, near,
|
||||
-- sameStage, hasRole, ageMs} -> "readopt" | "wait" | "forget" (in-game 4/10: Vario 2 kørt uden om en forhindring
|
||||
-- og parkeret ved F14 — moden sendte i stedet en anden tømmevogn)
|
||||
ADFieldJobs.READOPT_MAX_MS = 1800000
|
||||
function ADFieldJobs.readoptAction(s)
|
||||
if s.busy or not s.sameStage or not s.hasRole or (s.ageMs or 0) > ADFieldJobs.READOPT_MAX_MS then return "forget" end
|
||||
if s.controlled or not s.near then return "wait" end
|
||||
return "readopt"
|
||||
end
|
||||
|
||||
-- Den erstatning (samme mark/rolle) der skal hjem igen, når den genoptagne maskine overtager: kun én der endnu
|
||||
-- ikke arbejder. assignments = liste {phase, helper}; -> indeks eller nil
|
||||
function ADFieldJobs.replacementToCancel(assignments, helper)
|
||||
for index, assignment in ipairs(assignments or {}) do
|
||||
if assignment.helper == helper and assignment.phase ~= "working" and assignment.phase ~= "starting" then return index end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function ADFieldJobs.shouldEmptyHarvester(s)
|
||||
return (s.fill or 0) > 0 and s.near == true and not s.busy and not s.controlled and not s.tried
|
||||
end
|
||||
@@ -498,6 +517,8 @@ function ADFieldJobs.tick(adEnv, dt)
|
||||
ADFieldWork.release(assignment)
|
||||
end
|
||||
end
|
||||
local okRe, errRe = pcall(ADFieldWork.tickReadopt, adEnv)
|
||||
if not okRe then Logging.warning(ADFieldJobs.LOG_PREFIX .. "genoptag: %s", tostring(errRe)) end
|
||||
local t2 = clockMs()
|
||||
-- de første minutter efter indlæsning sendes intet ud: Courseplay/AutoDrive genoptager deres egne jobs
|
||||
-- lidt efter start, og indtil da ligner de maskiner ledige (in-game 26/9: kultivatoren blev taget midt
|
||||
|
||||
@@ -1288,6 +1288,59 @@ function ADFieldWork.tryEmptyHarvester(adEnv, field, info)
|
||||
return true
|
||||
end
|
||||
|
||||
ADFieldWork.taken = {}
|
||||
|
||||
-- Genoptag maskiner spilleren tog over, når han står af ved marken (én gang pr. tick for hver).
|
||||
function ADFieldWork.tickReadopt(adEnv)
|
||||
if next(ADFieldWork.taken) == nil then return end
|
||||
local rigsById = {}
|
||||
for _, rig in ipairs(ADFieldWork.getRigs(adEnv)) do rigsById[rig.id] = rig end
|
||||
for vehicleId, entry in pairs(ADFieldWork.taken) do
|
||||
local rig = rigsById[vehicleId]
|
||||
local field = ADFieldJobs.getField(entry.fieldId)
|
||||
local info = ADFields.getInfo(entry.fieldId)
|
||||
if rig == nil or field == nil or info == nil or ADFieldJobs.state.assignments[vehicleId] ~= nil then
|
||||
ADFieldWork.taken[vehicleId] = nil
|
||||
else
|
||||
local near = #(info.verts or {}) >= 3 and ADFieldJobs.insidePolygon(rig.x, rig.z, info.verts)
|
||||
if not near and info.markerId ~= nil then
|
||||
local wayPoint = adEnv.ADGraphManager:getWayPointById(info.markerId)
|
||||
near = wayPoint ~= nil and math.sqrt((wayPoint.x - rig.x) ^ 2 + (wayPoint.z - rig.z) ^ 2) <= 100
|
||||
end
|
||||
local action = ADFieldJobs.readoptAction({controlled = rig.controlled, busy = rig.busy, near = near,
|
||||
sameStage = field.stage == entry.stage,
|
||||
hasRole = rig.role == entry.role or (rig.roles ~= nil and rig.roles[entry.role] == true),
|
||||
ageMs = now() - (entry.at or now())})
|
||||
if action == "forget" then
|
||||
ADFieldWork.taken[vehicleId] = nil
|
||||
elseif action == "readopt" then
|
||||
ADFieldWork.taken[vehicleId] = nil
|
||||
-- erstatningen der stadig er på vej, sendes hjem
|
||||
local others = {}
|
||||
for _, assignment in pairs(ADFieldJobs.state.assignments) do
|
||||
if assignment.fieldId == entry.fieldId and assignment.role == entry.role then table.insert(others, assignment) end
|
||||
end
|
||||
local cancel = ADFieldJobs.replacementToCancel(others, entry.helper)
|
||||
if cancel ~= nil then
|
||||
local other = others[cancel]
|
||||
ADFieldWork.release(other)
|
||||
log(entry.fieldId, "'%s' sendes hjem — '%s' er tilbage og overtager", ADRuns.vehicleLabel(other.vehicle), tostring(rig.label))
|
||||
if not (ADHitch ~= nil and ADHitch.returnHome(adEnv, other.vehicle)) then
|
||||
local park = parkMarkerId(adEnv, other.vehicle)
|
||||
if park ~= nil then startAd(adEnv, other.vehicle, adEnv.AutoDrive.MODE_DRIVETO, park, nil) end
|
||||
end
|
||||
end
|
||||
local assignment = {vehicleId = rig.id, vehicle = rig.vehicle, fieldId = entry.fieldId, role = entry.role, stage = entry.stage,
|
||||
helper = entry.helper, phase = "driving", since = now(), width = rig.width, groupSize = 1, leader = true,
|
||||
manual = rig.manual == true, fillType = entry.fillType}
|
||||
ADFieldJobs.state.assignments[rig.id] = assignment
|
||||
log(entry.fieldId, "'%s' overtaget igen efter spilleren (%s)", tostring(rig.label), tostring(entry.role))
|
||||
beginWork(adEnv, field, info, assignment)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ADFieldWork.follow(adEnv, assignment)
|
||||
local vehicle = assignment.vehicle
|
||||
-- Kun når spilleren selv KØRER (bevæger sig uden Courseplay/AutoDrive) slippes sættet — at sidde i
|
||||
@@ -1296,6 +1349,9 @@ function ADFieldWork.follow(adEnv, assignment)
|
||||
local speed = vehicle.getLastSpeed ~= nil and vehicle:getLastSpeed() or 0
|
||||
if assignment.phase ~= "awaitingPlayer" and isControlledByPlayer(vehicle) and not steeredByAi and speed > ADFieldWork.PLAYER_DRIVING_KMH then
|
||||
log(assignment.fieldId, "'%s' frigivet — spilleren kører det", ADRuns.vehicleLabel(vehicle))
|
||||
-- husk den: står spilleren af ved marken, overtager moden igen (ADFieldWork.tickReadopt)
|
||||
ADFieldWork.taken[assignment.vehicleId] = {fieldId = assignment.fieldId, role = assignment.role, stage = assignment.stage,
|
||||
helper = assignment.helper, fillType = assignment.fillType, at = now()}
|
||||
return ADFieldWork.release(assignment)
|
||||
end
|
||||
local field = ADFieldJobs.getField(assignment.fieldId)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.16.0</version>
|
||||
<version>1.62.17.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user