From b34ef81efe9b993711a8343bc90eabe55e133f05 Mon Sep 17 00:00:00 2001 From: Lactozilla <jp6781615@gmail.com> Date: Sun, 6 Aug 2023 21:30:03 -0300 Subject: [PATCH] Store teamnames in both upper and lower case --- src/deh_lua.c | 10 +++------- src/deh_soc.c | 10 ++-------- src/doomstat.h | 2 +- src/g_game.c | 36 ++++++++++++++++++++++++++++++++---- src/g_game.h | 1 + src/p_setup.c | 9 ++------- 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/deh_lua.c b/src/deh_lua.c index 9696426d25..7daef303fb 100644 --- a/src/deh_lua.c +++ b/src/deh_lua.c @@ -133,15 +133,11 @@ static inline int lib_freeslot(lua_State *L) } else if (fastcmp(type, "TEAM")) { - if (numteams == MAXTEAMS) + UINT8 i = G_AddTeam(word); + if (i == MAXTEAMS) CONS_Alert(CONS_WARNING, "Ran out of free team slots!\n"); - UINT8 i = numteams; CONS_Printf("Team TEAM_%s allocated.\n",word); - teamnames[i] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); - strcpy(teamnames[i],word); lua_pushinteger(L, i); - G_InitTeam(i); - numteams++; r++; break; } @@ -579,7 +575,7 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word) p = word+5; for (i = 0; i < numteams; i++) { - if (fastcmp(p, teamnames[i])) { + if (fastcmp(p, teamnames[i][0])) { CacheAndPushConstant(L, word, i); return 1; } diff --git a/src/deh_soc.c b/src/deh_soc.c index 509d56959d..9ebec77b6e 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -475,13 +475,7 @@ void readfreeslots(MYFILE *f) } else if (fastcmp(type, "TEAM")) { - if (numteams < MAXTEAMS) - { - teamnames[numteams] = Z_Malloc(strlen(word)+1, PU_STATIC, NULL); - strcpy(teamnames[numteams],word); - G_InitTeam(numteams); - numteams++; - } + G_AddTeam(word); } else if (fastcmp(type, "SPR2")) { @@ -4366,7 +4360,7 @@ UINT8 get_team(const char *word) word += 5; // take off the TEAM_ for (i = 0; i < numteams; i++) { - if (fastcmp(word, teamnames[i])) + if (fastcmp(word, teamnames[i][0])) return i; } deh_warning("Couldn't find team named 'TEAM_%s'",word); diff --git a/src/doomstat.h b/src/doomstat.h index 5b30f4bb36..044c46dc12 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -418,7 +418,7 @@ typedef struct extern team_t teams[MAXTEAMS]; extern UINT8 numteams; -extern char *teamnames[MAXTEAMS]; +extern char *teamnames[MAXTEAMS][2]; #define NUMGAMETYPEFREESLOTS 128 diff --git a/src/g_game.c b/src/g_game.c index a441d6b6d7..7ee6bab36f 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3525,7 +3525,19 @@ team_t teams[MAXTEAMS] = { } }; -char *teamnames[MAXTEAMS]; +char *teamnames[MAXTEAMS][2]; + +static void G_SetTeamName(UINT8 i, const char *name) +{ + Z_Free(teamnames[i][0]); + Z_Free(teamnames[i][1]); + + teamnames[i][0] = Z_StrDup(name); + teamnames[i][1] = Z_StrDup(name); + + strupr(teamnames[i][0]); + strlwr(teamnames[i][1]); +} static void G_InitTeams(void) { @@ -3534,7 +3546,6 @@ static void G_InitTeams(void) teams[TEAM_NONE].name = Z_StrDup("None"); teams[TEAM_NONE].flag_name = Z_StrDup("Thingmabob"); - teamnames[TEAM_NONE] = Z_StrDup("NONE"); teams[TEAM_RED].name = Z_StrDup("Red"); teams[TEAM_RED].flag_name = Z_StrDup("Red Flag"); @@ -3542,7 +3553,6 @@ static void G_InitTeams(void) teams[TEAM_RED].icons[TEAM_ICON_FLAG] = Z_StrDup("RFLAGICO"); teams[TEAM_RED].icons[TEAM_ICON_GOT_FLAG] = Z_StrDup("GOTRFLAG"); teams[TEAM_RED].icons[TEAM_ICON_MISSING_FLAG] = Z_StrDup("NONICON2"); - teamnames[TEAM_RED] = Z_StrDup("RED"); teams[TEAM_BLUE].name = Z_StrDup("Blue"); teams[TEAM_BLUE].flag_name = Z_StrDup("Blue Flag"); @@ -3550,7 +3560,10 @@ static void G_InitTeams(void) teams[TEAM_BLUE].icons[TEAM_ICON_FLAG] = Z_StrDup("BFLAGICO"); teams[TEAM_BLUE].icons[TEAM_ICON_GOT_FLAG] = Z_StrDup("GOTBFLAG"); teams[TEAM_BLUE].icons[TEAM_ICON_MISSING_FLAG] = Z_StrDup("NONICON"); - teamnames[TEAM_BLUE] = Z_StrDup("BLUE"); + + G_SetTeamName(TEAM_NONE, "NONE"); + G_SetTeamName(TEAM_RED, "RED"); + G_SetTeamName(TEAM_BLUE, "BLUE"); G_UpdateTeamSelection(); } @@ -3924,6 +3937,21 @@ void G_InitTeam(UINT8 team) memset(&teams[team], 0, sizeof(team_t)); } +UINT8 G_AddTeam(const char *name) +{ + if (numteams == MAXTEAMS) + return MAXTEAMS; + + UINT8 i = numteams; + + G_InitTeam(i); + G_SetTeamName(i, name); + + numteams++; + + return i; +} + UINT8 G_GetGametypeTeam(UINT8 gtype, UINT8 team) { if (team == TEAM_NONE || team >= gametypes[gtype].teams.num + 1) diff --git a/src/g_game.h b/src/g_game.h index d2021bab58..7bd9ded323 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -224,6 +224,7 @@ void G_AfterIntermission(void); void G_EndGame(void); // moved from y_inter.c/h and renamed void G_InitTeam(UINT8 team); +UINT8 G_AddTeam(const char *name); UINT8 G_GetGametypeTeam(UINT8 gtype, UINT8 team); UINT8 G_GetTeam(UINT8 team); UINT8 G_GetTeamFromTeamFlag(UINT32 flag); diff --git a/src/p_setup.c b/src/p_setup.c index 1c170b451b..94daad2726 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1826,7 +1826,7 @@ static void ParseTextmapSectorParameter(UINT32 i, const char *param, const char for (UINT8 j = 0; j < numteams; j++) { - if (fastcmp(val, teamnames[j])) + if (fastcmp(val, teamnames[j][1])) { sectors[j].teambase = j; break; @@ -2749,12 +2749,7 @@ static void P_WriteTextmap(void) // actual teams TEAM_RED and TEAM_BLUE. UINT8 team = wsectors[i].teambase; if (team != TEAM_NONE && team < numteams) - { - char *teambase = Z_StrDup(teamnames[team]); - strlwr(teambase); - fprintf(f, "teambase = \"%s\";\n", teambase); - Z_Free(teambase); - } + fprintf(f, "teambase = \"%s\";\n", teamnames[team][1]); else fprintf(f, "teambase = \"%s\";\n", "unknown"); } -- GitLab