
; Enemy unit attack base


_unit = _this select 0

		_i = 0
		_distances = []
		_list =+ BUILT
		#MakeDistances
		_dist = _unit distance (_list select _i)
		_distances = _distances + [_dist]
		? _i < count _list - 1 : _i=_i+1; goto "MakeDistances"
		_sorted = [[_distances,_list], 0, count _distances - 1] call quicksort2
		_built = (_sorted select 1) select 0

_built = BUILT select 1
? !alive _built : exit

_dir = getdir camtarget
_unit move [ (getpos _built select 0) + 14 * (sin(_dir)), (getpos _built select 1) + 18 * (cos(_dir)), 0]
;_unit setPos [ (getpos _built select 0) + 14 * (sin(_dir)), (getpos _built select 1) + 18 * (cos(_dir)), 0]


goto "fire"

? (_unit distance _built) < 20 : goto "Fire"

	_dir = (((getpos _built select 0) - (getpos _unit select 0)) atan2 ((getpos _built select 1) - (getpos _unit select 1)))
	? _dir < 0 : _dir=_dir+360
	_dir = _dir + 180

	_x = (getpos _built select 0) + 18 * (sin(_dir))
	_y = (getpos _built select 1) + 18 * (cos(_dir))
	_z = 0

	_unit move [_x,_y,_z]
	_logic = "logic" camCreate [0,0,0]
	_logic setPos [_x,_y,_z]
	camtarget setPos [_x,_y,_z]
	Drop ["cl_water","","Billboard",1,10,[0,0,0],[0,0,0.02],0,1.2,1.1,0,[1.2,0,0],[[0.8,0,0,1]],[0,1,0],1,0.8,"","",_logic]


	@(_unit distance _built) < 26

	
	
#Fire
~1
_unit setCaptive true
@speed _unit == 0 && (_unit distance _built) < 20


;_unit move getpos _unit

_target = "lesIETA" createVehicle [0,0,0]

_x = (getpos _built select 0)
_y = (getpos _built select 1)
_z = 0.3

_target setPos [_x,_y,_z]
;camtarget setPos [_x,_y,_z]

#reveal
? _unit knowsAbout _target < 1 : _unit reveal _target; goto "Reveal"

_unit doTarget _target
_unit doFire _target
_unit setCombatMode "YELLOW"



@count ENEMIES == 1
_unit setCaptive false


#loop
~0.01

? !alive _unit : exit
? !alive _built : BUILT = BUILT - [_built]; goto "END"
_dir = getdir _unit

goto "loop"


#END
_built = (BUILT select 2)
_dir = getDir _built

_dista = 0 + (random 20)
_distb = 18 + 0

_x = (getPos _built select 0) + _distb * (sin(_dir)) + _dista * (cos(_dir))
_y = (getPos _built select 1) + _distb * (cos(_dir)) - _dista * (sin(_dir))
_z = 0

[_unit, _x,  _y] exec "Enemy\Guard.sqs" 