// makes roaming Hinds

EGG_killpilots =
{
	_chop = _this select 0;
	_crew = _this select 1;

	waitUntil { ({alive _x} count units _chop == 0) or not (canmove _chop) or (isnull _chop)};
	sleep 30;
	{_x setDamage 1} foreach _crew;
};

for [{_loop=0}, {_loop<1}, {_loop=_loop}] do
{

	_aircomms = 12;
	if (EGG_aircomms ==0) then {_aircomms = 24};
	//reinfdelay = 120, 180, 240, 300
	_rf = 0.5*(reinfdelay * _aircomms);
	sleep _rf;

	_startsd = ["EnemyAir01","EnemyAir02","EnemyAir03","EnemyAir04","EnemyAir05","EnemyAir06","EnemyAir07","EnemyAir08"];
	_poscreate = getmarkerpos (_startsd select (round random 7));
	_pilot = createGroup (east);

	_rndx = random 600;
	_rndy = random 600;
	_kpos = [(_poscreate select 0)-300 +_rndx,(_poscreate select 1)-300+_rndy,1500];

	_allunits = EGG_EVO_mepilot;
	_maxu = (count _allunits)-1;

	_upos = getmarkerpos "centerp";
	_dcounta = 5;
	_d = 0;
	while {_d <= _dcounta} do 
	{
		(_allunits select round random _maxu) createUnit [_upos, _pilot];Sleep BIS_EVO_GlobalSleep;
		_d = _d+1;
		sleep 0.1;
	};

//adding hinds
	_allvecs = EGG_EVO_eastheli2;
	_max = (count _allvecs)-1;
	_heli = createVehicle [_allvecs select (round random _max), _kpos, [], 50, "FLY"];Sleep BIS_EVO_GlobalSleep;
	_heli setpos [getpos _heli select 0, getpos _heli select 1, 1500];
	_heli setdir (random 100);
	_sumark = [_heli] execVM "scripts\air\sumarker.sqf";

	(units _pilot select 0) moveInDriver _heli;
	(units _pilot select 1) moveInTurret[_heli,[0]];
	_heli engineon true;
	_type0 = Typeof _heli;

//adding
	_heli1 = createVehicle [_allvecs select (round random _max), _kpos, [], 50, "FLY"];Sleep BIS_EVO_GlobalSleep;
	_heli1 setpos [getpos _heli1 select 0, getpos _heli1 select 1, 1500];
	_heli1 setdir (random 100);
	_sumark = [_heli1] execVM "scripts\air\sumarker.sqf";

	(units _pilot select 2) moveInDriver _heli1;
	(units _pilot select 3) moveInTurret[_heli1,[0]];
	_heli1 engineon true;
	_type1 = Typeof _heli1;

	_heli2 = createVehicle [_allvecs select (round random _max), _kpos, [], 50, "FLY"];Sleep BIS_EVO_GlobalSleep;
	_heli2 setpos [getpos _heli2 select 0, getpos _heli2 select 1, 1500];
	_heli2 setdir (random 100);
	_sumark = [_heli2] execVM "scripts\air\sumarker.sqf";

	(units _pilot select 4) moveInDriver _heli2;
	(units _pilot select 5) moveInTurret[_heli2,[0]];
	_heli2 engineon true;
	_type2 = Typeof _heli2;

//adding troops

	_maxcrew0 = 0;
	_maxcrew1 = 0;
	_maxcrew2 = 0;
	if (enemynumdiv==1) then 
	{
		_maxcrew0 = getNumber (configFile >> "CfgVehicles" >> _type0 >> "transportSoldier");
		_maxcrew1 = getNumber (configFile >> "CfgVehicles" >> _type1 >> "transportSoldier");
		_maxcrew2 = getNumber (configFile >> "CfgVehicles" >> _type2 >> "transportSoldier");
	};

	_helicount = 3;
	_z = 0;
	while {_z < _helicount} do 
	{
		if (_z ==0) then {_vec = _heli0; _maxcrew = _maxcrew0};
		if (_z ==1) then {_vec = _heli1; _maxcrew = _maxcrew1};
		if (_z ==2) then {_vec = _heli2; _maxcrew = _maxcrew2};
		_Crewcargo = EGG_EVO_east1;
		_ccargo = (count _Crewcargo)-1;
		_n = 0;
		while {_n < _maxcrew} do 
		{
			_unit = _pilot createUnit [_Crewcargo select (round random _ccargo), _upos, [], 0, "NONE"];
			_unit moveinCargo _vec;
			_n = _n+1;
			Sleep 0.1;
		};
	_z=_z+1;
	Sleep 0.1;
	};

	_pilot setFormation "WEDGE";
	_pilot setCombatMode "YELLOW";
	_handle = [_pilot] execVM "scripts\flightpath.sqf";
	{_x addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}]} forEach (units _pilot);

	_heli addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}];
	_spawne = [_heli] spawn {[_this select 0] call BIS_EVO_idelSVEC};
	_killh1 = [_heli,crew _heli] spawn {[_this select 0,_this select 1] call EGG_killpilots};

//adding
	_heli1 addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}];
	_spawnf = [_heli1] spawn {[_this select 0] call BIS_EVO_idelSVEC};
	_killh2 = [_heli1,crew _heli1] spawn {[_this select 0,_this select 1] call EGG_killpilots};

	_heli2 addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}];
	_spawng = [_heli2] spawn {[_this select 0] call BIS_EVO_idelSVEC};
	_killh3 = [_heli2,crew _heli2] spawn {[_this select 0,_this select 1] call EGG_killpilots};

	_addkit = [_heli] spawn {[_this select 0] call EGG_EVO_Fillcargo};
	_addkit1 = [_heli1] spawn {[_this select 0] call EGG_EVO_Fillcargo};
	_addkit2 = [_heli2] spawn {[_this select 0] call EGG_EVO_Fillcargo};

//	_nul = _heli addeventhandler ["HandleDamage", {if ((_this select 4) isKindOf "MissileCore") then {_vec setdamage 1};}];
//	_nul1 = _heli1 addeventhandler ["HandleDamage", {if ((_this select 4) isKindOf "MissileCore") then {_vec setdamage 1};}];
//	_nul2 = _heli2 addeventhandler ["HandleDamage", {if ((_this select 4) isKindOf "MissileCore") then {_vec setdamage 1};}];

	sleep 1.0;
	waitUntil { (not (alive _heli) AND not (alive _heli1) AND not (alive _heli2) ) or ( isNull (driver _heli) AND isNull (driver _heli1) AND isNull (driver _heli2) )};
	sleep 1.0;
	if (alive _heli) then {_heli setDamage 1};
	if (alive _heli1) then {_heli1 setDamage 1};
	if (alive _heli2) then {_heli2 setDamage 1};
	sleep _rf;
	if (alive (units _pilot select 0)) then {(units _pilot select 0) setDamage 1};
	if (alive (units _pilot select 1)) then {(units _pilot select 1) setDamage 1};
	if (alive (units _pilot select 2)) then {(units _pilot select 2) setDamage 1};
	if (alive (units _pilot select 3)) then {(units _pilot select 3) setDamage 1};
	if (alive (units _pilot select 4)) then {(units _pilot select 4) setDamage 1};
	if (alive (units _pilot select 5)) then {(units _pilot select 5) setDamage 1};

};
