#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include common_scripts\utility;
#include maps\mp\agents\_agent_utility;
//#include maps\mp\bots\_bots_strategy;
#include maps\mp\agents\_scriptedAgents;
/*
	Virtual Lobby
	Objective: 	see all player's costume and loadouts
	Map ends:	When you join a real game
	Respawning:	No wait

	Level requirementss
	------------------
		Spawnpoints:
			classname		mp_tdm_spawn
			All players spawn from these. The spawnpoint chosen is dependent on the current locations of teammates and enemies
			at the time of spawn. Players generally spawn behind their teammates relative to the direction of enemies.

		Spectator Spawnpoints:
			classname		mp_global_intermission
			Spectators spawn from these and intermission is viewed from these positions.
			Atleast one is required, any more and they are randomly chosen between.
*/



main()
{
	if( getdvar("mapname") == "mp_background" )
		return;
	
	assert( getdvar( "mapname" ) == getdvar( "virtualLobbyMap" ) );

	maps\mp\gametypes\_globallogic::init();
	maps\mp\gametypes\_callbacksetup::SetupCallbacks();
	maps\mp\gametypes\_globallogic::SetupCallbacks();
	
	level.rankedMatch = false;
	level.onStartGameType = ::onStartGameType;
	level.getSpawnPoint = ::getSpawnPoint; // handled in vl_main
	level.onSpawnPlayer = ::onSpawnPlayer;
	
	registerNumLivesDvar( level.gameType, 0 );
	registerTimeLimitDvar( level.gameType, 0 );
	registerScoreLimitDvar( level.gameType, 1 );
	registerHalfTimeDvar( level.gameType, 0 );
	
	level.classOld = level.class;
	level.class = ::MenuClass;

	game["menu_team"] = "main";
	game["menu_class_allies"] = "main";
	game["menu_class_axis"] = "main";
	game["menu_changeclass_allies"] = "main";
	game["menu_changeclass_axis"] = "main";
	game["menu_changeclass"] = "menu_cac_assault";
	
	// force the charsets
	game["allies"] = "sentinel_vl";
	game["axis"] = "atlas";

	//SetDvar("r_dof_tweak", 1);	
	//SetDvar("r_dof_physical_enable", 1);
	//SetDvar("sm_qualityspotshadow", 0);

	}

MenuClass( response )
{
	level.inGracePeriod = true;
	self.hasDoneCombat = false;
	[[level.classOld]](response);
}

onStartGameType()
{
	setClientNameMode("auto_change");

	if ( !isdefined( game["switchedsides"] ) )
		game["switchedsides"] = false;

	/*
	if ( game["switchedsides"] )
	{
		oldAttackers = game["attackers"];
		oldDefenders = game["defenders"];
		game["attackers"] = oldDefenders;
		game["defenders"] = oldAttackers;
	}
	*/
	setObjectiveText( "allies", &"OBJECTIVES_WAR" );
	setObjectiveText( "axis", &"OBJECTIVES_WAR" );
	
	setObjectiveScoreText( "allies", &"OBJECTIVES_WAR" );
	setObjectiveScoreText( "axis", &"OBJECTIVES_WAR" );

	setObjectiveHintText( "allies", &"OBJECTIVES_WAR" );
	setObjectiveHintText( "axis", &"OBJECTIVES_WAR" );

			
	init_spawns();
	
	allowed[0] = level.gameType;	
	maps\mp\gametypes\_gameobjects::main( allowed );	
	level.prematchPeriod = 0;
	level.prematchPeriodEnd = 0;
}

init_spawns()
{
	level.spawnMins = ( 0, 0, 0 );
	level.spawnMaxs = ( 0, 0, 0 );	
	
	maps\mp\gametypes\_spawnlogic::addStartSpawnPoints( "mp_tdm_spawn_allies_start" );
	maps\mp\gametypes\_spawnlogic::addStartSpawnPoints( "mp_tdm_spawn_axis_start" );
	maps\mp\gametypes\_spawnlogic::addSpawnPoints( "allies", "mp_tdm_spawn" );
	maps\mp\gametypes\_spawnlogic::addSpawnPoints( "axis", "mp_tdm_spawn" );
	
	level.mapCenter = maps\mp\gametypes\_spawnlogic::findBoxCenter( level.spawnMins, level.spawnMaxs );
	setMapCenter( level.mapCenter );
}

// called when a player looks for a spawn point - callback _playerlogic
getSpawnPoint( player_id )
{
	if (!IsDefined( player_id ))
	{
		player_id = 0;
		for (i=0; i<level.players.size; i++)
		{
			if (level.players[i] == self)
			{
				player_id = i;
				break;
			}
		}
	}
	// just return the first player_pos for now
	player_points =   GetEntArray( "player_pos", "targetname" );
	point = undefined;
	foreach (point in player_points)
	{
		if (point.script_noteworthy == ""+player_id)
			break;
	}
	if (!isdefined(point))
	{
		point = player_points[0];
	}
	//if(player_id == 0) // I want to store the origin and angles of the starting location on each agent, local player calls level.getSpawnPoint from _playerlogic so I special case store it here
	{
		self.avatar_spawnpoint = point;
	//	level.test_point_angle = point;   /// just for testing remove this eventually
	}
	return point;
}



// called anytime a player spawns from some other script / callback
onSpawnPlayer()
{
	if ( IsDefined( level.vl_onSpawnPlayer ) )
	    self [[ level.vl_onSpawnPlayer ]]();
}

