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

'disable the flame thrower, beam, & torpedo, start invulnerable
If vars.get("inited") = 0
	For Local g:Gun = EachIn s.gunGroup[0]
		g.enabled = False
	Next
	
	For Local g:Gun = EachIn s.gunGroup[1]
		If Lower(g.name) = "spawner dodongo" Then g.enabled = False
	Next

	'For Local g:Gun = EachIn s.gunGroup[1]
	'	If Lower(g.name) = "beam_axel" Then g.enabled = False
	'Next
	
	'black center
	Local e:Emitter = new_emitter("blackhole_under")
	e.x = s.x
	e.y = s.y
	e.upload()

	e = new_emitter("blackhole")
	e.x = s.x
	e.y = s.y
	e.upload()
	
	'inward-coming sparklies
	e = new_emitter("warp_sparklies")
	e.num = -1
	e.x = s.x
	e.y = s.y
	e.movrotX = s.x
	e.movrotY = s.y
	e.posVar = 420
	e.lifetimer = 1000
	e.alpha = .9
	e.setRGB(200,100,100)
	e.upload()
	
	'make the gravity well
	Local well:GravityWell = New GravityWell
	well.init(s.x, s.y, 350, 3.4)'3.75)
	well.direction = -1'in
	well.faction = s.faction'no friendly fire for gravity well

	'gravity don't affect no dodongo
	s.ignoreMovement = True

	's.invulnerable = True
	vars.set("inited", 1)
EndIf

'always be trying to fire fire, photon spiral
If target <> Null Then AI.fireAIWeapons(s, 0, target.x, target.y)


'count the number of peons
vars.init("lastHP", s.stat.armour)
vars.init("peonnum", -1)
If timerTick(s.controller.timerList, "census", 550)
	Local stage# = vars.get("stage")
	
	'get the peons
	If vars.get("peonnum") = -1
		For Local other:Ship = EachIn shipList
			If other.behavior = "boss_dodongo_bubblenode"
				If Not ListContains(s.controller.targetList, other.placeholder) Then s.controller.targetList.addLast(other.placeholder)
			EndIf
		Next
	EndIf

	'lose dead peons
	For Local peon:Gertrude = EachIn s.controller.targetList
		If peon.dead Then ListRemove(s.controller.targetList, peon)
	Next
	
	Local peonnum = CountList(s.controller.targetList)
	
		
	'should we spawn some dudes?
	Local spawnguys = 0
	'due to dead peons
	If vars.get("peonnum") > 0 And vars.get("peonnum") > peonnum
		spawnguys = 3-peonnum'one after the first dead peon, two after the second, three on the third
		Print "spawning " + spawnguys + " from peon death ("+peonnum+") ["+vars.get("peonnum")+"]"
	EndIf
	'due to damage
	If s.armour <= vars.get("lastHP") - 50
		spawnguys = Floor((s.stat.armour - s.armour)/100)
		vars.set("lastHP", vars.get("lastHP")-50)
		Print "spawning " + spawnguys + " from damage"
	EndIf
		
	'spawn mooks each time we lose something
	'Print "checking for stage advance...  peon:" + vars.get("peonnum") + "  or   " + ((stage / 4.0) * s.stat.armour) + " > " + s.armour
	If spawnguys > 0
		Print "     spawnguys!" + spawnguys
		'enable the spawner
		For Local g:Gun = EachIn s.gunGroup[1]
			If Lower(g.name) = "spawner dodongo" Then g.enabled = True
		Next
		'use the spawner
		For Local i = 1 To spawnguys
			AI.fireAIWeapons(s, 1)
		Next
		'disable the spawner
		For Local g:Gun = EachIn s.gunGroup[1]
			If Lower(g.name) = "spawner dodongo" Then g.enabled = False
		Next
		
		'pulsar!
		s.activateAbility()
		
		'enable flamethrower
		If spawnguys = 1
			For Local g:Gun = EachIn s.gunGroup[0]
				If Lower(g.name) = "thrower_circle" Then g.enabled = True
			Next
		
		'enable phonton spiral
		ElseIf spawnguys >= 2
			For Local g:Gun = EachIn s.gunGroup[0]
				If Lower(g.name) = "photon_spiral" Then g.enabled = True
			Next
		EndIf


	EndIf
	
	vars.set("peonnum", peonnum)
EndIf

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




'slow down
If s.speed > 15 Then s.speed = s.speed - 15*timeMod Else s.speed = 0

'slo-mo death
'If s.dead Or s.armour <= 0 Then timeRate = 0
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
	
	'clear the gravitywell
	For Local well:GravityWell = EachIn gravityWellList
		well.remove()
	Next

	timeRate = .25
	
	'how long to leave timerate unchanged
	maintainTimeRate = 600

	new_shakytext("DEFENSE NETWORK DISMANTLED", 2500)
	'shakyText("FABULOUS", 2500, False, 8)
	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


