-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--
-- AegisBot, a simple robot that detects nearby projectiles and shoots them
--
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------=

-------------------------------------------------------------------------------
-- This function is called once and should return the robot's name
function getName()
	return("AegisBot")
end

-------------------------------------------------------------------------------
-- This function called every tick
function onTick() 
	table.clear(items)
	bot:findVisibleObjects(items, ObjType.Burst, ObjType.Seeker, ObjType.Mine, ObjType.SpyBug)   -- Find a suitable target

	local closestItem = findClosest(items)

	if(closestItem == nil) then   -- Didn't find any bullets
		return
	end

	local angle = getFiringSolution(closestItem)

	if(angle == nil) then
		return
	end

	bot:setAngle(angle)
	bot:fireWeapon(Weapon.Phaser)

	-- closestItem must be a Weapon object for :getWeapon to work here
	local weap = closestItem:getWeapon()
	local weapInfo = WeaponInfo[weap]
	logprint("Targeting " .. weapInfo.name)
end


-------------------------------------------------------------------------------
-- This function is called before all other functions, only on robot start-up
function main()
	-- Set global objects here
	items = {}       -- Reusable container for finding objects
end
