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

'set blink ability values
If s.controller.vars.get("setblink") = 0
	s.controller.vars.set("setblink", 1)
	
	s.abilitySetVar("Blink", "cost", 0)
	s.abilitySetTimer("Blink", "blink_interval", 4500)	'time between natural blinks
	s.abilitySetTimer("Blink", "cooldown", 1000)		'minimum time between blinks
	s.abilitySetVar("Blink", "notify", 0)
	s.controller.vars.set("mindist", 100)				'blinks if target is closer than this				
EndIf


'look for a target
AI.getTarget(s, 2500)
	
'slow down
If s.speed > 1 Then s.speed = s.speed - 1 * (timePass / 20.0)

'act as a turret
If target <> Null
	AI.setGoalTo(s, "target")
	AI.face(s, "goal")			'face the target
	
	'fireAIWeapons(s, 0, target.x,  target.y)'fire at current target coords
	AI.fireAIWeapons(s, 0)'fire at predicted target coords

	'blink?
	Local activate = False
	Local a:Ability = s.abilityGet("Blink")
	If a <> Null
		'if it's just time
		If timerTick(a.timerList, "blink_interval") Then activate = True
		
		'if the target is too close
		If approxDist(target.y-s.y, target.x-s.x) < s.controller.vars.get("mindist") Then activate = True
	
		'activate our ability (assumed to be blink)
		If activate
			Local xdir = binsgn(Rand(0,1))
			Local ydir = binsgn(Rand(0,1))
			s.activateAbility(target.x + Rand(100, 240)*xdir, target.y + Rand(100, 240)*ydir)
		EndIf
	EndIf
EndIf