fix: påkobling foretrækker redskab lige bag krogen (v1.62.49)
This commit is contained in:
@@ -29,6 +29,15 @@ function ADHitchCreep.plan(offset)
|
||||
return "creep"
|
||||
end
|
||||
|
||||
-- Er kandidat a bedre end b? {plan, distance}: en der kan bakkes/kobles til slår altid en der ikke kan, ellers
|
||||
-- nærmeste (in-game 6/10: såmaskinen i nabobåsen 6,2 m til siden var nærmere end K105 lige bagved -> "none")
|
||||
function ADHitchCreep.isBetter(a, b)
|
||||
if b == nil then return true end
|
||||
local usableA, usableB = a.plan ~= "none", b.plan ~= "none"
|
||||
if usableA ~= usableB then return usableA end
|
||||
return a.distance < b.distance
|
||||
end
|
||||
|
||||
-- s = {inRange, distance, startDistance, elapsedMs, passed} -> "done" | "drive" | "giveUp"
|
||||
function ADHitchCreep.step(s)
|
||||
if s.inRange then return "done" end
|
||||
@@ -80,7 +89,7 @@ function ADHitchCreep.findTarget(vehicle)
|
||||
local joints = freeRearJoints(vehicle)
|
||||
if #joints == 0 or g_currentMission == nil or g_currentMission.vehicleSystem == nil then return nil end
|
||||
local farmId = vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() or nil
|
||||
local best, bestDistance = nil, math.huge
|
||||
local best = nil
|
||||
for _, object in pairs(g_currentMission.vehicleSystem.vehicles or {}) do
|
||||
local attachable = object.spec_attachable
|
||||
if object ~= vehicle and attachable ~= nil and object.spec_motorized == nil and attachable.inputAttacherJoints ~= nil
|
||||
@@ -91,10 +100,10 @@ function ADHitchCreep.findTarget(vehicle)
|
||||
for _, joint in ipairs(joints) do
|
||||
if input.jointType == nil or joint.jointType == nil or input.jointType == joint.jointType then
|
||||
local offset = offsetOf(vehicle, joint.node, input.node)
|
||||
local distance = math.sqrt(offset.x ^ 2 + offset.z ^ 2)
|
||||
if distance < bestDistance and distance <= ADHitchCreep.CREEP_MAX_DISTANCE + 2 then
|
||||
bestDistance = distance
|
||||
best = {wagon = object, joint = joint.node, target = input.node, offset = offset}
|
||||
local candidate = {wagon = object, joint = joint.node, target = input.node, offset = offset,
|
||||
distance = math.sqrt(offset.x ^ 2 + offset.z ^ 2), plan = ADHitchCreep.plan(offset)}
|
||||
if candidate.distance <= ADHitchCreep.CREEP_MAX_DISTANCE + 2 and ADHitchCreep.isBetter(candidate, best) then
|
||||
best = candidate
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -102,7 +111,6 @@ function ADHitchCreep.findTarget(vehicle)
|
||||
end
|
||||
end
|
||||
end
|
||||
if best ~= nil then best.plan = ADHitchCreep.plan(best.offset) end
|
||||
return best
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.48.0</version>
|
||||
<version>1.62.49.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user