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

'can't move
s.speed = 0

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

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

'if almost dead, don't clamp up
If s.armour <= 5
	If clamped Then justchanged = True
	clamped = 0
Else
	'open and close on a cycle (time overwritten during boss_reef behavior)
	timerInit(timerList, "close", Rand(2000,4000))'timer for being closed
	timerLoop(timerList, "close", False)
	timerInit(timerList, "open", Rand(1700,2000))'timer for being open
	timerLoop(timerList, "open", False)
	
	If Not timerDinged(timerList, "close")
		clamped = True
		If timerTick(timerList, "close")
			justchanged = True
			timerSet(timerList, "open")			
			'reset the guns
			For Local g:Gun = EachIn s.gunGroup[0]
				timerSet(g.timerList, "fireDelay")
				g.burst = 0
			Next
		EndIf
	Else
		clamped = False
		If timerTick(timerList, "open")
			justchanged = True
			timerSet(timerList, "close")
		EndIf
	EndIf
EndIf

'if clamped, button up
If clamped
	'reduce incoming damage
	's.damageMod = 0.05
	s.addDamageBuffer(12)
	
	s.ignoreCollisions = True
	
	If justchanged
		Rem
		Local clamp:Emitter = new_emitter("shell")
		clamp.interval = 20
		clamp.lifetimer = 20
		clamp.num = -1'infinite inifinite inifinitite ininifinititie
		clamp.attach(s)
		clamp.upload()
		EndRem
		
		'stop the guns
		For Local g:Gun = EachIn s.gunGroup[0]
			g.burst = 0
		Next
	EndIf
Else
	'normal damage
	's.damageMod = 1.0
	
	s.ignoreCollisions = False
	
	'turn off the clamped graphic
	If justchanged
		Rem
		Local clamp:Emitter = new_emitter("shell")
		clamp.num = 0
		clamp.attach(s)
		clamp.upload(0, 0, 1)
		EndRem
	
		'reset the guns
		For Local g:Gun = EachIn s.gunGroup[0]
			timerSet(g.timerList, "fireDelay")
			
			'(cheatyface modify the mite spawner to be more frequent)"
			'If Lower(g.name) = "spawner mite"
			'	g.fireDelay = 3000 + Rand(-500,1000)
			'EndIf
		Next
	EndIf

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

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

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


Rem
'if damaged, start shooting vomit in that direction (regardless of clamp status)
If s.recent_damage_timer > 0
	For Local g:Gun = EachIn s.gunGroup[1]
		'make it continual
		g.burst = 15
	Next

	'shoot outwards from the reef
	Local tx = s.x + Cos(s.controller.vars.get("angle")+180) * 100
	Local ty = s.y + Sin(s.controller.vars.get("angle")+180) * 100
	fireAIWeapons(s, 1, tx,  ty)	
EndIf
EndRem
