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

'set blink ability values
If s.controller.vars.get("setblink") = 0
	s.abilitySetTimer("Blink", "cooldown", 3000)
	s.abilitySetVar("Blink", "cost", 0)
	s.controller.vars.set("setblink", 1)
	
	'MAKE THE SHOTGUN fixed forward. sorry capslock
	For Local g:Gun = EachIn s.gunGroup[0]
		If Lower(g.name) = "shotgun bulwark" Then g.fixed = 4
	Next
	s.controller.vars.set("init", 1)
EndIf

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

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

	'how many summons we can do
	vars.init("summons", 5)

	'should we blink?
	Local port = False
	
	If s.armour > 8
		If s.recent_damage >= 14 Then port = True
		
		'port away from the center
		'If Abs(s.x) < 150 Then port = True
		'If Abs(s.y) < 150 Then port = True
	
		'blink & summon enemies
		If port
			Local oldx = s.x, oldy = s.y
			'try to activate our ability (AKA blink) -- if we do, then also fire our alternate weapon (AKA mirror image)
			Local xtar = target.x + Rand(-(stage.width-600), stage.width-600)
			Local ytar = target.y + Rand(-(stage.height-600), stage.height-600)
			'keep it away from the center gate
			If Abs(xtar) < 500 Then xtar = 500*Sgn(xtar)
			If Abs(ytar) < 500 Then ytar = 500*Sgn(ytar)
	
			If s.activateAbility(xtar, ytar, "Blink") And vars.get("summons") > 0
				s.speed = 0
				'summon all mooks
				For Local g:Gun = EachIn s.gunGroup[1]
					g.fire(oldx,oldy)
				Next
				vars.set("summons", vars.get("summons") - 1)
			EndIf
		EndIf
	EndIf
	
	Rem
	If s.armour <= 15
		'lash out
		For Local g:GunAuto = EachIn s.gunGroup[0]
			If Lower(g.name) = "peashooter_burst"
				g.burst = 10'CONTINUOUS
				g.shotspeed = 375
			EndIf
		Next
	EndIf
	EndRem
	
	'face the target
	AI.setGoalTo(s, "target")
	AI.face(s, "goal")
	
	'steamroll the target
	'Local theta# = ATan2((s.controller.goaly-s.y), (s.controller.goalx-s.x))
	'weight desire To go towards that direction
	'Local dx = Cos(theta)*80
	'Local dy = Sin(theta)*80
	
	'set the go direction and then do it
	's.controller.gox = s.controller.gox + dx
	's.controller.goy = s.controller.goy + dy
	'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


'try to avoid collisions, strafe if applicable
AI.setProximityAvoid(s)
If Abs(s.controller.gox > 10) Or Abs(s.controller.goy > 10)
	AI.go(s, 1)
Else
	'go forward
	s.add_thrust(0, 1.0, 0)
EndIf


'slo-mo death
'If s.dead Or s.armour <= 0 Then shakyText("A WINNER IS YOU!!!", 2500, False)

Rem
If s.dead Or s.armour <= 0
	new_shakytext("BOOM", 1500)
	'shakyText("FABULOUS", 2500, False, 8)
	For Local i = 0 To 5
		Local e:Emitter = new_emitter("shipexplode")
		e.y = s.y + Rand(-350,350)
		e.x = s.x + Rand(-350,350)
		e.num = 30
		e.upload()
		
		Local es:Emitter = new_emitter("shipexplode_slow")
		es.x = e.x
		es.y = e.y
		es.num = 15
		es.upload()
	Next
EndIf
EndRem

'nonbosses don't drop databanks
If vars.get("boss") = 0
	ClearList(s.dropList)
Else
	If s.dead Or s.armour <= 0
	
		For Local nemesis:Ship = EachIn shipList
			If nemesis.faction = s.faction And nemesis <> s
				nemesis.noItemDrop()
				nemesis.death()
			EndIf
		Next
	
		new_shakytext("NEMISIS BULWARK CRUMBLED", 2500)
		
		timeRate = .25
		maintainTimeRate = 600'how long to leave timerate unchanged
		
		For Local i = 0 To 10
			Local e:Emitter = new_emitter("shipexplode")
			e.y = s.y + Rand(-150,150)
			e.x = s.x + Rand(-150,150)
			e.num = 30
			e.upload()
			
			Local es:Emitter = new_emitter("shipexplode_slow")
			es.x = e.x
			es.y = e.y
			es.num = 15
			es.upload()
		Next

	EndIf
EndIf
