feat: kobling viser nærmeste ubrugelige redskab og hvorfor (v1.62.129)
This commit is contained in:
@@ -206,33 +206,57 @@ end
|
||||
|
||||
-- Nærmeste frakoblede redskab (samme gård) med et trækøje bag (front: foran) en ledig krog.
|
||||
-- -> {wagon, joint, target, offset, plan, front} | nil
|
||||
-- Anden returværdi: tekst om det nærmeste redskab der IKKE kunne bruges (for langt væk, påkoblet, forkert krogtype)
|
||||
-- — til loggen når intet findes (in-game 9/10: VNX 300 fandt ikke sættevognen ved 'Connect Semi Fladbed Trailer').
|
||||
function ADHitchCreep.findTarget(vehicle, front)
|
||||
local joints = freeJoints(vehicle, front)
|
||||
if #joints == 0 or g_currentMission == nil or g_currentMission.vehicleSystem == nil then return nil end
|
||||
if #joints == 0 then return nil, "ingen ledig krog " .. (front and "foran" or "bag") .. " på køretøjet" end
|
||||
if g_currentMission == nil or g_currentMission.vehicleSystem == nil then return nil end
|
||||
local farmId = vehicle.getOwnerFarmId ~= nil and vehicle:getOwnerFarmId() or nil
|
||||
local best = nil
|
||||
local jointTypes = {}
|
||||
for _, joint in ipairs(joints) do table.insert(jointTypes, tostring(joint.jointType)) end
|
||||
local best, nearest = nil, nil
|
||||
local function note(object, input, distance, why)
|
||||
if nearest == nil or distance < nearest.distance then
|
||||
nearest = {distance = distance, text = string.format("'%s' (%s) %.0f m væk: %s", vehicleName(object), tostring(input and input.jointType or "?"), distance, why)}
|
||||
end
|
||||
end
|
||||
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
|
||||
and (object.getAttacherVehicle == nil or object:getAttacherVehicle() == nil)
|
||||
and (farmId == nil or object.getOwnerFarmId == nil or object:getOwnerFarmId() == farmId) then
|
||||
local attached = object.getAttacherVehicle ~= nil and object:getAttacherVehicle() ~= nil
|
||||
for _, input in ipairs(attachable.inputAttacherJoints) do
|
||||
if input.node ~= nil then
|
||||
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 candidate = {wagon = object, joint = joint.node, target = input.node, offset = offset, front = front,
|
||||
distance = math.sqrt(offset.x ^ 2 + offset.z ^ 2), plan = ADHitchCreep.plan(offset, front)}
|
||||
if candidate.distance <= ADHitchCreep.CREEP_MAX_DISTANCE + 2 and ADHitchCreep.isBetter(candidate, best) then
|
||||
best = candidate
|
||||
local offsetAny = offsetOf(vehicle, joints[1].node, input.node)
|
||||
local distanceAny = math.sqrt(offsetAny.x ^ 2 + offsetAny.z ^ 2)
|
||||
if attached then
|
||||
note(object, input, distanceAny, "er koblet på '" .. vehicleName(object:getAttacherVehicle()) .. "'")
|
||||
else
|
||||
local typeOk = false
|
||||
for _, joint in ipairs(joints) do
|
||||
if input.jointType == nil or joint.jointType == nil or input.jointType == joint.jointType then
|
||||
typeOk = true
|
||||
local offset = offsetOf(vehicle, joint.node, input.node)
|
||||
local candidate = {wagon = object, joint = joint.node, target = input.node, offset = offset, front = front,
|
||||
distance = math.sqrt(offset.x ^ 2 + offset.z ^ 2), plan = ADHitchCreep.plan(offset, front)}
|
||||
if candidate.distance <= ADHitchCreep.CREEP_MAX_DISTANCE + 2 and ADHitchCreep.isBetter(candidate, best) then
|
||||
best = candidate
|
||||
elseif candidate.distance > ADHitchCreep.CREEP_MAX_DISTANCE + 2 then
|
||||
note(object, input, candidate.distance, string.format("for langt (%.0f m %s krogen, %.0f m til siden)",
|
||||
math.abs(offset.z), offset.z < 0 and "bag" or "foran", offset.x))
|
||||
end
|
||||
end
|
||||
end
|
||||
if not typeOk then
|
||||
note(object, input, distanceAny, "krogtype passer ikke (køretøjet har " .. table.concat(jointTypes, "/") .. ")")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return best
|
||||
return best, nearest ~= nil and nearest.text or "ingen frakoblede redskaber på gården"
|
||||
end
|
||||
|
||||
local function isInRange(vehicle, wagon)
|
||||
@@ -560,7 +584,7 @@ function ADHitchCreep.install(adEnv)
|
||||
if job == nil or job.markerId ~= self.destinationID then return end
|
||||
-- "Connect P Front Mower": frontkrogen og frem; ellers bagkrogen og bak (uændret)
|
||||
local front = ADHitchCreep.isFrontMarker(job.markerName)
|
||||
local target = ADHitchCreep.findTarget(self.vehicle, front)
|
||||
local target, why = ADHitchCreep.findTarget(self.vehicle, front)
|
||||
-- skævt i forhold til båsen: følg båsens bakkevej fra Connect ind til redskabet
|
||||
if target ~= nil and not front and target.plan == "none" and target.offset.z < 0 then
|
||||
local graph = adEnv.ADGraphManager
|
||||
@@ -576,8 +600,8 @@ function ADHitchCreep.install(adEnv)
|
||||
if target == nil or target.plan ~= "creep" then
|
||||
-- hvorfor der ikke bakkes (in-game 6/10: Læssevogn 2 'noAttachable' uden bakning)
|
||||
if target == nil then
|
||||
Logging.info(ADHitchCreep.LOG_PREFIX .. "'%s' ved '%s': intet frakoblet redskab med trækøje inden for %d m %s krogen",
|
||||
vehicleName(self.vehicle), tostring(job.markerName), ADHitchCreep.CREEP_MAX_DISTANCE + 2, front and "foran" or "bag")
|
||||
Logging.info(ADHitchCreep.LOG_PREFIX .. "'%s' ved '%s': intet frakoblet redskab med trækøje inden for %d m %s krogen — nærmeste: %s",
|
||||
vehicleName(self.vehicle), tostring(job.markerName), ADHitchCreep.CREEP_MAX_DISTANCE + 2, front and "foran" or "bag", tostring(why))
|
||||
else
|
||||
Logging.info(ADHitchCreep.LOG_PREFIX .. "'%s' ved '%s': bakker ikke (%s) — '%s' trækøje %.1f m %s, %.1f m til siden",
|
||||
vehicleName(self.vehicle), tostring(job.markerName), tostring(target.plan), vehicleName(target.wagon),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<modDesc descVersion="107">
|
||||
<author>masterdraco</author>
|
||||
<version>1.62.128.0</version>
|
||||
<version>1.62.129.0</version>
|
||||
<title>
|
||||
<en>AD Smart Pickup</en>
|
||||
</title>
|
||||
|
||||
Reference in New Issue
Block a user