if not term.isColor() then
  print("Advanced computer required")
  exit()
end

sides = peripheral.getNames()
mininglasers = {}
for key,side in pairs(sides) do
  if peripheral.getType(side) == "radar" then
    print("Wrapping " .. side)
    radar = peripheral.wrap(side)
  end
end

local argv = { ... }
if #argv ~= 1 then
  print("Usage: scan <radius>")
  return
end

local radius = tonumber(argv[1])

if radius < 1 or radius > 9999 then
  print("Radius must be between 1 and 9999")
  return
end

if radar.getEnergyLevel() < radius * radius then
  print("Low energy level...")
  return
end
radar.scanRadius(radius)
sleep(2)

print("Scanning...")

local seconds = 2
local count = nil
repeat
  count = radar.getResultsCount()
  sleep(1)
  seconds = seconds + 1
until count ~= nil or seconds > 10
print("took "..seconds.." seconds")

if count ~= nil then
  for i=0, count-1 do
    freq, x, y, z = radar.getResult(i)
    print("Ship '"..freq.."' @ ("..x.. " " .. y .. " " .. z .. ")")
  end
else
  print("Nothing is found =(")
end
