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

'can't move
s.speed = 0

'look for a target
getTarget(s, 600, 3000)

Local clamped = s.controller.vars.get("clamped")
Local justchanged = False

'if almost dead, don't clamp up
If armour <= 5
	If clamped Then justchanged = True
	clamped = 0
Else
	'open and close on a cycle (time overwritten during boss_reef behavior)
	s.controller.vars.init("cycle", 4000)
	If timerTick(s.controller.timerList, "cycletimer", s.controller.vars.get("cycle"))
		clamped = Not clamped
		justchanged = True
	EndIf
EndIf

'if clamped, button up
If clamped
	'reduce incoming damage
	s.damageMod = 0.05
	
	If justchanged
		Local clamp:Emitter = new_emitter("shell")
		clamp.interval = 0
		clamp.lifetimer = 20
		clamp.num = -1'infinite inifinite inifinitite ininifinititie
		clamp.attach(s)
		clamp.upload()
		
		'stop the guns
		For Local g:Gun = EachIn s.gunGroup[0]
			g.burst = 0
		Next
	EndIf
Else
	'normal damage
	s.damageMod = 1.0
	
	'turn off the clamped graphic
	If justchanged
		Local clamp:Emitter = new_emitter("shield")
		clamp.num = 0
		clamp.attach(s)
		clamp.upload(0, 0, 1)
	
		'reset the guns
		For Local g:Gun = EachIn s.gunGroup[0]
			timerSet(g.timerList, "fireDelay")
		Next
	EndIf

	If target <> Null
		'face the target
		setGoalTo(s, "target")
		face(s, "goal")

		'if within range
		If approxDist(s.x-s.controller.goalx,s.y-s.controller.goaly) <= rangeGroup(s, 0) 
			fireAIWeapons(s, 0)								'fire at predicted target coords
		EndIf
	EndIf
EndIf

'update the stored clamp value
s.controller.vars.set("clamped", clamped)