_oldhour = date select 3;
_tscore = 0;
_rankmes = localize "STR_M04t82";
_currentprog = -1;
_EGG_stations = [];

EGG_EVO_CWeath =
{
	"rainmarkt" setMarkerPosLocal getMarkerPos "rainmark";
	
	"rainmarkt2" setMarkerPosLocal getMarkerPos "rainmark2";
	
	"rainmarkt3" setMarkerPosLocal getMarkerPos "rainmark3";
};

EGG_EVO_stationRepair = 
{
	_vec = (vehicle player);
	_type = typeOf vehicle player;
	_EGG_stations = [];
	_EGG_stations = nearestObjects [player, ["Land_dp_bigTank_F","Land_dp_smallTank_F","Land_FuelStation_Build_F","Land_FuelStation_Feed_F","Land_FuelStation_Shed_F","Land_FuelStation_Sign_F","Land_FuelStation_Build_ruins_F","Land_FuelStation_Shed_ruins_F","Land_wagon_tanker","Land_fuel_tank_stairs","Land_Ind_TankSmall","Land_fuel_tank_big","Land_A_FuelStation_Shed","Land_repair_center","FuelStation","FuelStation_army","Land_Mil_Repair_center_EP1","Land_A_FuelStation_Build","Land_A_FuelStation_Feed","Land_Ind_FuelStation_Feed_EP1","Land_Ind_FuelStation_Build_EP1","Land_Ind_FuelStation_Shed_EP1","Land_Ind_Garage01_EP1","Land_benzina_schnell","Land_fuelstation","Land_fuelstation_army","Land_ibr_FuelStation_Feed","Land_ibr_FuelStation_Build","Land_ibr_FuelStation_Shed"], 30];

	if( (getDammage _vec > 0 or fuel _vec < 0.98) and (count _EGG_stations >0) and not (_vec isKindOf "Man") ) then
	{
		if( (_vec != player) and (speed _vec > -2) and (speed _vec < 2) and (position _vec select 2 < 2.0) and (local _vec) ) then
		{
			 titleText [localize "STR_M04t83", "PLAIN DOWN",0.3];//Servicing
			 for [{_loop3=0}, {_loop3<1}, {_loop3=_loop3}] do
			 {
			    sleep 0.200;	    		    
			    if (getDammage _vec > 0) then {_vec setDamage ((getDammage _vec)-0.0125);};
			    if (Fuel _vec < 1) then {_vec setFuel ((Fuel _vec)+0.0125);};
			    if (getDammage _vec == 0 and Fuel _vec == 1) then {_loop3=1;};
			    if(_vec != vehicle player or speed _vec < -2 or speed _vec > 2 or position _vec select 2 > 2.0) then {_loop3=1;titleText [localize "STR_M04t84", "PLAIN DOWN",0.3];};
			    _dam = (getDammage _vec)*100;
			    _ful = (Fuel _vec)*100;
			    hint format["Damage: %1\nFuel: %2",Round _dam,Round _ful];
			};
		};
	};
	_EGG_stations = [];
};

EGG_EVO_Repair = 
{
	_vec = (vehicle player);
	_type = typeOf vehicle player;
	if !(_vec isKindOf "Man") then
	{ //not man
		if ( (getDammage _vec > 0) || (fuel _vec < 0.98) || (_vec isKindOf "staticweapon" and getDammage _vec > 0) ) then
		{ //damaged
			if ( (_vec in list AirportIn) || (_vec in list farp1) || (_vec in list reng1) || (_vec in list reng2) || (_vec in list reng3) || (_vec in list reng4) ) then 
			{ // in farp
				if ( (_vec != player) && (speed _vec > -2) && (speed _vec < 2) && (position _vec select 2 < 2) ) then //&& (local _vec)
				{ //stationary
					titleText [localize "STR_M04t83", "PLAIN DOWN",0.3];//Servicing - may work if stringtable same for A3
					for [{_loop2=0}, {_loop2<1}, {_loop2=_loop2}] do
					{
						sleep 0.2;
						if (getDammage _vec > 0) then {_vec setDamage((getDammage _vec)-0.0125)};
						if (Fuel _vec < 1) then {_vec setFuel ((Fuel _vec)+0.0125);};
						if (getDammage _vec == 0 and Fuel _vec == 1) then {_loop2=1;};
						if(_vec != vehicle player or speed _vec < -2 or speed _vec > 2 or position _vec select 2 > 2.0) then {_loop2=1;titleText [localize "STR_M04t84", "PLAIN DOWN",0.3];};//again stringtable may need looking at for A3
						_dam = (getDammage _vec)*100;
						_ful = (Fuel _vec)*100;
						hint format["Damage: %1\nFuel: %2",Round _dam,Round _ful];
					}; //repair loop
					_vec setVehicleAmmo 1;
				};//loop complete
				sleep 2;
			};//farp check
			sleep 2;
		};//damaged
		sleep 2;
	}; //vehicle
};

EGG_EVO_HPM =
{
	if(not (alive vehicle player)) then
	{
		EGG_EVO_fattack = false;
	};
	if(EGG_EVO_fattack and getdammage player == 0) then
	{
		_medic = objNull;
		_Objects = (vehicle player) nearObjects 10;
		{if (_x in EGG_EVO_PlayerMedic or _x in EGG_EVO_MASH) then {_medic = _x}} forEach _Objects;
		if (not (isNull _medic) and not (local _medic)) then
		{
			EGG_EVO_mpoint = _medic;
			publicVariable "EGG_EVO_mpoint";
		};
		EGG_EVO_fattack = false;
	};
};

EGG_EVO_Rdisp = 
{
	_iimg = _this select 0;
	_iname = _this select 1;
	_mesg = _this select 2;
	_separator1 = parseText "<br /><br />";
	_img = parseText format["<t size='2.2'><img image='img\ranks\%1.paa'/></t>",_iimg];
	_name = parseText format["<t color='#FFFFCC'>   %1</t>",_iname];
	_txt = composeText [_img,_name,_separator1,_mesg];
	hint _txt;
};

EGG_EVO_Rank = 
{
	_name = name player;
	_score = score player;
	_rank = rank player;
	if (_score < EGG_EVO_rank1 and _rank != "PRIVATE")  exitWith  
	{	
		_rname = format["Pvt.%1",_name];
		_hint =  format[_rankmes,_rname];
		["pvt","PRIVATE",_hint] call EGG_EVO_Rdisp;		
		playSound "Promotion";
		[0] call EGG_EVO_AmmoBox;
//		[0] execVM "scripts\KBBW_Ammobox.sqf";
		EGG_EVO_PlayerSkill = 0.3;
		player SetSkill EGG_EVO_PlayerSkill;
		EGG_EVO_aunit = player;
		EGG_EVO_arank = "PRIVATE";
		player setUnitRank EGG_EVO_arank;
		publicVariable "EGG_EVO_aunit";
		publicVariable "EGG_EVO_arank";	
	};
	if (_score < EGG_EVO_rank2 and _score >= EGG_EVO_rank1 and _rank != "CORPORAL")  exitWith  
	{
		_rname = format["Corp.%1",_name];
		_hint =  format[_rankmes,_rname];
		["corp","CORPORAL",_hint] call EGG_EVO_Rdisp;
		playSound "Promotion";
		[1] call EGG_EVO_AmmoBox;
//		[1] execVM "scripts\KBBW_Ammobox.sqf";
		EGG_EVO_PlayerSkill = 0.4;
		player SetSkill EGG_EVO_PlayerSkill;		
		EGG_EVO_aunit = player;
		EGG_EVO_arank = "CORPORAL";
		player setUnitRank EGG_EVO_arank;
		publicVariable "EGG_EVO_aunit";
		publicVariable "EGG_EVO_arank";
	};
	if (_score < EGG_EVO_rank3 and _score >= EGG_EVO_rank2 and _rank != "SERGEANT")  exitWith  
	{
		_rname = format["Sgt.%1",_name];
		_hint =  format[_rankmes,_rname];
		["sgt","SERGEANT",_hint] call EGG_EVO_Rdisp;		
		playSound "Promotion";
		[2] call EGG_EVO_AmmoBox;
//		[2] execVM "scripts\KBBW_Ammobox.sqf";
		EGG_EVO_PlayerSkill = 0.5;
		player SetSkill EGG_EVO_PlayerSkill;		
		EGG_EVO_aunit = player;
		EGG_EVO_arank = "SERGEANT";
		player setUnitRank EGG_EVO_arank;
		publicVariable "EGG_EVO_aunit";
		publicVariable "EGG_EVO_arank";		
	};
	if (_score < EGG_EVO_rank4 and _score >= EGG_EVO_rank3 and _rank != "LIEUTENANT")  exitWith  
	{	
		_rname = format["Ltn.%1",_name];
		_hint =  format[_rankmes,_rname];
		["ltn","LIEUTENANT",_hint] call EGG_EVO_Rdisp;		
		playSound "Promotion";
		[3] call EGG_EVO_AmmoBox;
//		[3] execVM "scripts\KBBW_Ammobox.sqf";
		EGG_EVO_PlayerSkill = 0.6;
		player SetSkill EGG_EVO_PlayerSkill;		
		EGG_EVO_aunit = player;
		EGG_EVO_arank = "LIEUTENANT";
		player setUnitRank EGG_EVO_arank;
		publicVariable "EGG_EVO_aunit";
		publicVariable "EGG_EVO_arank";	
	};
	if (_score < EGG_EVO_rank5 and _score >= EGG_EVO_rank4 and _rank != "CAPTAIN")  exitWith  
	{
		_rname = format["Cpt.%1",_name];
		_hint =  format[_rankmes,_rname];
		["cpt","CAPTAIN",_hint] call EGG_EVO_Rdisp;		
		playSound "Promotion";
		[4] call EGG_EVO_AmmoBox;
//		[4] execVM "scripts\KBBW_Ammobox.sqf";
		EGG_EVO_PlayerSkill = 0.7;
		player SetSkill EGG_EVO_PlayerSkill;		
		EGG_EVO_aunit = player;
		EGG_EVO_arank = "CAPTAIN";
		player setUnitRank EGG_EVO_arank;
		publicVariable "EGG_EVO_aunit";
		publicVariable "EGG_EVO_arank";	
	};
	if (_score < EGG_EVO_rank6 and _score >= EGG_EVO_rank5 and _rank != "MAJOR")  exitWith  
	{	
		_rname = format["Mjr.%1",_name];
		_hint =  format[_rankmes,_rname];
		["mjr","MAJOR",_hint] call EGG_EVO_Rdisp;		
		playSound "Promotion";
		[5] call EGG_EVO_AmmoBox;
//		[5] execVM "scripts\KBBW_Ammobox.sqf";
		EGG_EVO_PlayerSkill = 0.8;
		player SetSkill EGG_EVO_PlayerSkill;		
		EGG_EVO_aunit = player;
		EGG_EVO_arank = "MAJOR";
		player setUnitRank EGG_EVO_arank;
		publicVariable "EGG_EVO_aunit";
		publicVariable "EGG_EVO_arank";	
	};
	if (_score >= EGG_EVO_rank6 and _rank != "COLONEL")  exitWith  
	{
		_rname = format["Col.%1",_name];
		_hint =  format[_rankmes,_rname];
		["col","COLONEL",_hint] call EGG_EVO_Rdisp;		
		playSound "Promotion";
		[6] call EGG_EVO_AmmoBox;
//		[6] execVM "scripts\KBBW_Ammobox.sqf";
		EGG_EVO_PlayerSkill = 1;
		player SetSkill EGG_EVO_PlayerSkill;		
		EGG_EVO_aunit = player;
		EGG_EVO_arank = "COLONEL";
		player setUnitRank EGG_EVO_arank;
		publicVariable "EGG_EVO_aunit";
		publicVariable "EGG_EVO_arank";
	};
	_tscore = score player;
};

EGG_EVO_CTime = 
{
	_temp = compile EGG_EVO_gdate_packed;
	_date = call _temp;
	_hour = _date select 3;
	
	if(_hour != _oldhour) then
	{
		if(_hour == 0) then
		{
			10 setOvercast 0.0;
			10 setRain 0.0;
		};
		_oldhour = _hour;
		setDate _date;
	};
};

EGG_EVO_CityClear = 
{
	EGG_citychange =
	{
		player sideChat format ["City Clear:%1",EGG_EVO_MissionProgress];
		_currentcity = (EGG_EVO_MissionProgress-1);
		_city = (EGG_EVO_Townnames select _currentcity);
		[West,"HQ"] SideChat format[localize "STR_M04t61",_city];//%1 IS CLEAR OF ENEMY, GREAT JOB MEN
		playSound "CityClear";
		sleep 2;
		_newcity = (EGG_EVO_Townnames select EGG_EVO_MissionProgress);
		[West,"HQ"] SideChat format["Liberate %1",_newcity];
	};

	switch (EGG_EVO_MissionProgress) do
	{
		case 0:
		{	
			"0" objstatus "done";
//			EGG_EVO_MainObjective setMarkerPosLocal getMarkerPos "mobj1";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj1";
			_city1 = (EGG_EVO_Townnames select 0);
			[West,"HQ"] SideChat format["Liberate %1",_city1];
		};
		case 1:
		{	
			"1" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj2";
			[] call EGG_citychange;
		};
		case 2:
		{	
			"2" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj3";
			[] call EGG_citychange;
		};
		case 3:
		{	
			"3" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj4";
			[] call EGG_citychange;
		};
		case 4:
		{	
			"4" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj5";
			[] call EGG_citychange;
		};
		case 5:
		{	
			"5" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj6";
			[] call EGG_citychange;
		};
		case 6:
		{	
			"6" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj7";
			[] call EGG_citychange;
		};
		case 7:
		{	
			"7" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj8";
			[] call EGG_citychange;
		};
		case 8:
		{	
			"8" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj9";
			[] call EGG_citychange;
		};
		case 9:
		{	
			"9" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj10";
			[] call EGG_citychange;
		};
		case 10:
		{	
			"10" objstatus "done";
			"MainObj" setMarkerPosLocal getMarkerPos "mobj11";
			[] call EGG_citychange;
		};
		case 11:
		{	
			"11" objstatus "done";
			deleteMarkerLocal "MainObj";
			player sideChat format ["EGG_EVO_CityClear:%1",EGG_EVO_MissionProgress];
			_currentcity = (EGG_EVO_MissionProgress-1);
			_city = (EGG_EVO_Townnames select _currentcity);
			[West,"HQ"] SideChat format[localize "STR_M04t61",_city];//%1 IS CLEAR OF ENEMY, GREAT JOB MEN
//			playSound "Intro";
		};		
	};
	[] call EGG_EVO_AssignTasks;//in eventsC
	_currentprog = EGG_EVO_MissionProgress;
};


for [{_loop=0}, {_loop<1}, {_loop=_loop}] do
{
	[] call EGG_EVO_Repair;
	sleep 1;
	[] call EGG_EVO_stationRepair;
	sleep 1;
	if (score player != _tscore and alive player) then {[] call EGG_EVO_Rank};
	sleep 1;
	if (EGG_EVO_MissionProgress > _currentprog) then {[] call EGG_EVO_CityClear};
	sleep 1;
//	[] call EGG_EVO_CTime;
//	sleep 1;
	[] call EGG_EVO_HPM;
	sleep 10;
};