From a75a973733f62c9f1fe6f1c1787762db78973771 Mon Sep 17 00:00:00 2001 From: "Tony J. White" Date: Fri, 27 Apr 2007 04:19:11 +0000 Subject: * (bug 2958) new function G_LeaveTeam() takes care of cancelling out a player's active missles, poision, and spectators following him when he switches teams. (M. Kristall) --- src/game/g_client.c | 14 +------------- src/game/g_cmds.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++----- src/game/g_local.h | 1 + 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/game/g_client.c b/src/game/g_client.c index 75136661..041821a2 100644 --- a/src/game/g_client.c +++ b/src/game/g_client.c @@ -1661,20 +1661,13 @@ void ClientDisconnect( int clientNum ) return; G_admin_namelog_update( ent->client, qtrue ); + G_LeaveTeam( ent ); // stop any following clients for( i = 0; i < level.maxclients; i++ ) { // remove any /ignore settings for this clientNum BG_ClientListRemove( &level.clients[ i ].sess.ignoreList, clientNum ); - - if( level.clients[ i ].sess.sessionTeam == TEAM_SPECTATOR && - level.clients[ i ].sess.spectatorState == SPECTATOR_FOLLOW && - level.clients[ i ].sess.spectatorClient == clientNum ) - { - if( !G_FollowNewClient( &g_entities[ i ], 1 ) ) - G_StopFollowing( &g_entities[ i ] ); - } } // send effect if they were completely connected @@ -1688,11 +1681,6 @@ void ClientDisconnect( int clientNum ) G_LogPrintf( "ClientDisconnect: %i [%s] (%s) \"%s\"\n", clientNum, ent->client->pers.ip, ent->client->pers.guid, ent->client->pers.netname ); - if( ent->client->pers.teamSelection == PTE_ALIENS ) - G_RemoveFromSpawnQueue( &level.alienSpawnQueue, ent->client->ps.clientNum ); - else if( ent->client->pers.teamSelection == PTE_HUMANS ) - G_RemoveFromSpawnQueue( &level.humanSpawnQueue, ent->client->ps.clientNum ); - trap_UnlinkEntity( ent ); ent->s.modelindex = 0; ent->inuse = qfalse; diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index 4c204361..fe56d2ed 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -586,6 +586,54 @@ void Cmd_Kill_f( gentity_t *ent ) } } +/* +================== +G_LeaveTeam +================== +*/ +void G_LeaveTeam( gentity_t *self ) +{ + pTeam_t team = self->client->pers.teamSelection; + gentity_t *ent; + int i; + + if( team == PTE_ALIENS ) + G_RemoveFromSpawnQueue( &level.alienSpawnQueue, self->client->ps.clientNum ); + else if( team == PTE_HUMANS ) + G_RemoveFromSpawnQueue( &level.humanSpawnQueue, self->client->ps.clientNum ); + else + return; + + for( i = 0; i < level.num_entities; i++ ) + { + ent = &g_entities[ i ]; + if( !ent->inuse ) + continue; + + // clean up projectiles + if( ent->s.eType == ET_MISSILE && ent->r.ownerNum == self->s.number ) + G_FreeEntity( ent ); + if( ent->client && ent->client->pers.connected == CON_CONNECTED ) + { + // stop following clients + if( ent->client->sess.sessionTeam == TEAM_SPECTATOR && + ent->client->sess.spectatorState == SPECTATOR_FOLLOW && + ent->client->sess.spectatorClient == self->client->ps.clientNum ) + { + if( !G_FollowNewClient( ent, 1 ) ) + G_StopFollowing( ent ); + } + // cure poison + if( ent->client->ps.stats[ STAT_STATE ] & SS_POISONCLOUDED && + ent->client->lastPoisonCloudedClient == self ) + ent->client->ps.stats[ STAT_STATE ] &= ~SS_POISONCLOUDED; + if( ent->client->ps.stats[ STAT_STATE ] & SS_POISONED && + ent->client->lastPoisonClient == self ) + ent->client->ps.stats[ STAT_STATE ] &= ~SS_POISONED; + } + } +} + /* ================= G_ChangeTeam @@ -598,13 +646,9 @@ void G_ChangeTeam( gentity_t *ent, pTeam_t newTeam ) if( oldTeam == newTeam ) return; + G_LeaveTeam( ent ); ent->client->pers.teamSelection = newTeam; - if( oldTeam == PTE_ALIENS ) - G_RemoveFromSpawnQueue( &level.alienSpawnQueue, ent->client->ps.clientNum ); - else if( oldTeam == PTE_HUMANS ) - G_RemoveFromSpawnQueue( &level.humanSpawnQueue, ent->client->ps.clientNum ); - // under certain circumstances, clients can keep their kills and credits // when switching teams if( G_admin_permission( ent, ADMF_TEAMCHANGEFREE ) || diff --git a/src/game/g_local.h b/src/game/g_local.h index a059751f..0015e54e 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -682,6 +682,7 @@ int G_SayArgc( void ); qboolean G_SayArgv( int n, char *buffer, int bufferLength ); char *G_SayConcatArgs( int start ); void G_DecolorString( char *in, char *out ); +void G_LeaveTeam( gentity_t *self ); void G_ChangeTeam( gentity_t *ent, pTeam_t newTeam ); void G_SanitiseName( char *in, char *out ); void G_PrivateMessage( gentity_t *ent ); -- cgit