diff --git a/code/game/g_cmds.c b/code/game/g_cmds.c index 6185c2a5..02469b30 100644 --- a/code/game/g_cmds.c +++ b/code/game/g_cmds.c @@ -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; diff --git a/code/game/g_local.h b/code/game/g_local.h index 3698a2c9..89dbafce 100644 --- a/code/game/g_local.h +++ b/code/game/g_local.h @@ -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, ... ); diff --git a/code/game/g_main.c b/code/game/g_main.c index 963355ff..ed4dcf00 100644 --- a/code/game/g_main.c +++ b/code/game/g_main.c @@ -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; diff --git a/code/game/g_session.c b/code/game/g_session.c index 26a9e166..75eb2e0f 100644 --- a/code/game/g_session.c +++ b/code/game/g_session.c @@ -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 ); }