Skip to content

Commit

Permalink
#118: Check if target vehicles supports any of the internal types, if…
Browse files Browse the repository at this point in the history
… not we allow all functions.
  • Loading branch information
stijnwop committed Mar 26, 2023
1 parent 125c0aa commit fde8f1c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/utils/ManualAttachUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,36 @@ end
---@param attacherJointIndex number
---@return boolean
function ManualAttachUtil.hasConnectionTarget(vehicle, attacherJointIndex)
local hoses = vehicle.spec_connectionHoses
if hoses ~= nil then
for _, node in ipairs(hoses.targetNodes) do
local spec = vehicle.spec_connectionHoses

local function hasConnectedNode(nodes)
for _, node in ipairs(nodes) do
if node.attacherJointIndices[attacherJointIndex] ~= nil then
return true
end
end

return false
end

local function hasInternals(nodes)
for _, node in ipairs(nodes) do
for type, _ in pairs(ManualAttachConnectionHoses.TYPES) do
if ManualAttachConnectionHoses.TYPES_TO_INTERNAL[type][(node.type):upper()] ~= nil then
return true
end
end
end

return false
end

if spec ~= nil then
if not hasInternals(spec.targetNodes) then
return false
end

return hasConnectedNode(spec.targetNodes)
end

return false
Expand All @@ -122,6 +145,7 @@ function ManualAttachUtil.hasConnectionHoses(object, vehicle)

local inputJointDescIndex = object.spec_attachable.inputAttacherJointDescIndex
local hoses = object:getConnectionHosesByInputAttacherJoint(inputJointDescIndex)

return #hoses ~= 0
end

Expand Down

0 comments on commit fde8f1c

Please sign in to comment.