Store teamnames in both upper and lower case

This commit is contained in:
Lactozilla 2023-08-06 21:30:03 -03:00
parent f6f5dcef1c
commit f3f9a0f4cb
6 changed files with 41 additions and 27 deletions

View file

@ -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;
}
@ -578,7 +574,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;
}

View file

@ -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"))
{
@ -4363,7 +4357,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);

View file

@ -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

View file

@ -3531,7 +3531,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)
{
@ -3540,7 +3552,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");
@ -3548,7 +3559,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");
@ -3556,7 +3566,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();
}
@ -3930,6 +3943,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)

View file

@ -223,6 +223,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);

View file

@ -1816,7 +1816,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;
@ -2737,12 +2737,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");
}