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

s.controller.vars.init("inert", 1)

'look for targets
s.controller.vars.init("checkinterval", 4000 + Rand(-500,500))
If s.controller.hasTimerTicked("multiTargetCheck", s.controller.vars.get("checkinterval"))	
	'clear the target list of everything but anemones (so we don't keep rechecking because of them; will be slightly more efficient than clearlist)
	'clearList(s.controller.targetList)
	For Local prey:Gertrude = EachIn s.controller.targetList
		If Not prey.behavior = "anemone" Then ListRemove(s.controller.targetList, prey)
	Next

	'and get new targets (of ANY faction)
	Local targetRange = 600
	Local tar:Gertrude
	Repeat									  '2 means we'll target anybody
		tar = closestShip(s.x, s.y, s.faction, 2, targetRange, s.controller.targetList)
		If tar <> Null Then s.controller.targetList.addlast(tar)
	Until tar = Null'until we can't find a valid target within range
EndIf

'fire beam at all non-inert, non-anemones
If Not ListIsEmpty(s.controller.targetList)
	Local beamrange# = rangeGroup(s, 0)

	For Local tar:Gertrude = EachIn s.controller.targetList
		'lose dead targets
		If tar.dead
			ListRemove(s.controller.targetList, tar)
			Continue
		EndIf
		
		'lose inappropriate targets
		If tar.behavior = "anemone" Or Left(tar.behavior, 5) = "inert" Or tar.faction = s.faction
			ListRemove(s.controller.targetList, tar)
			Continue
		EndIf
		
		'if within range
		Local dx = tar.x-s.x
		Local dy = tar.y-s.y
		Local dist# = approxDist(dx, dy)
		If dist < beamrange
			'fire ANEMONE BEAM at the other target
			fireShipWeapons(s, 0, tar.x, tar.y)
		EndIf		
	Next
EndIf