/*
============
G_InitGame

============
*/
void G_InitGame( int levelTime, int randomSeed, int restart ) {
	int					i;

	G_Printf ("------- Game Initialization -------\n");
	G_Printf ("gamename: %s\n", GAMEVERSION);
	G_Printf ("gamedate: %s\n", __DATE__);

	srand( randomSeed );

	G_RegisterCvars();

	G_ProcessIPBans();

	G_InitMemory();

	// set some level globals
	memset( &level, 0, sizeof( level ) );
	level.time = levelTime;
	level.startTime = levelTime;

	level.snd_fry = G_SoundIndex("sound/player/fry.wav");	// FIXME standing in lava / slime

	if ( g_gametype.integer != GT_SINGLE_PLAYER && g_logfile.string[0] ) {
		if ( g_logfileSync.integer ) {
			trap_FS_FOpenFile( g_logfile.string, &level.logFile, FS_APPEND_SYNC );
		} else {
			trap_FS_FOpenFile( g_logfile.string, &level.logFile, FS_APPEND );
		}
		if ( !level.logFile ) {
			G_Printf( "WARNING: Couldn't open logfile: %s\n", g_logfile.string );
		} else {
			char	serverinfo[MAX_INFO_STRING];

			trap_GetServerinfo( serverinfo, sizeof( serverinfo ) );

			G_LogPrintf("------------------------------------------------------------\n" );
			G_LogPrintf("InitGame: %s\n", serverinfo );
		}
	} else {
		G_Printf( "Not logging to disk.\n" );
	}

	G_InitWorldSession();

	// initialize all entities for this game
	memset( g_entities, 0, MAX_GENTITIES * sizeof(g_entities[0]) );
	level.gentities = g_entities;

	// initialize all clients for this game
	level.maxclients = g_maxclients.integer;
	memset( g_clients, 0, MAX_CLIENTS * sizeof(g_clients[0]) );
	level.clients = g_clients;

	// set client fields on player ents
	for ( i=0 ; i<level.maxclients ; i++ ) {
		g_entities[i].client = level.clients + i;
	}

	// always leave room for the max number of clients,
	// even if they aren't all used, so numbers inside that
	// range are NEVER anything but clients
	level.num_entities = MAX_CLIENTS;

	for ( i=0 ; i<MAX_CLIENTS ; i++ ) {
		g_entities[i].classname = "clientslot";
	}

	// let the server system know where the entites are
	trap_LocateGameData( level.gentities, level.num_entities, sizeof( gentity_t ), 
		&level.clients[0].ps, sizeof( level.clients[0] ) );

	// reserve some spots for dead player bodies
	InitBodyQue();

	ClearRegisteredItems();

	// parse the key/value pairs and spawn gentities
	G_SpawnEntitiesFromString();

	// general initialization
	G_FindTeams();

	// make sure we have flags for CTF, etc
	if( g_gametype.integer >= GT_TEAM ) {
		G_CheckTeamItems();
	}

	SaveRegisteredItems();

	G_Printf ("-----------------------------------\n");

	if( g_gametype.integer == GT_SINGLE_PLAYER || trap_Cvar_VariableIntegerValue( "com_buildScript" ) ) {
		G_ModelIndex( SP_PODIUM_MODEL );
	}

	if ( trap_Cvar_VariableIntegerValue( "bot_enable" ) ) {
		BotAISetup( restart );
		BotAILoadMap( restart );
		G_InitBots( restart );
	}

	G_RemapTeamShaders();

}
Example #2
0
/*
==============
SpawnEntities

Creates a server's entity / program execution context by
parsing textual entity definitions out of an ent file.
==============
*/
void Level::SpawnEntities( const char *themapname, const char *entities, int levelTime )
{
	int			inhibit,count=0;
	const char	*value;
	SpawnArgs   args;
	char        *spawnpos;
	
	// Init the level variables
	Init();
	
	spawnpos = const_cast<char*>(strchr( themapname, '$' ));
	if ( spawnpos )
	{
		mapname = str( themapname, 0, spawnpos - themapname );
		spawnpoint = spawnpos + 1;
	}
	else
	{
		mapname = themapname;
		spawnpoint = "";
	}
	
	// set up time so functions still have valid times
	setTime( levelTime, 1000 / 20 );
	
	if ( !LoadingServer )
	{
		// Get rid of anything left over from the last level
		//CleanUp( false );
		
		// Set up for a new map
		thePathManager.Init( mapname );
		
	}
	
	
	setSkill( skill->integer );
	
	// reset out count of the number of game traces
	sv_numtraces = 0;
	
	// parse world
	entities = args.Parse( entities );
	spawn_entnum = ENTITYNUM_WORLD;
	args.Spawn();
	
	if ( !world )
		Com_Error( ERR_FATAL, "No world\n" );
	
	if ( g_gametype->integer == GT_MULTIPLAYER || g_gametype->integer == GT_BOT_SINGLE_PLAYER )
	{
		multiplayerManager.initMultiplayerGame();
	}
	
	// parse ents
	inhibit = 0;
	for( entities = args.Parse( entities ); entities != NULL; entities = args.Parse( entities ) )
	{
		// remove things (except the world) from different skill levels or deathmatch
		spawnflags = 0;
		value = args.getArg( "spawnflags" );
		if ( value )
		{
			spawnflags = atoi( value );
			if ( inhibitEntity( spawnflags ) )
            {
				inhibit++;
				continue;
			}
		}
		
		args.Spawn();
		count++;

		gi.ProcessLoadingScreen( "$$SpawningEntities$$" );
	}
	
	gi.DPrintf( "%i entities spawned\n", count );
	gi.DPrintf( "%i entities inhibited\n", inhibit );
	
	// Process the spawn events
	L_ProcessPendingEvents();
	
	if ( multiplayerManager.inMultiplayer() )
	{
		multiplayerManager.initItems();
	}

	// Setup bots

	if ( gi.Cvar_VariableIntegerValue( "bot_enable" ) && multiplayerManager.inMultiplayer() ) 
	{
		BotAIShutdown( 0 );

		BotAISetup( 0 );
		BotAILoadMap( 0 );
		G_InitBots( 0 );
	}
	
	if ( !LoadingServer || game.autosaved )
	{
		Start();
	}
	
	postLoad();
   	
	
	//-------------------------------------------------------------------------------
    //
    // Deletion Note:
    // Since hNodeController is an Entity, it is deleted
    // when all the other entities are deleted in the clean up function
    // specifically the line
    //
	//
   	//	if ( active_edicts.next->entity )
	//		{
	//		delete active_edicts.next->entity;
	//		}
    //
	//
    // Since it is already being deleted like this
    // We do not need to explcitily delete the controller... In fact
    // you will error out if you try to.
	//--------------------------------------------------------------------------------
	hNodeController = new HelperNodeController;
	if ( hNodeController )
		hNodeController->SetTargetName( "HelperNodeController" );
	
	
	
	//
	// if this is a single player game, spawn the single player in now
	// this allows us to read persistant data into the player before the client
	// is completely ready
	//
	if ( game.maxclients == 1 )
	{
		spawn_entnum = 0;
		new Player;
	}
}