_oldhour = EVOhour; //param2;
EGG_EVO_NoHumanLeader = [];

_EVO_Weath =
{
	_xmin = (getmarkerpos "EnemyAir01" select 0);
	_ymin = (getmarkerpos "EnemyAir01" select 1);
	_ymax = (getmarkerpos "EnemyAir05" select 1) - (getmarkerpos "EnemyAir01" select 1) ;
	_xmax = (getmarkerpos "EnemyAir05" select 0) - (getmarkerpos "EnemyAir01" select 0);
	_randx = 0;
	_randy = (random _ymax);
	if ((position rainy select 0) > _xmax) then
	{
		rainy setpos [(_xmin + _randx),(_ymin + _randy),0];
	};
	if ((position rainy2 select 0) > _xmax) then
	{
		rainy2 setpos [(_xmin + _randx),(_ymin + _randy),0];
	};
	if ((position rainy3 select 0) > _xmax) then
	{
		rainy3 setpos [(_xmin + _randx),(_ymin + _randy),0];
	};	
	rainy setpos [(position rainy select 0)+10,(position rainy select 1),0];"rainmark" setMarkerPos position rainy;
	rainy2 setpos [(position rainy2 select 0)+10,(position rainy2 select 1),0];"rainmark2" setMarkerPos position rainy2;
	rainy3 setpos [(position rainy3 select 0)+10,(position rainy3 select 1),0];"rainmark3" setMarkerPos position rainy3;
};

EGG_EVO_listplayers = 
{
	_list = list EGG_EVO_ALLWEST;
	EGG_EVO_Playerlist = [];
	_i=0;
	while {_i < (count _list)} do 
	{
	
		_unit = _list select _i;
		if(not (_unit isKindOf "Man")) then
		{		
			{EGG_EVO_Playerlist = EGG_EVO_Playerlist + [_x]} forEach (crew _unit);
		}
		else
		{
			EGG_EVO_Playerlist = EGG_EVO_Playerlist + [_unit];
		};
		_i=_i+1;
	};
	EGG_EVO_Playercount = count EGG_EVO_Playerlist;
	if(EGG_EVO_Playercount == 0) then {EGG_EVO_Playercount = 1};
	EGG_EVO_Playerlist;//wtf is this?
};

EGG_EVO_NoHuman =
{
	_grp = _this select 0;
	_unit = leader _grp;
	sleep 10.0;
	if(not isPlayer (leader _unit) and not isNull _unit) then 
	{
		sleep 10.0;
		if(not isPlayer (leader _unit)) then 
		{		
			_unit setpos position vehicle _unit;
			Sleep 1.0;
			_unit = vehicle _unit;
			_unit setDamage 1;
			hideBody _unit;
		};
	};
	EGG_EVO_NoHumanLeader=EGG_EVO_NoHumanLeader-[_unit];
};

// Removes unused objects and weapon holders
_EVO_Clean =
{
	{if(count units _x == 0) then {deletegroup _x}} foreach allGroups; // Remove empty groups
//	_Objects = (getMarkerPos "ammob1") nearObjects 60;{if (_x isKindOf "WeaponHolder") then {deletevehicle _x}} forEach _Objects;

//adding
//{deleteVehicle _x} forEach allDead;
	{deleteVehicle _x} forEach nearestObjects [(getMarkerPos "Weapons"),["GroundWeaponHolder"],10];
//	{deleteVehicle _x} forEach nearestObjects [(getMarkerPos "respawnzone"),["WeaponHolder","GroundWeaponHolder"],4];
	{deleteVehicle _x} forEach nearestObjects [(getMarkerPos "spawnstart"),["WeaponHolder","GroundWeaponHolder"],7];
	_Objects = (getMarkerPos "Sick-Bay") nearObjects 10;{if ((_x isKindOf "Man") and !(alive _x)) then {hidebody _x}} forEach _Objects;
	_Objects2 = (getMarkerPos "spawnstart") nearObjects 10;{if ((_x isKindOf "Man") and !(alive _x)) then {hidebody _x}} forEach _Objects;
		{
			if(side _x == west) then 
			{
				if(not IsPlayer (leader _x)) then
				{
					if(not ((leader _x) in EGG_EVO_NoHumanLeader)) then 
					{
						_del = [_x] spawn {[_this select 0] call EGG_EVO_NoHuman};
						EGG_EVO_NoHumanLeader = EGG_EVO_NoHumanLeader+[_x]
					}
				}
			}
		} foreach allGroups;
/*
	_mark = format["%1mash",dunit];
	deleteMarker _mark;
	_mark = format["%1farp",dunit];
	deleteMarker _mark;
*/
};	
	
/*	
	_list = [] call EGG_EVO_listplayers;
	_count = count _list;
	_i = 0;
	if(_count > 0) then
	{
		while {_i < _count} do
		{
			_unit = _list select _i;
			if(not isPlayer (leader group _unit) and not (_unit in EGG_EVO_NoHumanLeader)) then
			{		
				_del = [_x] spawn {[_this select 0] call EGG_EVO_NoHuman};EGG_EVO_NoHumanLeader = EGG_EVO_NoHumanLeader+[_x]
			};
			_i = _i+1;
			Sleep 0.1;
		}; 
	};
*/


_EVO_timesync =
{
	EGG_EVO_gdate = date;
	EGG_EVO_gdate_packed = str (EGG_EVO_gdate); publicvariable "EGG_EVO_gdate_packed";
	_oldhour = (date select 3);
};

for [{_loop=0}, {_loop<1}, {_loop=_loop}] do
{	
	_time = time;
	[] call _EVO_Weath;
	sleep 1.011;
	if (_oldhour != (date select 3)) then {[] call _EVO_timesync};
	_newtime = time - _time;	
	[] call _EVO_Clean;
	sleep 180;
};
