Fix player queueing for tournament play (#4939)

This commit is contained in:
Thilo Schulz 2011-04-07 23:41:32 +00:00
parent 806a849bf2
commit 31ec563999
4 changed files with 38 additions and 11 deletions

View file

@ -583,10 +583,10 @@ void SetTeam( gentity_t *ent, char *s ) {
player_die (ent, ent, ent, 100000, MOD_SUICIDE);
}
// they go to the end of the line for tournements
if ( team == TEAM_SPECTATOR ) {
client->sess.spectatorTime = level.time;
}
if(team == TEAM_SPECTATOR && oldTeam != team)
AddTournamentQueue(client);
client->sess.sessionTeam = team;
client->sess.spectatorState = specState;

View file

@ -225,7 +225,7 @@ typedef struct {
// MUST be dealt with in G_InitSessionData() / G_ReadSessionData() / G_WriteSessionData()
typedef struct {
team_t sessionTeam;
int spectatorTime; // for determining next-in-line to play
int spectatorNum; // for determining next-in-line to play
spectatorState_t spectatorState;
int spectatorClient; // for chasecam and follow mode
int wins, losses; // tournament stats
@ -623,6 +623,7 @@ void FindIntermissionPoint( void );
void SetLeader(int team, int client);
void CheckTeamLeader( int team );
void G_RunThink (gentity_t *ent);
void AddTournamentQueue(gclient_t *client);
void QDECL G_LogPrintf( const char *fmt, ... );
void SendScoreboardMessageToAllClients( void );
void QDECL G_Printf( const char *fmt, ... );

View file

@ -602,9 +602,8 @@ void AddTournamentPlayer( void ) {
continue;
}
if ( !nextInLine || client->sess.spectatorTime < nextInLine->sess.spectatorTime ) {
if(!nextInLine || client->sess.spectatorNum > nextInLine->sess.spectatorNum)
nextInLine = client;
}
}
if ( !nextInLine ) {
@ -617,6 +616,33 @@ void AddTournamentPlayer( void ) {
SetTeam( &g_entities[ nextInLine - level.clients ], "f" );
}
/*
=======================
RequeueTournamentLoser
Add client to end of tournament queue
=======================
*/
void AddTournamentQueue(gclient_t *client)
{
int index;
gclient_t *curclient;
for(index = 0; index < level.maxclients; index++)
{
curclient = &level.clients[index];
if(curclient->pers.connected != CON_DISCONNECTED)
{
if(curclient == client)
curclient->sess.spectatorNum = 0;
else if(curclient->sess.sessionTeam == TEAM_SPECTATOR)
curclient->sess.spectatorNum++;
}
}
}
/*
=======================
RemoveTournamentLoser
@ -716,10 +742,10 @@ int QDECL SortRanks( const void *a, const void *b ) {
// then spectators
if ( ca->sess.sessionTeam == TEAM_SPECTATOR && cb->sess.sessionTeam == TEAM_SPECTATOR ) {
if ( ca->sess.spectatorTime < cb->sess.spectatorTime ) {
if ( ca->sess.spectatorNum > cb->sess.spectatorNum ) {
return -1;
}
if ( ca->sess.spectatorTime > cb->sess.spectatorTime ) {
if ( ca->sess.spectatorNum < cb->sess.spectatorNum ) {
return 1;
}
return 0;

View file

@ -46,7 +46,7 @@ void G_WriteClientSessionData( gclient_t *client ) {
s = va("%i %i %i %i %i %i %i",
client->sess.sessionTeam,
client->sess.spectatorTime,
client->sess.spectatorNum,
client->sess.spectatorState,
client->sess.spectatorClient,
client->sess.wins,
@ -78,7 +78,7 @@ void G_ReadSessionData( gclient_t *client ) {
sscanf( s, "%i %i %i %i %i %i %i",
&sessionTeam,
&client->sess.spectatorTime,
&client->sess.spectatorNum,
&spectatorState,
&client->sess.spectatorClient,
&client->sess.wins,
@ -144,7 +144,7 @@ void G_InitSessionData( gclient_t *client, char *userinfo ) {
}
sess->spectatorState = SPECTATOR_FREE;
sess->spectatorTime = level.time;
AddTournamentQueue(client);
G_WriteClientSessionData( client );
}