-- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
-- If a copy of the bCDDL was not distributed with this
-- file, You can obtain one at http://beamng.com/bCDDL-1.1.txt

local M = {}
--Mandatory controller parameters
M.type = "auxiliary"
M.relevantDevice = nil

--LOCAL--
local beams = {}
M.enabled = false

-------
local function init()
  beams = {}
  for k,bm in pairs(v.data.beams) do
    table.insert(beams, bm)
  end
end


local function update()
  if not M.enabled then return end
  for k,bm in ipairs(beams) do
    if obj:getBeamLengthRefRatio(bm.cid) > 2 and not obj:beamIsBroken(bm.cid) then
      print("INSTABILITY!!")
      print(tostring(bm.id1) .. "->" .. tostring(bm.id2))
      print("frompart " .. bm.partOrigin or "nil::")
    end
  end
end

M.init = init
M.update = update

return M