예제 #1
0
파일: g_main.c 프로젝트: osfpsproject/MF2
/*
==================
BeginIntermission
==================
*/
void BeginIntermission()
{
	if ( theLevel.intermissiontime_ ) 
		return;		// already active

	// if in tournement mode, change the wins / losses
	if ( g_gametype.integer == GT_TOURNAMENT ) 
		AdjustTournamentScores();

	theLevel.intermissiontime_ = theLevel.time_;
	FindIntermissionPoint();

	// if single player game
	if ( g_gametype.integer == GT_SINGLE_PLAYER ) 
		UpdateTournamentInfo();

	// move all clients to the intermission point
	for( int i=1 ; i<= theLevel.maxclients_ ; i++ ) 
	{
		GameEntity* client = theLevel.getEntity(i);
		if( !client || !client->inuse_ )
			continue;
		// respawn if dead
		if( client->health_ <= 0 ) 
			respawn(client);

		MoveClientToIntermission( client );
	}

	// send the current scoring to all clients
	SendScoreboardMessageToAllClients();

}
예제 #2
0
/*
==================
BeginIntermission
==================
*/
void BeginIntermission( void ) {
	int			i;
	gentity_t	*client;

	if ( level.intermissiontime ) {
		return;		// already active
	}

	// if in tournement mode, change the wins / losses
	if ( g_gametype.integer == GT_TOURNAMENT ) {
		AdjustTournamentScores();
	}

	level.intermissiontime = level.time;
	FindIntermissionPoint();

#ifdef MISSIONPACK
	if (g_singlePlayer.integer) {
		trap_Cvar_Set("ui_singlePlayerActive", "0");
		UpdateTournamentInfo();
	}
#else
	// if single player game
	if ( g_gametype.integer == GT_SINGLE_PLAYER ) {
		UpdateTournamentInfo();
		SpawnModelsOnVictoryPads();
	}
#endif

	// move all clients to the intermission point
	for (i=0 ; i< level.maxclients ; i++) {
		client = g_entities + i;
		if (!client->inuse)
			continue;
		// respawn if dead
		if (client->health <= 0) {
			respawn(client);
		}
		MoveClientToIntermission( client );
	}

	// send the current scoring to all clients
	SendScoreboardMessageToAllClients();

}
/*
============
CalculateRanks

Recalculates the score ranks of all players
This will be called on every client connect, begin, disconnect, death,
and team change.
============
*/
void CalculateRanks( void ) {
	int		i;
	int		rank;
	int		score;
	int		newScore;
	gclient_t	*cl;

	level.follow1 = -1;
	level.follow2 = -1;
	level.numConnectedClients = 0;
	level.numNonSpectatorClients = 0;
	level.numPlayingClients = 0;
	level.numVotingClients = 0;		// don't count bots

	for (i = 0; i < ARRAY_LEN(level.numteamVotingClients); i++)
		level.numteamVotingClients[i] = 0;

	for ( i = 0 ; i < level.maxclients ; i++ ) {
		if ( level.clients[i].pers.connected != CON_DISCONNECTED ) {
			level.sortedClients[level.numConnectedClients] = i;
			level.numConnectedClients++;

			if ( level.clients[i].sess.sessionTeam != TEAM_SPECTATOR ) {
				level.numNonSpectatorClients++;
			
				// decide if this should be auto-followed
				if ( level.clients[i].pers.connected == CON_CONNECTED ) {
					level.numPlayingClients++;
					if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
						level.numVotingClients++;
						if ( level.clients[i].sess.sessionTeam == TEAM_RED )
							level.numteamVotingClients[0]++;
						else if ( level.clients[i].sess.sessionTeam == TEAM_BLUE )
							level.numteamVotingClients[1]++;
					}
					if ( level.follow1 == -1 ) {
						level.follow1 = i;
					} else if ( level.follow2 == -1 ) {
						level.follow2 = i;
					}
				}
			}
		}
	}

	qsort( level.sortedClients, level.numConnectedClients, 
		sizeof(level.sortedClients[0]), SortRanks );

	// set the rank value for all clients that are connected and not spectators
	if ( g_gametype.integer >= GT_TEAM ) {
		// in team games, rank is just the order of the teams, 0=red, 1=blue, 2=tied
		for ( i = 0;  i < level.numConnectedClients; i++ ) {
			cl = &level.clients[ level.sortedClients[i] ];
			if ( level.teamScores[TEAM_RED] == level.teamScores[TEAM_BLUE] ) {
				cl->ps.persistant[PERS_RANK] = 2;
			} else if ( level.teamScores[TEAM_RED] > level.teamScores[TEAM_BLUE] ) {
				cl->ps.persistant[PERS_RANK] = 0;
			} else {
				cl->ps.persistant[PERS_RANK] = 1;
			}
		}
	} else {	
		rank = -1;
		score = 0;
		for ( i = 0;  i < level.numPlayingClients; i++ ) {
			cl = &level.clients[ level.sortedClients[i] ];
			newScore = cl->ps.persistant[PERS_SCORE];
			if ( i == 0 || newScore != score ) {
				rank = i;
				// assume we aren't tied until the next client is checked
				level.clients[ level.sortedClients[i] ].ps.persistant[PERS_RANK] = rank;
			} else {
				// we are tied with the previous client
				level.clients[ level.sortedClients[i-1] ].ps.persistant[PERS_RANK] = rank | RANK_TIED_FLAG;
				level.clients[ level.sortedClients[i] ].ps.persistant[PERS_RANK] = rank | RANK_TIED_FLAG;
			}
			score = newScore;
			if ( g_gametype.integer == GT_SINGLE_PLAYER && level.numPlayingClients == 1 ) {
				level.clients[ level.sortedClients[i] ].ps.persistant[PERS_RANK] = rank | RANK_TIED_FLAG;
			}
		}
	}

	// set the CS_SCORES1/2 configstrings, which will be visible to everyone
	if ( g_gametype.integer >= GT_TEAM ) {
		trap_SetConfigstring( CS_SCORES1, va("%i", level.teamScores[TEAM_RED] ) );
		trap_SetConfigstring( CS_SCORES2, va("%i", level.teamScores[TEAM_BLUE] ) );
	} else {
		if ( level.numConnectedClients == 0 ) {
			trap_SetConfigstring( CS_SCORES1, va("%i", SCORE_NOT_PRESENT) );
			trap_SetConfigstring( CS_SCORES2, va("%i", SCORE_NOT_PRESENT) );
		} else if ( level.numConnectedClients == 1 ) {
			trap_SetConfigstring( CS_SCORES1, va("%i", level.clients[ level.sortedClients[0] ].ps.persistant[PERS_SCORE] ) );
			trap_SetConfigstring( CS_SCORES2, va("%i", SCORE_NOT_PRESENT) );
		} else {
			trap_SetConfigstring( CS_SCORES1, va("%i", level.clients[ level.sortedClients[0] ].ps.persistant[PERS_SCORE] ) );
			trap_SetConfigstring( CS_SCORES2, va("%i", level.clients[ level.sortedClients[1] ].ps.persistant[PERS_SCORE] ) );
		}
	}

	// see if it is time to end the level
	CheckExitRules();

	// if we are at the intermission, send the new info to everyone
	if ( level.intermissiontime ) {
		SendScoreboardMessageToAllClients();
	}
}
예제 #4
0
파일: g_main.c 프로젝트: osfpsproject/MF2
/*
============
CalculateRanks

Recalculates the score ranks of all players
This will be called on every client connect, begin, disconnect, death,
and team change.
============
*/
void CalculateRanks()
{
	theLevel.follow1_ = -1;
	theLevel.follow2_ = -1;
	theLevel.numConnectedClients_ = 0;
	theLevel.numNonSpectatorClients_ = 0;
	theLevel.numPlayingClients_ = 0;
	theLevel.numVotingClients_ = 0;		// don't count bots
	for( int i = 0; i < ClientBase::TEAM_NUM_TEAMS; i++ ) 
		theLevel.numteamVotingClients_[i] = 0;

	for( int i = 1 ; i <= theLevel.maxclients_ ; i++ ) 
	{
		GameClient* client = theLevel.getClient(i);
		if( client && client->pers_.connected_ != GameClient::ClientPersistant::CON_DISCONNECTED ) 
		{
			theLevel.sortedClients_[theLevel.numConnectedClients_] = i;
			theLevel.numConnectedClients_++;

			if( client->sess_.sessionTeam_ != ClientBase::TEAM_SPECTATOR ) 
			{
				theLevel.numNonSpectatorClients_++;
			
				// decide if this should be auto-followed
				if ( client->pers_.connected_ == GameClient::ClientPersistant::CON_CONNECTED ) 
				{
					theLevel.numPlayingClients_++;
					if( !(theLevel.getEntity(i)->r.svFlags & SVF_BOT) ) 
					{
						theLevel.numVotingClients_++;
						if( client->sess_.sessionTeam_ == ClientBase::TEAM_RED )
							theLevel.numteamVotingClients_[0]++;
						else if( client->sess_.sessionTeam_ == ClientBase::TEAM_BLUE )
							theLevel.numteamVotingClients_[1]++;
					}
					if( theLevel.follow1_ == -1 ) 
						theLevel.follow1_ = i;
					else if( theLevel.follow2_ == -1 ) 
						theLevel.follow2_ = i;
				}
			}
		}
	}

	qsort( theLevel.sortedClients_, theLevel.numConnectedClients_, 
		sizeof(theLevel.sortedClients_[0]), SortRanks );

	// set the rank value for all clients that are connected and not spectators
	if( g_gametype.integer >= GT_TEAM ) 
	{
		// in team games, rank is just the order of the teams, 0=red, 1=blue, 2=tied
		for ( int i = 0;  i < theLevel.numConnectedClients_; i++ ) 
		{
			GameClient *cl =  theLevel.getClient(theLevel.sortedClients_[i]);
			if( theLevel.teamScores_[ClientBase::TEAM_RED] == theLevel.teamScores_[ClientBase::TEAM_BLUE] ) 
				cl->ps_.persistant[PERS_RANK] = 2;
			else if( theLevel.teamScores_[ClientBase::TEAM_RED] > theLevel.teamScores_[ClientBase::TEAM_BLUE] ) 
				cl->ps_.persistant[PERS_RANK] = 0;
			else
				cl->ps_.persistant[PERS_RANK] = 1;
		}
	} 
	else 
	{	
		int rank = -1;
		int score = 0;
		for( int i = 0;  i < theLevel.numPlayingClients_; i++ ) 
		{
			GameClient *cl = theLevel.getClient(theLevel.sortedClients_[i]);
			int newScore = cl->ps_.persistant[PERS_SCORE];
			if( i == 0 || newScore != score ) 
			{
				rank = i;
				// assume we aren't tied until the next client is checked
				theLevel.getClient(theLevel.sortedClients_[i])->ps_.persistant[PERS_RANK] = rank;
			} 
			else 
			{
				// we are tied with the previous client
				theLevel.getClient(theLevel.sortedClients_[i-1])->ps_.persistant[PERS_RANK] = rank | RANK_TIED_FLAG;
				theLevel.getClient(theLevel.sortedClients_[i])->ps_.persistant[PERS_RANK] = rank | RANK_TIED_FLAG;
			}
			score = newScore;
			if( g_gametype.integer == GT_SINGLE_PLAYER && theLevel.numPlayingClients_ == 1 ) 
				theLevel.getClient(theLevel.sortedClients_[i])->ps_.persistant[PERS_RANK] = rank | RANK_TIED_FLAG;
		}
	}

	// set the CS_SCORES1/2 configstrings, which will be visible to everyone
	if( g_gametype.integer >= GT_TEAM ) 
	{
		SV_SetConfigstring( CS_SCORES1, va("%i", theLevel.teamScores_[ClientBase::TEAM_RED] ) );
		SV_SetConfigstring( CS_SCORES2, va("%i", theLevel.teamScores_[ClientBase::TEAM_BLUE] ) );
	} 
	else
	{
		if( theLevel.numConnectedClients_ == 0 ) 
		{
			SV_SetConfigstring( CS_SCORES1, va("%i", SCORE_NOT_PRESENT) );
			SV_SetConfigstring( CS_SCORES2, va("%i", SCORE_NOT_PRESENT) );
		}
		else if( theLevel.numConnectedClients_ == 1 ) 
		{
			SV_SetConfigstring( CS_SCORES1, va("%i", theLevel.getClient(theLevel.sortedClients_[0])->ps_.persistant[PERS_SCORE] ) );
			SV_SetConfigstring( CS_SCORES2, va("%i", SCORE_NOT_PRESENT) );
		} 
		else
		{
			SV_SetConfigstring( CS_SCORES1, va("%i", theLevel.getClient(theLevel.sortedClients_[0])->ps_.persistant[PERS_SCORE] ) );
			SV_SetConfigstring( CS_SCORES2, va("%i", theLevel.getClient(theLevel.sortedClients_[1])->ps_.persistant[PERS_SCORE] ) );
		}
	}

	// see if it is time to end the level
	CheckExitRules();

	// if we are at the intermission, send the New info to everyone
	if( theLevel.intermissiontime_ ) 
		SendScoreboardMessageToAllClients();
}