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

'default to chasing the target
s.controller.vars.init("chase", 1)

'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

'has an offset firing pattern from other things
If s.controller.vars.get("scrambled") = 0
	s.controller.vars.set("scrambled", 1)
	For Local g:Gun = EachIn s.gunGroup[0]
		Local bump = Rand(0, timerMaxTime(g.timerList, "fireDelay"))
		timerBump(g.timerList, "fireDelay", bump)
	Next
EndIf

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

s.controller.vars.init("holdrad", Rand(100, 200))
Local circledist = Min(rangeGroup(s, 0) - 25, 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
AI.getTarget(s, 3000)

If target = Null
		
	AI.face(s, "go")
	AI.go(s, 1)
	
	'face the direction we've decided
	's.turn(ATan2(s.controller.goy, s.controller.gox), 1)
	
	'--go towards wherever we decided we wanted to go (faster if heavily weighted)
	'throttle = math.Max(script.getDist(gox, goy) / 200, .5)
	's.add_thrust(math.deg(math.ATan2(goy, gox)), throttle, 1)
	
	Local throttle = 1
	s.add_thrust(0, throttle, 0)
	
Else

	'set the goal coords to the target (to circle them)
	If s.controller.vars.get("chase") = 1 Then AI.setGoalTo(s, "target")
	
	'face the target & go in the direction we decided	
	AI.face(s, "goal")
	AI.go(s, 1)
	
	'shoot
	'fireAIWeapons(s, 0, target.x,  target.y)'fire at current target coords
	AI.fireAIWeapons(s, 0)'fire at predicted target coords
EndIf


'for spitters
If s.base.ord
	If (s.armour / s.stat.armour) <= .1
		AI.fireAIWeapons(s, 0)
		AI.fireAIWeapons(s, 1)
	EndIf
EndIf

