
; Order to destroy given unit

	_unit = _this select 0
	_enemy = _this select 1
	_wp = _this select 2
	
	_x = getpos _wp select 0
	_engageDIST = 15
	_engageMIN = 0 
	? "dune_RL" in weapons _unit : _engageDIST=40; _engageMIN=30
	



	
	#Distance
	~0.05
	? !alive _unit : exit
	
	_id = _unit call findID
	? COMMANDS select _id != 2 : _unit setCombatMode "BLUE"; exit
	
	? (getpos _wp select 0) != _x : exit

	? !alive _enemy  : _unit move getPos _unit; _unit setCombatMode "BLUE"; COMMANDS set [_id,0]; exit
	
	_dist = _unit distance _enemy
	if (_dist < _engageDIST && _dist > _engageMIN) then {_unit move getPos _unit; _unit setCombatMode "YELLOW"; _unit doTarget _enemy} else {goto "Move"}
	
	goto "Distance"
	

	

	
	#Move
	_unit setCombatMode "BLUE"
	? _dist > _engageMIN : _unit move getpos _enemy; goto "Distance"
	
	
; For heavy infantry	
	
	_dir = (((getpos _enemy select 0) - (getpos _unit select 0)) atan2 ((getpos _enemy select 1) - (getpos _unit select 1)))
	? _dir < 0 : _dir=_dir+360
	_dir = _dir + 180
	_meters = _engageMIN - _dist +1
	
	_x = (getpos _unit select 0) + _meters * (sin(_dir)) 
	_y = (getpos _unit select 1) + _meters * (cos(_dir)) 
	_unit move [_x,_y,0]
	
	@!alive _unit || _unit distance _enemy > _engageMIN
	? !alive _unit : exit
	_unit setCombatMode "YELLOW"
	_unit doTarget _enemy
	_unit doFire _enemy

	~0.05
	goto "Distance"
	