Split map code checking from Command_Map_f

This commit is contained in:
James R 2019-12-29 02:14:02 -08:00
parent c27d062cc8
commit 19aafbfd0b
3 changed files with 58 additions and 44 deletions

View File

@ -1802,18 +1802,15 @@ 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;
INT32 d;
char *p;
if (client && !IsPlayerAdmin(consoleplayer))
{
@ -1873,43 +1870,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)
{
@ -1918,11 +1880,6 @@ static void Command_Map_f(void)
return;
}
if (usemapcode)
{
realmapname = G_BuildMapTitle(newmapnum);
}
if (mustmodifygame && option_force)
{
G_SetGameModified(false);

View File

@ -4536,6 +4536,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

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