'== included in the AI scripts file =='
s.spin = 2

'look for an enemy target
AI.getTarget(s, 600)
If s.controller.target <> Null Then fireShipWeapons(s, 1)


'try to avoid collisions: sets gox & goy to point away from nearby ss
AI.setProximityAvoid(s)

'look for the axel / other spokes
s.controller.vars.init("checkinterval", 5000 + Rand(-500,500))
If ListIsEmpty(s.controller.targetList) Or timerTick(s.controller.timerList, "spokecheck", s.controller.vars.get("checkinterval"))
	Local spokenum#	'number of found other spokes
	Local spoke#	'which spoke we are
	ClearList(s.controller.targetList)
	For Local other:Ship = EachIn shipList
		If other.behavior = "boss_axel" Then s.controller.targetList.addLast(other.placeholder)
		If other.behavior = "boss_aspoke"
			spokenum:+ 1
			If other.netspriteIDNUM < s.netspriteIDNUM Then spoke:+ 1
		EndIf
	Next
	s.controller.vars.set("spoke", spoke / spokenum)
EndIf

'lose dead targets
Local checkList:TList = s.controller.targetList.Copy()
For Local peon:Gertrude = EachIn checkList
	If peon.dead Then ListRemove(s.controller.targetList, peon)
Next


'if we found the axel
If Not ListIsEmpty(s.controller.targetList)
	For Local tar:Gertrude = EachIn s.controller.targetList
		'lose dead targets
		'If tar.dead
		'	ListRemove(s.controller.targetList, tar)
		'	Continue
		'EndIf
			
		'get target coordinates
		s.controller.goalx = tar.x
		s.controller.goaly = tar.y
			
		'IF WITHIN RANGE???
		Local dist# = approxDist(tar.x-s.x, tar.y-s.y)
		If dist < rangeGroup(s, 0)
			fireShipWeapons(s, 0, tar.x, tar.y)'fire REPAIR BEAM at each target coord
		EndIf
		
		'lose dead targets
		If tar.dead Then ListRemove(s.controller.targetList, tar)
	Next
EndIf

'circle around the axel (every 15s)
'timerInit(s.controller.timerList, "wheel", 15000)
'timerTick(s.controller.timerList, "wheel")

'current dist theta we should be from the axel
Local circledist = 300
Local theta# = s.controller.vars.get("spoke") * 360' + timerTween(s.controller.timerList, "wheel") * 360

'Print "     at theta " + theta

Local movx = s.controller.goalx + Cos(theta)*circledist
Local movy = s.controller.goaly + Sin(theta)*circledist
		
'find distance and angle to the target move
Local movtheta = ATan2((movy-s.y), (movx-s.x))
	
'weight desire To go towards that direction
Local dx = Cos(movtheta)*80
Local dy = Sin(movtheta)*80
	
'store the new direction
s.controller.gox = s.controller.gox + dx
s.controller.goy = s.controller.goy + dy	

'go in the decided direction
AI.go(s)






