summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-24 09:53:15 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-24 13:42:52 +0200
commitda338b5f05fd0154b3d1aba9ae45b944bfe865f2 (patch)
tree78a51e86b5b9ebcb3648209d987ae249b086e3e1 /src/game
parentc17c9c0f4d000a6765653a1168453a830e403117 (diff)
Discard players' votes when they leave.
Diffstat (limited to 'src/game')
-rw-r--r--src/game/bg_public.h2
-rw-r--r--src/game/g_active.c3
-rw-r--r--src/game/g_client.c19
-rw-r--r--src/game/g_cmds.c61
-rw-r--r--src/game/g_local.h2
5 files changed, 58 insertions, 29 deletions
diff --git a/src/game/bg_public.h b/src/game/bg_public.h
index 790e206..02ded16 100644
--- a/src/game/bg_public.h
+++ b/src/game/bg_public.h
@@ -291,8 +291,6 @@ typedef enum
#define EF_MOVER_STOP 0x00001000 // will push otherwise
#define EF_TALK 0x00002000 // draw a talk balloon
#define EF_CONNECTION 0x00004000 // draw a connection trouble sprite
-#define EF_VOTED 0x00008000 // already cast a vote
-#define EF_TEAMVOTED 0x00010000 // already cast a vote
#define EF_BLOBLOCKED 0x00020000 // TA: caught by a trapper
#define EF_REAL_LIGHT 0x00040000 // TA: light sprites according to ambient light
#define EF_DBUILDER 0x00080000 // designated builder protection
diff --git a/src/game/g_active.c b/src/game/g_active.c
index c419e30..63af175 100644
--- a/src/game/g_active.c
+++ b/src/game/g_active.c
@@ -2109,8 +2109,7 @@ void SpectatorClientEndFrame( gentity_t *ent )
if( cl -> sess.spectatorState != SPECTATOR_FOLLOW )
{
- flags = ( cl->ps.eFlags & ~( EF_VOTED | EF_TEAMVOTED ) ) |
- ( ent->client->ps.eFlags & ( EF_VOTED | EF_TEAMVOTED ) );
+ flags = cl->ps.eFlags | ent->client->ps.eFlags;
score = ent->client->ps.persistant[ PERS_SCORE ];
ping = ent->client->ps.ping;
ent->client->ps = cl->ps;
diff --git a/src/game/g_client.c b/src/game/g_client.c
index a9fdb1f..b30b9c7 100644
--- a/src/game/g_client.c
+++ b/src/game/g_client.c
@@ -2067,7 +2067,7 @@ void ClientSpawn( gentity_t *ent, gentity_t *spawn, vec3_t origin, vec3_t angles
client->pers.teamState.state = TEAM_ACTIVE;
// toggle the teleport bit so the client knows to not lerp
- flags = ent->client->ps.eFlags & ( EF_TELEPORT_BIT | EF_VOTED | EF_TEAMVOTED );
+ flags = ent->client->ps.eFlags & EF_TELEPORT_BIT;
flags ^= EF_TELEPORT_BIT;
G_UnlaggedClear( ent );
@@ -2347,6 +2347,23 @@ void ClientDisconnect( int clientNum )
ent->client->pers.control = 0;
}
+ // discard this player's vote
+ if( level.voteTime && level.votedHow[ clientNum ] )
+ {
+ if( level.votedHow[ clientNum ] > 0 )
+ {
+ level.voteYes--;
+ trap_SetConfigstring( CS_VOTE_YES, va( "%i", level.voteYes ) );
+ }
+ else
+ {
+ level.voteNo--;
+ trap_SetConfigstring( CS_VOTE_NO, va( "%i", level.voteNo ) );
+ }
+
+ level.votedHow[ clientNum ] = 0;
+ }
+
// look through the bhist and readjust it if the referenced ent has left
for( ptr = level.buildHistory; ptr; ptr = ptr->next )
{
diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c
index 17ec730..5c26da1 100644
--- a/src/game/g_cmds.c
+++ b/src/game/g_cmds.c
@@ -595,7 +595,9 @@ void G_LeaveTeam( gentity_t *self )
{
pTeam_t team = self->client->pers.teamSelection;
gentity_t *ent;
- int i;
+ int i, clientNum;
+
+ clientNum = self->client->ps.clientNum;
if( team == PTE_ALIENS )
G_RemoveFromSpawnQueue( &level.alienSpawnQueue, self->client->ps.clientNum );
@@ -636,6 +638,24 @@ void G_LeaveTeam( gentity_t *self )
ent->client->ps.stats[ STAT_STATE ] &= ~SS_POISONED;
}
}
+
+ if( level.teamVoteTime[ team ] && level.teamVotedHow[ team ][ clientNum ] )
+ {
+ int cs_offset = (team == PTE_ALIENS ? 1 : 0);
+
+ if( level.teamVotedHow[ team ][ clientNum ] > 0 )
+ {
+ level.teamVoteYes[ team ]--;
+ trap_SetConfigstring( CS_TEAMVOTE_YES + cs_offset, va( "%i", level.teamVoteYes[ team ] ) );
+ }
+ else
+ {
+ level.teamVoteNo[ team ]--;
+ trap_SetConfigstring( CS_TEAMVOTE_NO + cs_offset, va( "%i", level.teamVoteNo[ team ] ) );
+ }
+
+ level.teamVotedHow[ team ][ clientNum ] = 0;
+ }
}
/*
@@ -2418,8 +2438,7 @@ void Cmd_CallVote_f( gentity_t *ent )
level.voteTime = level.time;
level.voteNo = 0;
- for( i = 0 ; i < level.maxclients ; i++ )
- level.clients[i].ps.eFlags &= ~EF_VOTED;
+ memset( level.votedHow, 0, sizeof( level.votedHow ) );
if( !Q_stricmp( arg1, "poll" ) )
{
@@ -2427,8 +2446,8 @@ void Cmd_CallVote_f( gentity_t *ent )
}
else
{
- level.voteYes = 1;
- ent->client->ps.eFlags |= EF_VOTED;
+ level.votedHow[ ent - g_entities ] = 1;
+ level.voteYes = 1;
}
trap_SetConfigstring( CS_VOTE_TIME, va( "%i", level.voteTime ) );
@@ -2469,20 +2488,18 @@ void Cmd_Vote_f( gentity_t *ent )
if( ent->client->pers.teamSelection == PTE_ALIENS )
cs_offset = 1;
- if( level.teamVoteTime[ cs_offset ] )
+ if( level.teamVoteTime[ cs_offset ] &&
+ !level.teamVotedHow[ cs_offset ][ g_entities - ent ] )
{
- if( !(ent->client->ps.eFlags & EF_TEAMVOTED ) )
- {
- Cmd_TeamVote_f(ent);
- return;
- }
+ Cmd_TeamVote_f(ent);
+ return;
}
}
trap_SendServerCommand( ent-g_entities, "print \"No vote in progress\n\"" );
return;
}
- if( ent->client->ps.eFlags & EF_VOTED )
+ if( level.votedHow[ ent - g_entities ] )
{
trap_SendServerCommand( ent-g_entities, "print \"Vote already cast\n\"" );
return;
@@ -2490,18 +2507,18 @@ void Cmd_Vote_f( gentity_t *ent )
trap_SendServerCommand( ent-g_entities, "print \"Vote cast\n\"" );
- ent->client->ps.eFlags |= EF_VOTED;
-
trap_Argv( 1, msg, sizeof( msg ) );
if( msg[ 0 ] == 'y' || msg[ 1 ] == 'Y' || msg[ 1 ] == '1' )
{
level.voteYes++;
+ level.votedHow[ ent - g_entities ] = 1;
trap_SetConfigstring( CS_VOTE_YES, va( "%i", level.voteYes ) );
}
else
{
level.voteNo++;
+ level.votedHow[ ent - g_entities ] = -1;
trap_SetConfigstring( CS_VOTE_NO, va( "%i", level.voteNo ) );
}
@@ -2918,11 +2935,7 @@ void Cmd_CallTeamVote_f( gentity_t *ent )
level.teamVoteTime[ cs_offset ] = level.time;
level.teamVoteNo[ cs_offset ] = 0;
- for( i = 0 ; i < level.maxclients ; i++ )
- {
- if( level.clients[ i ].ps.stats[ STAT_PTEAM ] == team )
- level.clients[ i ].ps.eFlags &= ~EF_TEAMVOTED;
- }
+ memset( level.teamVotedHow[ cs_offset ], 0, sizeof( level.teamVotedHow[ 0 ] ));
if( !Q_stricmp( arg1, "poll" ) )
{
@@ -2930,8 +2943,8 @@ void Cmd_CallTeamVote_f( gentity_t *ent )
}
else
{
- level.teamVoteYes[ cs_offset ] = 1;
- ent->client->ps.eFlags |= EF_TEAMVOTED;
+ level.teamVotedHow[ cs_offset ][ ent - g_entities ] = 1;
+ level.teamVoteYes[ cs_offset ] = 1;
}
trap_SetConfigstring( CS_TEAMVOTE_TIME + cs_offset, va( "%i", level.teamVoteTime[ cs_offset ] ) );
@@ -2960,7 +2973,7 @@ void Cmd_TeamVote_f( gentity_t *ent )
return;
}
- if( ent->client->ps.eFlags & EF_TEAMVOTED )
+ if( level.teamVotedHow[ cs_offset ][ ent - g_entities ] )
{
trap_SendServerCommand( ent-g_entities, "print \"Team vote already cast\n\"" );
return;
@@ -2968,17 +2981,17 @@ void Cmd_TeamVote_f( gentity_t *ent )
trap_SendServerCommand( ent-g_entities, "print \"Team vote cast\n\"" );
- ent->client->ps.eFlags |= EF_TEAMVOTED;
-
trap_Argv( 1, msg, sizeof( msg ) );
if( msg[ 0 ] == 'y' || msg[ 1 ] == 'Y' || msg[ 1 ] == '1' )
{
+ level.teamVotedHow[ cs_offset ][ ent - g_entities ] = 1;
level.teamVoteYes[ cs_offset ]++;
trap_SetConfigstring( CS_TEAMVOTE_YES + cs_offset, va( "%i", level.teamVoteYes[ cs_offset ] ) );
}
else
{
+ level.teamVotedHow[ cs_offset ][ ent - g_entities ] = -1;
level.teamVoteNo[ cs_offset ]++;
trap_SetConfigstring( CS_TEAMVOTE_NO + cs_offset, va( "%i", level.teamVoteNo[ cs_offset ] ) );
}
diff --git a/src/game/g_local.h b/src/game/g_local.h
index 489b52a..82ad397 100644
--- a/src/game/g_local.h
+++ b/src/game/g_local.h
@@ -704,6 +704,7 @@ typedef struct
int voteYes;
int voteNo;
int numVotingClients; // set by CalculateRanks
+ int votedHow[MAX_CLIENTS]; // 0 is "hasn't voted", 1 is "voted yes", -1 is voted "no"
// team voting state
char teamVoteString[ 2 ][ MAX_STRING_CHARS ];
@@ -713,6 +714,7 @@ typedef struct
int teamVoteYes[ 2 ];
int teamVoteNo[ 2 ];
int numteamVotingClients[ 2 ]; // set by CalculateRanks
+ int teamVotedHow[ 2 ][ MAX_CLIENTS ];
// spawn variables
qboolean spawning; // the G_Spawn*() functions are valid