Skip to content

Commit

Permalink
DISCORD: add game type to status message
Browse files Browse the repository at this point in the history
see issue #305

the gameNames_Long and gameNames_Short arrays should be used in a few more locations to clean up the code
duplication
  • Loading branch information
mgerhardy committed Nov 19, 2024
1 parent 26831a7 commit 84d09b8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
11 changes: 11 additions & 0 deletions code/game/bg_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,17 @@ void BG_PlayerStateToEntityStateExtraPolate(playerState_t *ps, entityState_t *s,
s->generic1 = ps->generic1;
}

const char *gameNames_Long[GT_MAX_GAME_TYPE] = {
GAMETYPE_NAME(GT_FFA), GAMETYPE_NAME(GT_TOURNAMENT), GAMETYPE_NAME(GT_SINGLE_PLAYER), GAMETYPE_NAME(GT_SPRAYFFA),
GAMETYPE_NAME(GT_LPS), GAMETYPE_NAME(GT_CATCH), GAMETYPE_NAME(GT_TEAM), GAMETYPE_NAME(GT_FREEZETAG),
GAMETYPE_NAME(GT_CTF), GAMETYPE_NAME(GT_1FCTF), GAMETYPE_NAME(GT_SPRAY), GAMETYPE_NAME(GT_BALLOON)};

const char *gameNames_Short[GT_MAX_GAME_TYPE] = {
GAMETYPE_NAME_SHORT(GT_FFA), GAMETYPE_NAME_SHORT(GT_TOURNAMENT), GAMETYPE_NAME_SHORT(GT_SINGLE_PLAYER),
GAMETYPE_NAME_SHORT(GT_SPRAYFFA), GAMETYPE_NAME_SHORT(GT_LPS), GAMETYPE_NAME_SHORT(GT_CATCH),
GAMETYPE_NAME_SHORT(GT_TEAM), GAMETYPE_NAME_SHORT(GT_FREEZETAG), GAMETYPE_NAME_SHORT(GT_CTF),
GAMETYPE_NAME_SHORT(GT_1FCTF), GAMETYPE_NAME_SHORT(GT_SPRAY), GAMETYPE_NAME_SHORT(GT_BALLOON)};

int convertGTStringToGTNumber(const char *argStr) {
int gt = -1;
char buf[512];
Expand Down
3 changes: 3 additions & 0 deletions code/game/bg_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ typedef enum {
#define GAMETYPE_NAME(gametype) GTN__##gametype
#define GAMETYPE_NAME_SHORT(gametype) GTN_S__##gametype

extern const char *gameNames_Long[GT_MAX_GAME_TYPE];
extern const char *gameNames_Short[GT_MAX_GAME_TYPE];

int convertGTStringToGTNumber(const char *argStr);

typedef enum { GENDER_MALE, GENDER_FEMALE, GENDER_NEUTER, GENDER_MAX } gender_t;
Expand Down
13 changes: 9 additions & 4 deletions code/game/g_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,10 @@ const char *ClientConnect(int clientNum, qboolean firstTime, qboolean isBot) {
gclient_t *client;
char userinfo[MAX_INFO_STRING];
gentity_t *ent;
int gametype = g_gametype.integer;
if (gametype < 0 || gametype >= GT_MAX_GAME_TYPE) {
gametype = GT_MAX_GAME_TYPE - 1;
}

ent = &g_entities[clientNum];

Expand Down Expand Up @@ -1014,12 +1018,13 @@ const char *ClientConnect(int clientNum, qboolean firstTime, qboolean isBot) {
}

if (isTeam) {
buf = va("%i %s playing **%s**\n* Blue Noses: %i (and %i bots)\n* Red Pads: %i (and %i bots)\n* "
buf = va("%i %s playing **%s** on **%s**\n* Blue Noses: %i (and %i bots)\n* Red Pads: %i (and %i bots)\n* "
"Spectators: %i",
humanAll, padPlayerStr, map, humanCount[TEAM_BLUE], botCount[TEAM_BLUE], humanCount[TEAM_RED],
botCount[TEAM_RED], humanCount[TEAM_SPECTATOR]);
humanAll, padPlayerStr, gameNames_Short[gametype], map, humanCount[TEAM_BLUE], botCount[TEAM_BLUE],
humanCount[TEAM_RED], botCount[TEAM_RED], humanCount[TEAM_SPECTATOR]);
} else {
buf = va("%i %s playing **%s**\n* Spectators: %i", humanAll, padPlayerStr, map, humanCount[TEAM_SPECTATOR]);
buf = va("%i %s playing **%s** on **%s**\n* Spectators: %i", humanAll, padPlayerStr,
gameNames_Short[gametype], map, humanCount[TEAM_SPECTATOR]);
}
trap_GlobalMessage(NULL, buf);
}
Expand Down
9 changes: 1 addition & 8 deletions code/game/g_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,21 +1175,14 @@ static void Cmd_CallVote_f(gentity_t *ent) {

// special case for g_gametype, check for bad values
if (!Q_stricmp(arg1, "g_gametype")) {
static const char *gametypeNames[GT_MAX_GAME_TYPE] = {
GAMETYPE_NAME(GT_FFA), GAMETYPE_NAME(GT_TOURNAMENT), GAMETYPE_NAME(GT_SINGLE_PLAYER),
GAMETYPE_NAME(GT_SPRAYFFA), GAMETYPE_NAME(GT_LPS), GAMETYPE_NAME(GT_CATCH),
GAMETYPE_NAME(GT_TEAM), GAMETYPE_NAME(GT_FREEZETAG), GAMETYPE_NAME(GT_CTF),
GAMETYPE_NAME(GT_1FCTF), GAMETYPE_NAME(GT_SPRAY), GAMETYPE_NAME(GT_BALLOON)};
CASSERT(ARRAY_LEN(gametypeNames) == GT_MAX_GAME_TYPE);

i = atoi(arg2);
if (i == GT_SINGLE_PLAYER || i < GT_FFA || i >= GT_MAX_GAME_TYPE) {
trap_SendServerCommand(ent - g_entities, "print \"Invalid gametype.\n\"");
return;
}

Com_sprintf(level.voteString, sizeof(level.voteString), "set g_gametype %i", i);
Com_sprintf(level.voteDisplayString, sizeof(level.voteDisplayString), "Gametype %s", gametypeNames[i]);
Com_sprintf(level.voteDisplayString, sizeof(level.voteDisplayString), "Gametype %s", gameNames_Long[i]);
} else if (!Q_stricmp(arg1, "map")) {
// special case for map changes, we want to reset the nextmap setting
// this allows a player to change maps, but not upset the map rotation
Expand Down

0 comments on commit 84d09b8

Please sign in to comment.