require "util"
require "defines"

script.on_init(function()
  global.devnull = {}
end)

script.on_load(function()
  global.devnull = global.devnull or {}
end)

script.on_event(defines.events.on_built_entity, function(event)
  if (event.created_entity.name == "devnull") then
    table.insert(global.devnull, event.created_entity)
  end
end)

script.on_event(defines.events.on_tick, function(event)
  if event.tick%60 == 49 then
    for i, devnull in ipairs(global.devnull) do --destroy dynamite ghosts
      if devnull.valid and devnull.get_item_count() > 0 then
        devnull.get_inventory(defines.inventory.chest).clear()
      elseif not devnull.valid then
        table.remove(global.devnull, i)
      end
    end
  end
end)

function getboundingbox(position, radius)
return {{position.x-radius, position.y-radius}, {position.x+radius,position.y+radius}}
end

function writeDebug(message, conditions)
  local conditionsMet = true
  if conditions then
    if type(conditions) == "boolean" then
      conditionsMet = conditions
    elseif type(conditions) == "table" then
      for _, condition in pairs(conditions) do
        if type(condition) == "boolean" and not condition then conditionsMet = false end
      end
    end
  end
  if not global.release and conditionsMet then script.player.print(serpent.block(message)) end
end
