// makespetz.sqf
// spetnaz assault event
// makes truck (and soon to follow hind / boat)
// borne spetnaz assault that spawns in village and seeks either the airfield or MHQ ambulance to destroy Blufor spawnbases

if !(isServer) exitwith{};

_allspawns = [];
_allvecsNG = [];
_allvecsG = [];
_allunits = EGG_EVO_east1;
_targblue = getMarkerPos "T1";

_deletespetz =
{
	_handle = [_spetz2] execVM "scripts\delete.sqf";
	_handle = [_spetz3] execVM "scripts\delete.sqf";
	_handle = [_spetz4] execVM "scripts\delete.sqf";
	_handle = [_spetz5] execVM "scripts\delete.sqf";
};

//managed on and off in sinit.sqf with 
//if (Raiders >0)

_skillLevel = 1;

for [{_loop=0}, {_loop<1}, {_loop=_loop}] do
{
	//reinfdelay = 120, 180, 240, 300
	_aircomms = 12;
	if (EGG_aircomms ==0) then {_aircomms = 24};
	_rf = 0.5*(reinfdelay * _aircomms);
	sleep (round random _rf);

	_allspawns = ["raiders1_0","raiders1_1","raiders1_2","raiders1_3","raiders1_4","raiders1_5","raiders1_6","raiders1_7"];
	_maxs = (count _allspawns)-1;
	sleep 0.1;
//making waves of enemy attackers on foot

//group 1
	_spetz2 = createGroup (east);
	_pos21 = GetMarkerPos (_allspawns select round random _maxs);
	_spetzgrpcount = 6+ (round random 18);
	while {_spetzgrpcount > 0} do 
	{
		_allunits = EGG_EVO_east2;
		_max = (count _allunits)-1;
		_allunits select (round random (_max - 1)) createUnit [_pos21, _spetz2];Sleep 0.3;
		_spetzgrpcount = _spetzgrpcount-1;
		Sleep 0.11;
	};
//	{_x addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}]} forEach (units _spetz2);
	[_spetz2, 5] spawn EGG_EVO_skill;
	_recy = [objnull,_spetz2] execVM "scripts\grecycle.sqf";
	_spetz2 setCombatMode "RED";
	sleep random 20;
	_wp = _spetz2 addWaypoint [_targblue, 40];
	[_spetz2, 1] setWaypointType "HOLD";	

//group 2
	_spetz3 = createGroup (east);
	_pos22 = GetMarkerPos (_allspawns select round random _maxs);
	_spetzgrpcount = 6+ (round random 12);
	while {_spetzgrpcount > 0} do 
	{
		_allunits = EGG_EVO_east1;
		_max = (count _allunits)-1;
		_allunits select (round random (_max - 1)) createUnit [_pos22, _spetz3];Sleep 1.2;
		_spetzgrpcount = _spetzgrpcount-1;
		Sleep 0.11;
	};
//	{_x addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}]} forEach (units _spetz3);
	[_spetz3, 4] spawn EGG_EVO_skill;
	_recy = [objnull,_spetz3] execVM "scripts\grecycle.sqf";
	_spetz3 setCombatMode "RED";
	sleep random 20;
	_wp = _spetz3 addWaypoint [_targblue, 60];
	[_spetz3, 1] setWaypointType "HOLD";

//group 3
	_spetz4 = createGroup (east);
	_pos23 = GetMarkerPos (_allspawns select round random _maxs);
	_spetzgrpcount = 6+ (round random 12);
	while {_spetzgrpcount > 0} do 
	{
		_allunits = EGG_EVO_east2;
		_max = (count _allunits)-1;
		_allunits select (round random (_max - 1)) createUnit [_pos23, _spetz4];Sleep 1.2;
		_spetzgrpcount = _spetzgrpcount-1;
		Sleep 0.11;
	};
//	{_x addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}]} forEach (units _spetz4);
	[_spetz4, 4] spawn EGG_EVO_skill;
	_recy = [objnull,_spetz4] execVM "scripts\grecycle.sqf";
	_spetz4 setCombatMode "RED";
	sleep random 20;
	_wp = _spetz4 addWaypoint [_targblue, 10];
	[_spetz4, 1] setWaypointType "HOLD";

//group 4
	_spetz5 = createGroup (east);
	_pos24 = GetMarkerPos (_allspawns select round random _maxs);
	_spetzgrpcount = 6+ (round random 14);
	while {_spetzgrpcount > 0} do 
	{
		_allunits = EGG_EVO_east3;
		_max = (count _allunits)-1;
		_allunits select (round random (_max - 1)) createUnit [_pos24, _spetz5];Sleep 1.2;
		_spetzgrpcount = _spetzgrpcount-1;
		Sleep 0.11;
	};
//	{_x addEventHandler ["killed", {handle = [_this select 0] execVM "scripts\bury.sqf"}]} forEach (units _spetz5);
	[_spetz5, 5] spawn EGG_EVO_skill;
	_recy = [objnull,_spetz5] execVM "scripts\grecycle.sqf";
	_spetz5 setCombatMode "RED";
	sleep random 20;
	_wp = _spetz5 addWaypoint [_targblue, 30];
	[_spetz5, 1] setWaypointType "HOLD";
	waitUntil 
	{
		({alive _x} count units _spetz2) < 3 &&
		({alive _x} count units _spetz3) < 3 &&
		({alive _x} count units _spetz4) < 3 &&
		({alive _x} count units _spetz5) < 3
	};
	sleep 1;
	[West,"HQ"] SideChat "Human wave assault defeated!";
	playSound "Goodjob";
	sleep 2;
	[] call _deletespetz;
	sleep _rf;	
};
