//tky_evo_performance report by GITS Tankbsuter
//put me in the mission scripts folder and fire me up from init.sqf or similar with nul = execVM "scripts\tky_evo_performance_report.sqf";
diag_log "perfmon";

private ["_myentities", "_westcars","_eastcars","_westmen","_civmen","_westair","_eastair","_animals", "_mypause"];
_mypause = _this select 0;
//hint format ["pause value:%1",_mypause];

//if (!isServer) exitWith {}; // disabled by scorp, so he could monitor stats in game

if (!isServer && name player != "Scorp") exitWith {};

if (_mypause == 0) exitWith {};

_numDeadMarkers = 0;
_task = player createSimpleTask ["EntityMonitoring"];

while {true} do
{	
	_myentities = entities "";
	_westcars = {_x isKindOf "Car" and side _x == west} count _myentities;
	_eastcars = {_x isKindOf "Car" and side _x == east} count _myentities;
	_westmen = {_x isKindOf "SoldierWB"} count _myentities;
	_eastmen = {_x isKindOf "SoldierEB"} count _myentities;
	_civmen = {_x isKindOf "Civilian"} count _myentities;
	_westair = {_x isKindOf "Air" and side _x == west} count _myentities;
	_eastair = {_x isKindOf "Air" and side _x == east} count _myentities;
	_animals = {_x isKindOf "Animal_Base_F"} count _myentities;
	_weapons = {_x isKindOf "Weapon"} count _myentities;
	_ammo = {_x isKindOf "Magazine"} count _myentities;
	_equip = {_x isKindOf "Equipment"} count _myentities;
	
	diag_log format ["===tky performance output for %1, %2, %3.%4, %5===", missionName, productVersion select 1, productVersion select 2, productVersion select 3, productVersion select 4];
	diag_log format ["Missiontime %1 Servertime %2", floor Time, floor serverTime];
	diag_log format ["FPS %1 Players %2 Entities %3", floor diag_fps,  playersNumber west, count _myentities];
	diag_log format ["Occupied Vehicles West %1 East %2", _westcars,_eastcars];
	diag_log format ["Dismounted Men West %1 East %2 Civs %3", _westmen,_eastmen, _civmen];
	diag_log format ["Airborne West %1 East %2", _westair,_eastair];
	diag_log format ["Dead men %1 Animals %2", count alldeadmen, _animals];
	
	if ( !isDedicated) then
	{		
		if (name player == "Scorp") then
		{
			player groupchat format ["Missiontime %1 Servertime %2 - %3", floor Time, floor serverTime, (name player)];
			player groupchat format ["FPS %1 Players %2 Entities %3", floor diag_fps,  playersNumber west, count _myentities];
			player groupchat format ["Occupied Vehicles West %1 East %2", _westcars,_eastcars];
			player groupchat format ["Dismounted Men West %1 East %2 Civs %3", _westmen,_eastmen, _civmen];
			player groupchat format ["Airborne West %1 East %2", _westair,_eastair];
			player groupchat format ["Dead men %1 Animals %2", count alldeadmen, _animals];	
			
			for "_i" from 1 to _numDeadMarkers do
			{
				_deadmarkname = format ["DeadMarker%1", _i];
				if (getMarkerType _deadmarkname != "") then {
					deleteMarkerLocal _deadmarkname;
				};
			};
						
			_i = 0;
			{
				_i = _i + 1;
				_deadmarkname = format ["DeadMarker%1", _i];
				_deadmark = createMarkerLocal [ _deadmarkname, position _x];
				_deadmark setMarkerShapeLocal "ICON";
				_deadmark setMarkerTypeLocal "Mil_Dot";
				_deadmark setMarkerColorLocal "ColorYellow";
				_deadmark setMarkerTextLocal format ["Dead - %1 - %2", typeOf _x, side _x];
				_deadmark setMarkerSizeLocal [0.25, 0.25];				
			} forEach allDeadMen;
			_numDeadMarkers = _i;			
		};
	};	
	
	sleep _mypause;	
};
