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

Local newTarget = False
If target = Null Then newTarget = True'if we get a target, it'll be a new one

'look for a target
AI.getTarget(s, 600, 3000)
	
'slow down
If s.speed > 5 Then s.speed = s.speed - 5*timeMod Else s.speed = 0

s.controller.vars.init("clamped", 0)

'if damaged, button up
If s.recent_damage_timer > 0 And s.armour > 0
	'reduce incoming damage
	s.damageMod = 0.50
	s.addDamageBuffer(1)
	
	'track the recent damage, if it changes
	Local changed = False
	If s.recent_damage <> s.controller.vars.get("recentdamage") Then changed = True
	s.controller.vars.set("recentdamage", s.recent_damage)
	
	'put a clamped graphic on it
	If changed
		Rem
		Local clamp:Emitter = new_emitter("shell")
		clamp.lifetimer = s.recent_damage_delay
		clamp.attach(s)
		clamp.upload()
		EndRem
		
		s.controller.vars.set("clamped", 1)
		
		'stop the guns (unless we just got our target)
		If Not newTarget
			For Local g:Gun = EachIn s.gunGroup[0]
				g.burst = 0
			Next
		EndIf
	EndIf
	
	'can't move
	s.speed = 0

Else
	'normal damage
	s.damageMod = 1.0
	
	'turn off the clamped graphic
	If s.controller.vars.get("clamped") = 1
		'Local clamp:Emitter = new_emitter("shield")
		'clamp.num = 0
		'clamp.attach(s)
		'clamp.upload(0, 0, 1)
		
		s.controller.vars.set("clamped", 0)
		
		'reset the guns
		For Local g:Gun = EachIn s.gunGroup[0]
			timerSet(g.timerList, "fireDelay")
		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


