
; Unit on guard


	_unit = _this
	_magazine = "dune_M16_mag"
	_engageDIST = 17
	_engageMIN = 0 
	_hinf = false
	? "dune_RL" in weapons _unit : _engageDIST=40; _engageMIN=30; _hinf=true; exit
	


	
	#Wait
	~0.1
	? !alive _unit : exit
	
	_id = _unit call findID
	? COMMANDS select _id != 0 : goto "Wait"


	#Search
	? count ENEMIES == 0 : goto "wait"
	_listUnits =+ ENEMIES
	
		_i = 0
		_distances = []
		#MakeDistances
		_unit2 = (_listUnits select _i)
		_dist = _unit distance _unit2
		_distances = _distances + [_dist]
		? _i < count _listUnits - 1 : _i=_i+1; goto "MakeDistances"

		_sorted = [[_distances,_listUnits], 0, count _distances - 1] call quicksort2
	
		_firstDist = (_sorted select 0) select 0
		_firstEnem = (_sorted select 1) select 0

		? speed _this == 0  &&  _firstDist < _engageDIST  &&  _firstDist > _engageMIN : _unit setCombatMode "YELLOW"; _unit reveal _firstEnem; _unit doTarget _firstEnem; goto "Wait"
		
	_unit setCombatMode "BLUE"
	goto "Wait"
