From bf88e3e18ce55a397e2ec674c3541c606a0fe8ea Mon Sep 17 00:00:00 2001 From: Roman Tetelman Date: Sat, 3 Oct 2009 11:55:12 +0000 Subject: * revert part of r77 to allow clients to keep their credits * put back clientPersistant_t.savedCredits --- src/game/g_cmds.c | 32 ++++++++++++++++++++++++++++++-- src/game/g_local.h | 3 +++ 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index bd819988..48bc3a0a 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -595,8 +595,36 @@ void G_ChangeTeam( gentity_t *ent, team_t newTeam ) ClientSpawn( ent, NULL, NULL, NULL ); ent->client->pers.joinedATeam = qtrue; ent->client->pers.teamChangeTime = level.time; - ent->client->pers.credit = 0; - ent->client->ps.persistant[ PERS_CREDIT ] = 0; + + if( oldTeam == TEAM_NONE ) + { + // ps.persistant[] from a spectator cannot be trusted + ent->client->ps.persistant[ PERS_CREDIT ] = ent->client->pers.savedCredit; + } + else if( oldTeam == TEAM_HUMANS && newTeam == TEAM_ALIENS ) + { + // Convert from human to alien credits + ent->client->ps.persistant[ PERS_CREDIT ] = + (int)( ent->client->ps.persistant[ PERS_CREDIT ] * + ALIEN_MAX_CREDITS / HUMAN_MAX_CREDITS + 0.5f ); + } + else if( oldTeam == TEAM_ALIENS && newTeam == TEAM_HUMANS ) + { + // Convert from alien to human credits + ent->client->ps.persistant[ PERS_CREDIT ] = + (int)( ent->client->ps.persistant[ PERS_CREDIT ] * + HUMAN_MAX_CREDITS / ALIEN_MAX_CREDITS + 0.5f ); + } + + ent->client->pers.credit = ent->client->ps.persistant[ PERS_CREDIT ]; + + if( newTeam == TEAM_NONE ) + { + // save values before the client enters the spectator team and their + // ps.persistant[] values become trashed + ent->client->pers.savedCredit = ent->client->ps.persistant[ PERS_CREDIT ]; + } + ClientUserinfoChanged( ent->client->ps.clientNum ); } diff --git a/src/game/g_local.h b/src/game/g_local.h index 764892ab..d7bb0a6f 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -323,6 +323,9 @@ typedef struct int credit; int ping; + // used to save persistant[] values while in SPECTATOR_FOLLOW mode + int savedCredit; + // votes qboolean vote; qboolean teamVote; -- cgit