mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-21 11:21:11 +00:00
Split map code checking from Command_Map_f
This commit is contained in:
parent
c27d062cc8
commit
19aafbfd0b
3 changed files with 58 additions and 44 deletions
|
@ -1802,18 +1802,15 @@ static void Command_Map_f(void)
|
||||||
boolean newresetplayers;
|
boolean newresetplayers;
|
||||||
|
|
||||||
boolean mustmodifygame;
|
boolean mustmodifygame;
|
||||||
boolean usemapcode = false;
|
|
||||||
|
|
||||||
INT32 newmapnum;
|
INT32 newmapnum;
|
||||||
|
|
||||||
char * mapname;
|
char * mapname;
|
||||||
size_t mapnamelen;
|
|
||||||
char *realmapname = NULL;
|
char *realmapname = NULL;
|
||||||
|
|
||||||
INT32 newgametype = gametype;
|
INT32 newgametype = gametype;
|
||||||
|
|
||||||
INT32 d;
|
INT32 d;
|
||||||
char *p;
|
|
||||||
|
|
||||||
if (client && !IsPlayerAdmin(consoleplayer))
|
if (client && !IsPlayerAdmin(consoleplayer))
|
||||||
{
|
{
|
||||||
|
@ -1873,43 +1870,8 @@ static void Command_Map_f(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
mapname = ConcatCommandArgv(1, first_option);
|
mapname = ConcatCommandArgv(1, first_option);
|
||||||
mapnamelen = strlen(mapname);
|
|
||||||
|
|
||||||
if (mapnamelen == 2)/* maybe two digit code */
|
newmapnum = G_FindMapByNameOrCode(mapname, &realmapname);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newmapnum == 0)
|
if (newmapnum == 0)
|
||||||
{
|
{
|
||||||
|
@ -1918,11 +1880,6 @@ static void Command_Map_f(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usemapcode)
|
|
||||||
{
|
|
||||||
realmapname = G_BuildMapTitle(newmapnum);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mustmodifygame && option_force)
|
if (mustmodifygame && option_force)
|
||||||
{
|
{
|
||||||
G_SetGameModified(false);
|
G_SetGameModified(false);
|
||||||
|
|
54
src/g_game.c
54
src/g_game.c
|
@ -4536,6 +4536,60 @@ void G_FreeMapSearch(mapsearchfreq_t *freq, INT32 freqc)
|
||||||
Z_Free(freq);
|
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
|
// DEMO RECORDING
|
||||||
//
|
//
|
||||||
|
|
|
@ -130,6 +130,9 @@ INT32 G_FindMap(const char *query, char **foundmapnamep,
|
||||||
mapsearchfreq_t **freqp, INT32 *freqc);
|
mapsearchfreq_t **freqp, INT32 *freqc);
|
||||||
void G_FreeMapSearch(mapsearchfreq_t *freq, 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
|
// XMOD spawning
|
||||||
mapthing_t *G_FindCTFStart(INT32 playernum);
|
mapthing_t *G_FindCTFStart(INT32 playernum);
|
||||||
mapthing_t *G_FindMatchStart(INT32 playernum);
|
mapthing_t *G_FindMatchStart(INT32 playernum);
|
||||||
|
|
Loading…
Reference in a new issue