summaryrefslogtreecommitdiff
path: root/src/cgame
diff options
context:
space:
mode:
authorM. Kristall <mkpdev@gmail.com>2009-10-09 07:41:45 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:16:44 +0000
commit5d14c5b22672683dfd762e2c61f514ef8ef1aacd (patch)
tree1b2719c49ba638fb854cd113ca6c4d9fbeb69b50 /src/cgame
parentb5381f86afd9646f155eab40c83a902866b77849 (diff)
* Massive refactor of voting code
* Remove cvar g_suddenDeath since it is no longer needed * "Sudden Death in 0 seconds!" should no longer display on map start when sudden death is disabled
Diffstat (limited to 'src/cgame')
-rw-r--r--src/cgame/cg_draw.c73
-rw-r--r--src/cgame/cg_local.h16
-rw-r--r--src/cgame/cg_main.c13
-rw-r--r--src/cgame/cg_servercmds.c76
4 files changed, 53 insertions, 125 deletions
diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c
index 4ae6792d..ba8aaacf 100644
--- a/src/cgame/cg_draw.c
+++ b/src/cgame/cg_draw.c
@@ -2756,76 +2756,39 @@ static void CG_DrawCenterString( void )
CG_DrawVote
=================
*/
-static void CG_DrawVote( void )
+static void CG_DrawVote( team_t team )
{
char *s;
int sec;
vec4_t white = { 1.0f, 1.0f, 1.0f, 1.0f };
char yeskey[ 32 ], nokey[ 32 ];
- if( !cgs.voteTime )
+ if( !cgs.voteTime[ team ] )
return;
// play a talk beep whenever it is modified
- if( cgs.voteModified )
+ if( cgs.voteModified[ team ] )
{
- cgs.voteModified = qfalse;
+ cgs.voteModified[ team ] = qfalse;
trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND );
}
- sec = ( VOTE_TIME - ( cg.time - cgs.voteTime ) ) / 1000;
+ sec = ( VOTE_TIME - ( cg.time - cgs.voteTime[ team ] ) ) / 1000;
if( sec < 0 )
sec = 0;
- Q_strncpyz( yeskey, CG_KeyBinding( "vote yes" ), sizeof( yeskey ) );
- Q_strncpyz( nokey, CG_KeyBinding( "vote no" ), sizeof( nokey ) );
- s = va( "VOTE(%i): \"%s\" [%s]Yes:%i [%s]No:%i", sec, cgs.voteString,
- yeskey, cgs.voteYes, nokey, cgs.voteNo );
- UI_Text_Paint( 8, 340, 0.3f, white, s, 0, 0, ITEM_TEXTSTYLE_NORMAL );
-}
-
-/*
-=================
-CG_DrawTeamVote
-=================
-*/
-static void CG_DrawTeamVote( void )
-{
- char *s;
- int sec, cs_offset;
- vec4_t white = { 1.0f, 1.0f, 1.0f, 1.0f };
- char yeskey[ 32 ], nokey[ 32 ];
-
- if( cg.predictedPlayerState.stats[ STAT_TEAM ] == TEAM_HUMANS )
- cs_offset = 0;
- else if( cg.predictedPlayerState.stats[ STAT_TEAM ] == TEAM_ALIENS )
- cs_offset = 1;
- else
- return;
-
- if( !cgs.teamVoteTime[ cs_offset ] )
- return;
-
- // play a talk beep whenever it is modified
- if ( cgs.teamVoteModified[ cs_offset ] )
- {
- cgs.teamVoteModified[ cs_offset ] = qfalse;
- trap_S_StartLocalSound( cgs.media.talkSound, CHAN_LOCAL_SOUND );
- }
-
- sec = ( VOTE_TIME - ( cg.time - cgs.teamVoteTime[ cs_offset ] ) ) / 1000;
-
- if( sec < 0 )
- sec = 0;
-
- Q_strncpyz( yeskey, CG_KeyBinding( "teamvote yes" ), sizeof( yeskey ) );
- Q_strncpyz( nokey, CG_KeyBinding( "teamvote no" ), sizeof( nokey ) );
- s = va( "TEAMVOTE(%i): \"%s\" [%s]Yes:%i [%s]No:%i", sec,
- cgs.teamVoteString[ cs_offset ],
- yeskey, cgs.teamVoteYes[cs_offset],
- nokey, cgs.teamVoteNo[ cs_offset ] );
- UI_Text_Paint( 8, 360, 0.3f, white, s, 0, 0, ITEM_TEXTSTYLE_NORMAL );
+ Q_strncpyz( yeskey,
+ CG_KeyBinding( va( "%svote yes", team == TEAM_NONE ? "" : "team" ) ),
+ sizeof( yeskey ) );
+ Q_strncpyz( nokey,
+ CG_KeyBinding( va( "%svote no", team == TEAM_NONE ? "" : "team" ) ),
+ sizeof( nokey ) );
+ s = va( "%sVOTE(%i): \"%s\" [%s]Yes:%i [%s]No:%i",
+ team == TEAM_NONE ? "" : "TEAM", sec, cgs.voteString[ team ],
+ yeskey, cgs.voteYes[ team ], nokey, cgs.voteNo[ team ] );
+ UI_Text_Paint( 8, team == TEAM_NONE ? 340 : 360, 0.3f, white, s, 0, 0,
+ ITEM_TEXTSTYLE_NORMAL );
}
@@ -2999,8 +2962,8 @@ static void CG_Draw2D( void )
Menu_Paint( menu, qtrue );
- CG_DrawVote( );
- CG_DrawTeamVote( );
+ CG_DrawVote( TEAM_NONE );
+ CG_DrawVote( cg.predictedPlayerState.stats[ STAT_TEAM ] );
CG_DrawQueue( );
// don't draw center string if scoreboard is up
diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h
index 17328819..f7dda861 100644
--- a/src/cgame/cg_local.h
+++ b/src/cgame/cg_local.h
@@ -1356,17 +1356,11 @@ typedef struct
char mapname[ MAX_QPATH ];
qboolean markDeconstruct; // Whether or not buildables are marked
- int voteTime;
- int voteYes;
- int voteNo;
- qboolean voteModified; // beep whenever changed
- char voteString[ MAX_STRING_TOKENS ];
-
- int teamVoteTime[ 2 ];
- int teamVoteYes[ 2 ];
- int teamVoteNo[ 2 ];
- qboolean teamVoteModified[ 2 ]; // beep whenever changed
- char teamVoteString[ 2 ][ MAX_STRING_TOKENS ];
+ int voteTime[ NUM_TEAMS ];
+ int voteYes[ NUM_TEAMS ];
+ int voteNo[ NUM_TEAMS ];
+ qboolean voteModified[ NUM_TEAMS ];// beep whenever changed
+ char voteString[ NUM_TEAMS ][ MAX_STRING_TOKENS ];
int levelStartTime;
diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c
index 68a34159..01c24579 100644
--- a/src/cgame/cg_main.c
+++ b/src/cgame/cg_main.c
@@ -1763,12 +1763,15 @@ void CG_Init( int serverMessageNum, int serverCommandSequence, int clientNum )
// copy vote display strings so they don't show up blank if we see
// the same one directly after connecting
- Q_strncpyz( cgs.voteString, CG_ConfigString( CS_VOTE_STRING ),
+ Q_strncpyz( cgs.voteString[ TEAM_NONE ],
+ CG_ConfigString( CS_VOTE_STRING + TEAM_NONE ),
sizeof( cgs.voteString ) );
- Q_strncpyz( cgs.teamVoteString[ 0 ], CG_ConfigString( CS_TEAMVOTE_STRING + 0 ),
- sizeof( cgs.teamVoteString[ 0 ] ) );
- Q_strncpyz( cgs.teamVoteString[ 1 ], CG_ConfigString( CS_TEAMVOTE_STRING + 1 ),
- sizeof( cgs.teamVoteString[ 1 ] ) );
+ Q_strncpyz( cgs.voteString[ TEAM_ALIENS ],
+ CG_ConfigString( CS_VOTE_STRING + TEAM_ALIENS ),
+ sizeof( cgs.voteString[ TEAM_ALIENS ] ) );
+ Q_strncpyz( cgs.voteString[ TEAM_HUMANS ],
+ CG_ConfigString( CS_VOTE_STRING + TEAM_ALIENS ),
+ sizeof( cgs.voteString[ TEAM_HUMANS ] ) );
// check version
s = CG_ConfigString( CS_GAME_VERSION );
diff --git a/src/cgame/cg_servercmds.c b/src/cgame/cg_servercmds.c
index 2d9b7038..8e18fd9c 100644
--- a/src/cgame/cg_servercmds.c
+++ b/src/cgame/cg_servercmds.c
@@ -291,65 +291,33 @@ static void CG_ConfigStringModified( void )
}
else if( num == CS_LEVEL_START_TIME )
cgs.levelStartTime = atoi( str );
- else if( num == CS_VOTE_TIME )
+ else if( num >= CS_VOTE_TIME && num < CS_VOTE_TIME + NUM_TEAMS )
{
- cgs.voteTime = atoi( str );
- cgs.voteModified = qtrue;
-
- if( cgs.voteTime )
- trap_Cvar_Set( "ui_voteActive", "1" );
- else
- trap_Cvar_Set( "ui_voteActive", "0" );
- }
- else if( num == CS_VOTE_YES )
- {
- cgs.voteYes = atoi( str );
- cgs.voteModified = qtrue;
- }
- else if( num == CS_VOTE_NO )
- {
- cgs.voteNo = atoi( str );
- cgs.voteModified = qtrue;
- }
- else if( num == CS_VOTE_STRING )
- Q_strncpyz( cgs.voteString, str, sizeof( cgs.voteString ) );
- else if( num >= CS_TEAMVOTE_TIME && num <= CS_TEAMVOTE_TIME + 1 )
- {
- int cs_offset = num - CS_TEAMVOTE_TIME;
-
- cgs.teamVoteTime[ cs_offset ] = atoi( str );
- cgs.teamVoteModified[ cs_offset ] = qtrue;
-
- if( cs_offset == 0 )
- {
- if( cgs.teamVoteTime[ cs_offset ] )
- trap_Cvar_Set( "ui_humanTeamVoteActive", "1" );
- else
- trap_Cvar_Set( "ui_humanTeamVoteActive", "0" );
- }
- else if( cs_offset == 1 )
- {
- if( cgs.teamVoteTime[ cs_offset ] )
- trap_Cvar_Set( "ui_alienTeamVoteActive", "1" );
- else
- trap_Cvar_Set( "ui_alienTeamVoteActive", "0" );
- }
- }
- else if( num >= CS_TEAMVOTE_YES && num <= CS_TEAMVOTE_YES + 1 )
- {
- cgs.teamVoteYes[ num - CS_TEAMVOTE_YES ] = atoi( str );
- cgs.teamVoteModified[ num - CS_TEAMVOTE_YES ] = qtrue;
+ cgs.voteTime[ num - CS_VOTE_TIME ] = atoi( str );
+ cgs.voteModified[ num - CS_VOTE_TIME ] = qtrue;
+
+ if( num - CS_VOTE_TIME == TEAM_NONE )
+ trap_Cvar_Set( "ui_voteActive", cgs.voteTime[ TEAM_NONE ] ? "1" : "0" );
+ else if( num - CS_VOTE_TIME == TEAM_ALIENS )
+ trap_Cvar_Set( "ui_alienTeamVoteActive",
+ cgs.voteTime[ TEAM_ALIENS ] ? "1" : "0" );
+ else if( num - CS_VOTE_TIME == TEAM_HUMANS )
+ trap_Cvar_Set( "ui_humanTeamVoteActive",
+ cgs.voteTime[ TEAM_HUMANS ] ? "1" : "0" );
}
- else if( num >= CS_TEAMVOTE_NO && num <= CS_TEAMVOTE_NO + 1 )
+ else if( num >= CS_VOTE_YES && num < CS_VOTE_YES + NUM_TEAMS )
{
- cgs.teamVoteNo[ num - CS_TEAMVOTE_NO ] = atoi( str );
- cgs.teamVoteModified[ num - CS_TEAMVOTE_NO ] = qtrue;
+ cgs.voteYes[ num - CS_VOTE_YES ] = atoi( str );
+ cgs.voteModified[ num - CS_VOTE_YES ] = qtrue;
}
- else if( num >= CS_TEAMVOTE_STRING && num <= CS_TEAMVOTE_STRING + 1 )
+ else if( num >= CS_VOTE_NO && num < CS_VOTE_NO + NUM_TEAMS )
{
- Q_strncpyz( cgs.teamVoteString[ num - CS_TEAMVOTE_STRING ], str,
- sizeof( cgs.teamVoteString[ num - CS_TEAMVOTE_STRING ] ) );
+ cgs.voteNo[ num - CS_VOTE_NO ] = atoi( str );
+ cgs.voteModified[ num - CS_VOTE_NO ] = qtrue;
}
+ else if( num >= CS_VOTE_STRING && num < CS_VOTE_STRING + NUM_TEAMS )
+ Q_strncpyz( cgs.voteString[ num - CS_VOTE_STRING ], str,
+ sizeof( cgs.voteString[ num - CS_VOTE_STRING ] ) );
else if( num == CS_INTERMISSION )
cg.intermissionStarted = atoi( str );
else if( num >= CS_MODELS && num < CS_MODELS+MAX_MODELS )
@@ -406,7 +374,7 @@ static void CG_MapRestart( void )
cg.intermissionStarted = qfalse;
- cgs.voteTime = 0;
+ cgs.voteTime[ TEAM_NONE ] = 0;
cg.mapRestart = qtrue;