From fab71cd44004636f3298ef9cef363cf82d85c152 Mon Sep 17 00:00:00 2001 From: Mikko Tiusanen Date: Wed, 24 Sep 2014 21:40:34 +0300 Subject: Added support for forcing random teams when joining the game. --- src/game/g_client.c | 9 ++++++++- src/game/g_local.h | 1 + src/game/g_main.c | 6 +++++- src/game/g_spawn.c | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/game/g_client.c b/src/game/g_client.c index fc797e5..1d50a97 100644 --- a/src/game/g_client.c +++ b/src/game/g_client.c @@ -1229,7 +1229,6 @@ char *ClientConnect( int clientNum, qboolean firstTime ) G_ChangeTeam( ent, client->sess.restartTeam ); client->sess.restartTeam = TEAM_NONE; } - return NULL; } @@ -1299,6 +1298,14 @@ void ClientBegin( int clientNum ) client->sess.seenWelcome = 1; G_TriggerMenu( client->ps.clientNum, MN_WELCOME ); } + + if ( g_ForceRandomTeams.integer ) { + if( level.numAlienClients > level.numHumanClients ) { + G_ChangeTeam( ent, TEAM_HUMANS ); + } else if( level.numHumanClients > level.numAlienClients ) { + G_ChangeTeam( ent, TEAM_ALIENS ); + } else G_ChangeTeam( ent, random() >= 0.5f ? TEAM_ALIENS : TEAM_HUMANS ); + } } /* diff --git a/src/game/g_local.h b/src/game/g_local.h index 44c6996..d82c862 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -1286,6 +1286,7 @@ extern vmCvar_t g_KillRewardMultiplierH; extern vmCvar_t g_ConstantRewardFactor; extern vmCvar_t g_TeamRewardFactor; extern vmCvar_t g_PlayerRewardFactor; +extern vmCvar_t g_ForceRandomTeams; void trap_Print( const char *fmt ); void trap_Error( const char *fmt ); diff --git a/src/game/g_main.c b/src/game/g_main.c index f5d8d8a..afbd986 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -194,6 +194,7 @@ vmCvar_t g_TeamRewardFactor; vmCvar_t g_PlayerRewardFactor; vmCvar_t g_TimerPeriod; vmCvar_t g_TimerCommand; +vmCvar_t g_ForceRandomTeams; // copy cvars that can be set in worldspawn so they can be restored later static char cv_gravity[ MAX_CVAR_VALUE_STRING ]; @@ -357,7 +358,8 @@ static cvarTable_t gameCvarTable[ ] = { &g_TeamRewardFactor, "g_TeamRewardFactor", "0.5", CVAR_ARCHIVE, 0, qfalse }, { &g_PlayerRewardFactor, "g_PlayerRewardFactor", "0.25", CVAR_ARCHIVE, 0, qfalse }, { &g_TimerPeriod, "g_TimerPeriod", "0", CVAR_ARCHIVE, 0, qfalse }, - { &g_TimerCommand, "g_TimerCommand", "", CVAR_ARCHIVE, 0, qfalse } + { &g_TimerCommand, "g_TimerCommand", "", CVAR_ARCHIVE, 0, qfalse }, + { &g_ForceRandomTeams, "g_ForceRandomTeams", "0", CVAR_ARCHIVE, 0, qfalse } }; static int gameCvarTableSize = sizeof( gameCvarTable ) / sizeof( gameCvarTable[ 0 ] ); void G_InitGame( int levelTime, int randomSeed, int restart ); @@ -717,6 +719,8 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) trap_Cvar_Set( "g_humanStage", va( "%d", S1 ) ); trap_Cvar_Set( "g_alienCredits", 0 ); trap_Cvar_Set( "g_humanCredits", 0 ); + if( g_ForceRandomTeams.integer == 2) + trap_Cvar_Set( "g_ForceRandomTeams", 0 ); level.suddenDeathBeginTime = g_suddenDeathTime.integer * 60000; level.nextArmageddonKillTime = (g_suddenDeathTime.integer+g_armageddonInitialTimeStep.integer) * 60000; level.nextCommandTime = g_TimerPeriod.integer; diff --git a/src/game/g_spawn.c b/src/game/g_spawn.c index 83a9fab..8edf5c3 100644 --- a/src/game/g_spawn.c +++ b/src/game/g_spawn.c @@ -635,7 +635,7 @@ void SP_worldspawn( void ) // see if we want a warmup time trap_SetConfigstring( CS_WARMUP, "-1" ); - if( g_doWarmup.integer ) + if( g_doWarmup.integer && !g_ForceRandomTeams.integer ) { level.warmupTime = level.time - level.startTime + ( g_warmup.integer * 1000 ); trap_SetConfigstring( CS_WARMUP, va( "%i", level.warmupTime ) ); -- cgit