/*

	Copyright (C) 2004 Michael Liebscher

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#include "../wolfiphone.h"

/*
-----------------------------------------------------------------------------
 Function: 
 
 Parameters:
 
 Returns:
 
 Notes: 

-----------------------------------------------------------------------------
*/
PUBLIC void Client_PrepRefresh( const char *r_mapname )
{
	char mapname[ 32 ];

	if( ! r_mapname || ! *r_mapname )
	{
		return;
	}

	if( g_version->value == SPEAROFDESTINY )
	{
		spritelocation = SODSPRITESDIRNAME;
	}
	else
	{
		spritelocation = WL6SPRITESDIRNAME;
	}

	my_strlcpy( mapname, r_mapname, sizeof( mapname ) );	// skip "maps/"

	// !@# fix crash bug if you type something short...
	if ( strlen( mapname ) > 4 && !strcmp( mapname + strlen( mapname ) - 4, ".map" ) ) {
		mapname[ strlen( mapname ) - 4 ] = '\0';		// cut off ".map"
	}

	// register models, pics, and skins	
	R_BeginRegistration( mapname );

	if( r_world == NULL )
	{
		return;
	}


	Com_Printf( "Map: %s\n", r_world->mapName ); 
	
	Level_ScanInfoPlane( r_world ); // Spawn items/guards

	Com_Printf( "Spawning Entities\n" );
	PL_Spawn( r_world->pSpawn, r_world ); // Spawn Player

	Com_Printf( "Caching Textures and Sounds\n" );
	Level_PrecacheTextures_Sound( r_world );
	
	// clear any lines of console text
	Con_ClearNotify();

	if( r_world->musicName )
	{
		Sound_StartBGTrack( r_world->musicName, r_world->musicName );
	}

	Player.playstate = ex_playing;	
}

int tics;




