-- THIS IS A TEST AI for a ship, just to make sure the custom AI lua control was working
-- the other AIs are hardcoded 'cause otherwise it runs too slow
-- this functionality is just provided in case people want their own AI scripts
-- to use this script, just set the behavior of a chassis to the name of your lua script file
-- it'll be constantly be run every loop (with "s" as the name of the ship in question)

function update()

		--start out happy with where we are
	if s.controller.goalx == 0 then s.controller.goalx = s.x end
	if s.controller.goaly == 0 then s.controller.goaly = s.y end

	--try to avoid collisions: sets gox & goy to point away from nearby ss
	AI.setProximityAvoid(s)

	s.controller.vars.init("holdrad", math.random(100, 200))
	circledist = s.controller.vars.get("holdrad")
	s.controller.vars.set("holdrad", circledist)

	--fly in circles around the goal
	AI.holdingPattern(s)

	--look for a s.target (ship, dist, interval, diplomacy, skip cloaked ships)
	AI.getTarget(s, 3000, 1500, -1, 1)

	--if we're just chillin'
	if s.controller.hasTarget() == 0 then
		AI.face(s, "go")
		AI.go(s, 1)
		
	--if we have a target
	else
		--set the goal coords to the target (to circle them)
		AI.setGoalTo(s, "target")
		
		--face the target & go in the direction we decided	
		AI.face(s, "goal")
		AI.go(s, 1)
		
		--fire at predicted target coords
		AI.fireAIWeapons(s, 0)
	end
	
	return 0
end
