'== included in the AI scripts file =='

'start out happy with where we are
If s.controller.goalx = 0 Then s.controller.goalx = s.x
If s.controller.goaly = 0 Then s.controller.goaly = s.y

'wiiiiide circles
s.controller.vars.set("holdrad", 340)'heavier things do further-away flybys

'direction to harass from
s.controller.vars.init("flytheta", Rand(1,360))

'try to avoid collisions: sets gox & goy to point away from nearby ss
AI.setProximityAvoid(s, TSIZE*1.5)

'look for a s.target
AI.getTarget(s, 1900)

If target <> Null
	'a direction from the target to harass them from
	Local flytheta = s.controller.vars.get("flytheta")
	Local flyrad = s.controller.vars.get("holdrad")

	'set the goal coords to the target (to circle them)
	AI.setGoalTo(s, "target")
	
	s.controller.goalx:+ Cos(flytheta) * (flyrad - 320)
	s.controller.goaly:+ Sin(flytheta) * (flyrad - 320)
	
	'reset if the circle point goes off the stage
	If Abs(s.controller.goalx) > stage.width Or Abs(s.controller.goaly) > stage.height Then s.controller.vars.set("flytheta", Rand(1,360))
	If Abs(s.x + TSIZE) > stage.width Or Abs(s.y + TSIZE) > stage.height Then s.controller.vars.set("flytheta", ATan2(s.y, s.x))

	'fly in circles around the goal
	AI.holdingPattern(s)
	
	AI.setGoalTo(s, "target")

	'shoot
	'fire if within range
	If approxDist(s.x-s.controller.goalx, s.y-s.controller.goaly) <= rangeGroup(s, 0) 
		If AI.fireAIWeapons(s, 0, s.controller.goalx, s.controller.goaly)'fire at current target coords (the gun is fixed tho so it'll be just straight forward)
			'face target slow
			AI.face(s, "goal", 55)
		Else
			'face target fast
			AI.face(s, "goal", 85)
		EndIf
	Else
		'face forwards
		AI.face(s, "go", 270)
	EndIf

Else
	'face towards where we want to go
	AI.face(s, "go", 270)
	'fly in circles around the goal
	AI.holdingPattern(s)
EndIf


'go in whatever direction we decided
AI.go(s, 1)


