Skip to content

Commit

Permalink
Smart follow on +use button
Browse files Browse the repository at this point in the history
  • Loading branch information
aufau committed Feb 19, 2016
1 parent 20fdb2e commit bdf0c63
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions code/game/g_active.c
Expand Up @@ -624,6 +624,10 @@ void SpectatorThink( gentity_t *ent, usercmd_t *ucmd ) {
// attack button cycles through spectators
if ( ( client->buttons & BUTTON_ATTACK ) && ! ( client->oldbuttons & BUTTON_ATTACK ) ) {
Cmd_FollowCycle_f( ent, 1 );
} else if ( ( client->buttons & BUTTON_ALT_ATTACK ) && ! ( client->oldbuttons & BUTTON_ALT_ATTACK ) ) {
Cmd_FollowCycle_f( ent, -1 );
} else if ( ( client->buttons & BUTTON_USE ) && ! ( client->oldbuttons & BUTTON_USE ) ) {
Cmd_SmartFollowCycle_f( ent );
}

if (client->sess.spectatorState == SPECTATOR_FOLLOW && (ucmd->upmove > 0))
Expand Down
9 changes: 9 additions & 0 deletions code/game/g_client.c
Expand Up @@ -2057,6 +2057,15 @@ void ClientDisconnect( int clientNum ) {
}
i = 0;

// stop any following clients
for ( i = 0 ; i < level.maxclients ; i++ ) {
if ( level.clients[i].sess.sessionTeam == TEAM_SPECTATOR
&& level.clients[i].sess.spectatorState == SPECTATOR_FOLLOW
&& level.clients[i].sess.spectatorClient == clientNum ) {
StopFollowing( &g_entities[i] );
}
}

// send effect if they were completely connected
if ( ent->client->pers.connected == CON_CONNECTED
&& ent->client->sess.sessionTeam != TEAM_SPECTATOR ) {
Expand Down
74 changes: 74 additions & 0 deletions code/game/g_cmds.c
Expand Up @@ -1084,6 +1084,80 @@ void Cmd_FollowCycle_f( gentity_t *ent, int dir ) {
// leave it where it was
}

void Cmd_SmartFollowCycle_f( gentity_t *ent )
{
gclient_t *client;
gclient_t *ci;
int clientNum, clientRank;
int i;

if ( ent->client->sess.spectatorState != SPECTATOR_FOLLOW ) {
clientNum = ent->client->sess.spectatorClient;
} else {
clientNum = -1;
}

if (clientNum == -1) {
clientNum = level.follow1;
} else if (clientNum == -2) {
clientNum = level.follow2;
}
if (clientNum < 0) {
StopFollowing(ent);
return;
}

client = &level.clients[clientNum];

// Alternate between dueling players
if ( client->ps.duelInProgress ) {
ent->client->sess.spectatorClient = client->ps.duelIndex;
return;
}

i = 0;
while (i < level.numPlayingClients && level.sortedClients[i] != clientNum) {
i++;
}
if (i >= level.numPlayingClients) {
return;
}

clientRank = i;

// Try to find a powerup player first
do {
if (--i < 0) {
i = level.numPlayingClients - 1;
}
ci = &level.clients[level.sortedClients[i]];

if (ci->ps.isJediMaster || ci->ps.powerups[PW_REDFLAG] ||
ci->ps.powerups[PW_BLUEFLAG] || ci->ps.powerups[PW_YSALAMIRI]) {
ent->client->sess.spectatorClient = level.sortedClients[i];
return;
}
} while (i != clientRank);

if ( GT_Team(g_gametype.integer) ) {
// Cycle through sorted team
do {
if (--i < 0) {
i = level.numPlayingClients - 1;
}
ci = &level.clients[level.sortedClients[i]];
} while (ci->sess.sessionTeam != client->sess.sessionTeam);

ent->client->sess.spectatorClient = level.sortedClients[i];
} else {
// Cycle through sorted players
if (--i < 0) {
i = level.numPlayingClients - 1;
}

ent->client->sess.spectatorClient = level.sortedClients[i];
}
}

/*
==================
Expand Down
1 change: 1 addition & 0 deletions code/game/g_local.h
Expand Up @@ -554,6 +554,7 @@ qboolean ValidateTeam( int ignoreClientNum, team_t team );
void SetTeam( gentity_t *ent, team_t team );
void SetTeamFromString( gentity_t *ent, char *s );
void Cmd_FollowCycle_f( gentity_t *ent, int dir );
void Cmd_SmartFollowCycle_f( gentity_t *ent );
void Cmd_SaberAttackCycle_f(gentity_t *ent);
int G_ItemUsable(playerState_t *ps, int forcedUse);
void Cmd_ToggleSaber_f(gentity_t *ent);
Expand Down

0 comments on commit bdf0c63

Please sign in to comment.