Skip to content

Commit

Permalink
Initial implementation of the intermission music system.
Browse files Browse the repository at this point in the history
  • Loading branch information
dGr8LookinSparky committed Dec 23, 2017
1 parent 6099c8d commit eaa2f7a
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 87 deletions.
17 changes: 14 additions & 3 deletions src/cgame/cg_local.h
Expand Up @@ -1216,6 +1216,16 @@ typedef struct
qhandle_t b3;
} cgMediaBinaryShader_t;

typedef enum
{
INTMSN_SND_WIN,
INTMSN_SND_LOSS,
INTMSN_SND_EVAC,
INTMSN_SND_TIME,

NUM_INTMSN_SNDS
} intermissionSound_t;

typedef struct
{
qhandle_t charsetShader;
Expand Down Expand Up @@ -1287,9 +1297,8 @@ typedef struct
sfxHandle_t votePassed;
sfxHandle_t voteFailed;

sfxHandle_t intermissionDrawSound;
sfxHandle_t intermissionLossSound;
sfxHandle_t intermissionWinSound;
sfxHandle_t intermissionCustomSounds[ NUM_TEAMS ][ NUM_INTMSN_SNDS ][ MAX_INTERMISSION_SOUND_SETS ];
sfxHandle_t intermissionDefaultSounds[ NUM_INTMSN_SNDS ];
sfxHandle_t warmupEndSound;

sfxHandle_t watrInSound;
Expand Down Expand Up @@ -1707,6 +1716,8 @@ extern vmCvar_t cg_chatTeamPrefix;

extern vmCvar_t cg_warmupBuildableRespawning;

extern vmCvar_t cg_intermissionMusic;

//
// cg_main.c
//
Expand Down
43 changes: 38 additions & 5 deletions src/cgame/cg_main.c
Expand Up @@ -255,6 +255,8 @@ vmCvar_t cg_chatTeamPrefix;

vmCvar_t cg_warmupBuildableRespawning;

vmCvar_t cg_intermissionMusic;

typedef struct
{
vmCvar_t *vmCvar;
Expand Down Expand Up @@ -421,7 +423,9 @@ static cvarTable_t cvarTable[ ] =

{ &cg_chatTeamPrefix, "cg_chatTeamPrefix", "1", CVAR_ARCHIVE },

{ &cg_warmupBuildableRespawning, "g_warmupBuildableRespawning", "0", 0 }
{ &cg_warmupBuildableRespawning, "g_warmupBuildableRespawning", "0", 0 },

{ &cg_intermissionMusic, "cg_intermissionMusic", "1", CVAR_ARCHIVE }
};

static size_t cvarTableSize = ARRAY_LEN( cvarTable );
Expand Down Expand Up @@ -836,7 +840,7 @@ called during a precache command
*/
static void CG_RegisterSounds( void )
{
int i;
int i, j;
char name[ MAX_QPATH ];
const char *soundName;

Expand All @@ -858,9 +862,38 @@ static void CG_RegisterSounds( void )

cgs.media.voteAlarmSound = trap_S_RegisterSound( "sound/misc/213096__soundsexciting__gong-with-music.wav", qfalse );

cgs.media.intermissionDrawSound = trap_S_RegisterSound( "sound/misc/intermission_draw.wav", qfalse );
cgs.media.intermissionLossSound = trap_S_RegisterSound( "sound/misc/intermission_loss.wav", qfalse );
cgs.media.intermissionWinSound = trap_S_RegisterSound( "sound/misc/intermission_win.wav", qfalse );
for( i = 0; i < NUM_TEAMS; i++ )
{
for( j = 0; j < MAX_INTERMISSION_SOUND_SETS; j++ )
{
if( i != TEAM_NONE )
{
cgs.media.intermissionCustomSounds[ i ][ INTMSN_SND_WIN ][ j ] =
trap_S_RegisterSound( va( "sound/teams/%s/intermission_win%i",
BG_Team( i )->name2, j ), qfalse );
cgs.media.intermissionCustomSounds[ i ][ INTMSN_SND_LOSS ][ j ] =
trap_S_RegisterSound( va( "sound/teams/%s/intermission_loss%i",
BG_Team( i )->name2, j ), qfalse );
}
cgs.media.intermissionCustomSounds[ i ][ INTMSN_SND_EVAC ][ j ] =
trap_S_RegisterSound( va( "sound/teams/%s/intermission_evac%i",
BG_Team( i )->name2, j ), qfalse );
cgs.media.intermissionCustomSounds[ i ][ INTMSN_SND_TIME ][ j ] =
trap_S_RegisterSound( va( "sound/teams/%s/intermission_time%i",
BG_Team( i )->name2, j ), qfalse );
}
}

//these defaults must be .wav so that the old clients can play them
cgs.media.intermissionDefaultSounds[ INTMSN_SND_WIN ] =
trap_S_RegisterSound( "sound/misc/intermission_default_win.wav", qfalse );
cgs.media.intermissionDefaultSounds[ INTMSN_SND_LOSS ] =
trap_S_RegisterSound( "sound/misc/intermission_default_loss.wav", qfalse );
cgs.media.intermissionDefaultSounds[ INTMSN_SND_EVAC ] =
trap_S_RegisterSound( "sound/misc/intermission_default_evac.wav", qfalse );
cgs.media.intermissionDefaultSounds[ INTMSN_SND_TIME ] =
trap_S_RegisterSound( "sound/misc/intermission_default_time.wav", qfalse );

cgs.media.warmupEndSound = trap_S_RegisterSound( "sound/misc/warmup_end.wav", qfalse );

cgs.media.talkSound = trap_S_RegisterSound( "sound/misc/talk.wav", qfalse );
Expand Down
8 changes: 4 additions & 4 deletions src/cgame/cg_players.c
Expand Up @@ -755,13 +755,13 @@ static void CG_StatusMessages( clientInfo_t *new, clientInfo_t *old )
{
if( new->team == TEAM_NONE )
CG_Printf( "%s" S_COLOR_WHITE " left the %ss\n", new->name,
BG_TeamName( old->team ) );
BG_Team( old->team )->name2 );
else if( old->team == TEAM_NONE )
CG_Printf( "%s" S_COLOR_WHITE " joined the %ss\n", new->name,
BG_TeamName( new->team ) );
BG_Team( new->team )->name2 );
else
CG_Printf( "%s" S_COLOR_WHITE " left the %ss and joined the %ss\n",
new->name, BG_TeamName( old->team ), BG_TeamName( new->team ) );
new->name, BG_Team( old->team )->name2, BG_Team( new->team )->name2 );
}
}

Expand Down Expand Up @@ -812,7 +812,7 @@ void CG_NewClientInfo( int clientNum )
char config[ MAX_CVAR_VALUE_STRING ];

trap_Cvar_VariableStringBuffer(
va( "cg_%sConfig", BG_TeamName( newInfo.team ) ),
va( "cg_%sConfig", BG_Team( newInfo.team )->name2 ),
config, sizeof( config ) );

if( config[ 0 ] )
Expand Down
104 changes: 71 additions & 33 deletions src/cgame/cg_servercmds.c
Expand Up @@ -217,7 +217,7 @@ void CG_ParseVoteStrings( int team, const char *conStr )
cgs.voteString[ subStringIndex ][ team ][subStringChar] = cgs.voteString[ RAW_VOTE_STRING ][ team ][rawStringChar];
++subStringChar;
}
}
}

cgs.voteString[ subStringIndex ][ team ][subStringChar] = 0;
++subStringIndex;
Expand Down Expand Up @@ -367,6 +367,29 @@ static void CG_AnnounceHumanStageTransistion( stage_t from, stage_t to )
GIANTCHAR_WIDTH * 4, -1 );
}

/*
================
CG_PlayIntermissionSound
================
*/
static void CG_PlayIntermissionSound( team_t team, intermissionSound_t soundType, int index )
{
int i = ( index > MAX_INTERMISSION_SOUND_SETS ) ? MAX_INTERMISSION_SOUND_SETS : index;
sfxHandle_t sound = cgs.media.intermissionCustomSounds[ team ][ soundType ][ i ];

if( !sound )
sound = cgs.media.intermissionCustomSounds[ team ][ soundType ][ 0 ];

if( !sound )
sound = cgs.media.intermissionDefaultSounds[ soundType ];

if( !sound )
return;

trap_S_StartLocalSound( sound, CHAN_LOCAL_SOUND );
}

/*
================
CG_ConfigStringModified
Expand Down Expand Up @@ -496,43 +519,57 @@ static void CG_ConfigStringModified( void )
else if( num == CS_WINNER )
{
team_t team = cg.snap->ps.stats[ STAT_TEAM ];
int index;
team_t winningTeam;
char winner[ MAX_TOKENLENGTH ] = {'\0'};

trap_Cvar_Set( "ui_winner", str );
if( !Q_stricmp( str, "Evacuation" ) ||
!Q_stricmp( str, "Stalemate" ) )
trap_S_StartLocalSound( cgs.media.intermissionDrawSound, CHAN_LOCAL_SOUND );
else if( !Q_stricmp( str, "Humans Win" ) )
//parse the CS_WINNER string
if( str )
{
switch ( team )
{
case TEAM_NONE:
trap_S_StartLocalSound( cgs.media.intermissionDrawSound, CHAN_LOCAL_SOUND );
break;
case TEAM_HUMANS:
trap_S_StartLocalSound( cgs.media.intermissionWinSound, CHAN_LOCAL_SOUND );
break;
int rawCharNum, subCharNum;
char *indexStr = "";

default:
trap_S_StartLocalSound( cgs.media.intermissionLossSound, CHAN_LOCAL_SOUND );
break;
}
}
else if( !Q_stricmp( str, "Aliens Win" ) )
{
switch ( team )
{
case TEAM_NONE:
trap_S_StartLocalSound( cgs.media.intermissionDrawSound, CHAN_LOCAL_SOUND );
break;
case TEAM_ALIENS:
trap_S_StartLocalSound( cgs.media.intermissionWinSound, CHAN_LOCAL_SOUND );
break;
for( rawCharNum = 0;
str[rawCharNum] && ( str[rawCharNum] != '|' );
rawCharNum++ )
indexStr[ rawCharNum ] = str[ rawCharNum ];

default:
trap_S_StartLocalSound( cgs.media.intermissionLossSound, CHAN_LOCAL_SOUND );
break;
index = atoi( indexStr );

if( str[rawCharNum] == '|' )
rawCharNum++;

for( subCharNum = 0;
str[rawCharNum];
rawCharNum++, subCharNum++ )
winner[ subCharNum ] = str[ rawCharNum ];

if( cg_intermissionMusic.integer )
{
if( !Q_stricmp( winner, "Evacuation" ) )
CG_PlayIntermissionSound( team, INTMSN_SND_EVAC, index );
if( !Q_stricmp( winner, "Stalemate" ) )
CG_PlayIntermissionSound( team, INTMSN_SND_TIME, index );
else if( winner )
{
for( winningTeam = 0; winningTeam < NUM_TEAMS; winningTeam++ )
{
if( Q_stricmp( winner, va( "%s Win", BG_Team( winningTeam )->humanName ) ) )
continue;

if( team == winningTeam ||
team == TEAM_NONE )
CG_PlayIntermissionSound( winningTeam, INTMSN_SND_WIN, index );
else
CG_PlayIntermissionSound( team, INTMSN_SND_LOSS, index );

break;
}
}
}
}

trap_Cvar_Set( "ui_winner", winner );
}
else if( num == CS_SHADERSTATE )
{
Expand Down Expand Up @@ -1137,7 +1174,8 @@ static void CG_Say( int clientNum, saymode_t mode, const char *text )

if( cg_chatTeamPrefix.integer )
Com_sprintf( prefix, sizeof( prefix ), "%s[%s%c%s]" S_COLOR_WHITE " ",
tbcolor, tcolor, toupper( *( BG_TeamName( ci->team ) ) ),
tbcolor, tcolor,
toupper( *( BG_Team( ci->team )->name2 ) ),
tbcolor );

if( ( mode == SAY_TEAM || mode == SAY_AREA ) &&
Expand Down
19 changes: 3 additions & 16 deletions src/game/bg_misc.c
Expand Up @@ -46,12 +46,14 @@ static const teamAttributes_t bg_teamList[ ] =
{
TEAM_NONE, //int number;
"spectate", //char *name;
"spectator", //char *name2;
"Spectators", //char *humanName;
"Spectators watch the game without participating.",
},
{
TEAM_ALIENS, //int number;
"aliens", //char *name;
"alien", //char *name2;
"Aliens", //char *humanName;
"The strength of Aliens lie in their agility, fierce melee attacks and "
"their ability to construct new bases without much restriction. They "
Expand All @@ -63,6 +65,7 @@ static const teamAttributes_t bg_teamList[ ] =
{
TEAM_HUMANS, //int number;
"humans", //char *name;
"human", //char *name2;
"Humans", //char *humanName;
"Humans are the masters of technology. Although their bases are "
"restricted by power requirements, automated defenses help ensure that "
Expand Down Expand Up @@ -4460,22 +4463,6 @@ const teamAttributes_t *BG_Team( team_t team )
&bg_teamList[ team ] : &nullTeam;
}

/*
============
BG_TeamName
============
*/
char *BG_TeamName( team_t team )
{
if( team == TEAM_NONE )
return "spectator";
if( team == TEAM_ALIENS )
return "alien";
if( team == TEAM_HUMANS )
return "human";
return "<team>";
}

int cmdcmp( const void *a, const void *b )
{
return Q_stricmp( (const char *)a, ((dummyCmd_t *)b)->name );
Expand Down
4 changes: 3 additions & 1 deletion src/game/bg_public.h
Expand Up @@ -133,6 +133,8 @@ enum
#error overflow: CS_MAX > MAX_CONFIGSTRINGS
#endif

#define MAX_INTERMISSION_SOUND_SETS 1

typedef enum
{
GENDER_MALE,
Expand Down Expand Up @@ -1178,6 +1180,7 @@ typedef struct
team_t number;

char *name;
char *name2;
char *humanName;
char *info;
} teamAttributes_t;
Expand Down Expand Up @@ -1539,7 +1542,6 @@ voiceTrack_t *BG_VoiceTrackFind( voiceTrack_t *head, team_t team,
int BG_LoadEmoticons( emoticon_t *emoticons, int num );

const teamAttributes_t *BG_Team( team_t team );
char *BG_TeamName( team_t team );

typedef struct
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/g_active.c
Expand Up @@ -583,7 +583,7 @@ qboolean ClientInactivityTimer( gentity_t *ent )
SV_GameSendServerCommand( -1,
va( "print \"%s^7 moved from %s to spectators due to inactivity\n\"",
client->pers.netname,
BG_TeamName( client->pers.teamSelection ) ) );
BG_Team( client->pers.teamSelection )->name2 ) );
G_LogPrintf( "Inactivity: %d", (int)(client - level.clients) );
G_ChangeTeam( ent, TEAM_NONE );
}
Expand Down

0 comments on commit eaa2f7a

Please sign in to comment.