diff --git a/src/deh_lua.c b/src/deh_lua.c index 9696426d256c85cb62f7faaf544137caa17fa507..7daef303fbb0ec93517c84a8e9b90311968210d4 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 509d56959d3ad3166bdbf0a25b54bc4afec2c74d..9ebec77b6e1c4194df5f822be3da24ed5564bc2a 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 5b30f4bb36dd5f00900315c17b8020f4556da723..044c46dc12e3823d56b48f5b12ccc7df455f44fd 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 a441d6b6d72e4859e32a60e2349fe2796992a489..7ee6bab36fc1ad7b394a9fda0e58ae52466022dc 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 d2021bab589c669cde9c1f387673fd6588284867..7bd9ded323ae102e48f1a5ec2e6d30e102f7e553 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 1c170b451babf5a8c2853eea945bc6a8e45970f4..94daad2726c7ab8904f4b9471e6150430fdb8d77 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"); }