Split map code checking from Command_Map_f

(cherry picked from commit 19aafbfd0b9bde40809ca91195d4636899504708)
This commit is contained in:
James R 2019-12-29 02:14:02 -08:00
parent 1adae3deea
commit 52a863d1fd
3 changed files with 58 additions and 44 deletions

View file

@ -2530,19 +2530,16 @@ static void Command_Map_f(void)
boolean newresetplayers;
boolean mustmodifygame;
boolean usemapcode = false;
INT32 newmapnum;
char * mapname;
size_t mapnamelen;
char *realmapname = NULL;
INT32 newgametype = gametype;
boolean newencoremode = cv_kartencore.value;
INT32 d;
char *p;
if (client && !IsPlayerAdmin(consoleplayer))
{
@ -2601,43 +2598,8 @@ static void Command_Map_f(void)
}
mapname = ConcatCommandArgv(1, first_option);
mapnamelen = strlen(mapname);
if (mapnamelen == 2)/* maybe two digit code */
{
if (( newmapnum = M_MapNumber(mapname[0], mapname[1]) ))
usemapcode = true;
}
else if (mapnamelen == 5 && strnicmp(mapname, "MAP", 3) == 0)
{
if (( newmapnum = M_MapNumber(mapname[3], mapname[4]) ) == 0)
{
CONS_Alert(CONS_ERROR, M_GetText("Invalid map code '%s'.\n"), mapname);
Z_Free(mapname);
return;
}
usemapcode = true;
}
if (!usemapcode)
{
/* Now detect map number in base 10, which no one asked for. */
newmapnum = strtol(mapname, &p, 10);
if (*p == '\0')/* we got it */
{
if (newmapnum < 1 || newmapnum > NUMMAPS)
{
CONS_Alert(CONS_ERROR, M_GetText("Invalid map number %d.\n"), newmapnum);
Z_Free(mapname);
return;
}
usemapcode = true;
}
else
{
newmapnum = G_FindMap(mapname, &realmapname, NULL, NULL);
}
}
newmapnum = G_FindMapByNameOrCode(mapname, &realmapname);
if (newmapnum == 0)
{
@ -2646,11 +2608,6 @@ static void Command_Map_f(void)
return;
}
if (usemapcode)
{
realmapname = G_BuildMapTitle(newmapnum);
}
if (mustmodifygame && option_force)
{
G_SetGameModified(false, true);

View file

@ -4928,6 +4928,60 @@ void G_FreeMapSearch(mapsearchfreq_t *freq, INT32 freqc)
Z_Free(freq);
}
INT32 G_FindMapByNameOrCode(const char *mapname, char **realmapnamep)
{
boolean usemapcode = false;
INT32 newmapnum;
size_t mapnamelen;
char *p;
mapnamelen = strlen(mapname);
if (mapnamelen == 2)/* maybe two digit code */
{
if (( newmapnum = M_MapNumber(mapname[0], mapname[1]) ))
usemapcode = true;
}
else if (mapnamelen == 5 && strnicmp(mapname, "MAP", 3) == 0)
{
if (( newmapnum = M_MapNumber(mapname[3], mapname[4]) ) == 0)
{
CONS_Alert(CONS_ERROR, M_GetText("Invalid map code '%s'.\n"), mapname);
return 0;
}
usemapcode = true;
}
if (!usemapcode)
{
/* Now detect map number in base 10, which no one asked for. */
newmapnum = strtol(mapname, &p, 10);
if (*p == '\0')/* we got it */
{
if (newmapnum < 1 || newmapnum > NUMMAPS)
{
CONS_Alert(CONS_ERROR, M_GetText("Invalid map number %d.\n"), newmapnum);
return 0;
}
usemapcode = true;
}
else
{
newmapnum = G_FindMap(mapname, realmapnamep, NULL, NULL);
}
}
if (usemapcode)
{
(*realmapnamep) = G_BuildMapTitle(newmapnum);
}
return newmapnum;
}
//
// DEMO RECORDING
//

View file

@ -193,6 +193,9 @@ INT32 G_FindMap(const char *query, char **foundmapnamep,
mapsearchfreq_t **freqp, INT32 *freqc);
void G_FreeMapSearch(mapsearchfreq_t *freq, INT32 freqc);
/* Match map name by search + 2 digit map code or map number. */
INT32 G_FindMapByNameOrCode(const char *query, char **foundmapnamep);
// XMOD spawning
mapthing_t *G_FindCTFStart(INT32 playernum);
mapthing_t *G_FindMatchStart(INT32 playernum);