Add support for custom keywords
For now, 32 characters separated by spaces. Also fixed a SIGSEGV from an empty level title.
This commit is contained in:
parent
6358d839ee
commit
bb65e8d72f
|
@ -1719,6 +1719,25 @@ void D_MapChange(INT32 mapnum, INT32 newgametype, boolean pultmode, boolean rese
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Return the number of times a series of keywords, delimited by spaces, matched.
|
||||||
|
*/
|
||||||
|
static int measurekeywords(const char *s, const char *q)
|
||||||
|
{
|
||||||
|
int r = 0;
|
||||||
|
char *qp;
|
||||||
|
for (qp = strtok(va("%s", q), " ");
|
||||||
|
qp;
|
||||||
|
qp = strtok(0, " "))
|
||||||
|
{
|
||||||
|
if (strcasestr(s, qp))
|
||||||
|
{
|
||||||
|
r++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Easy macro; declare parm_*id* and define acceptableargc; put in the parameter
|
Easy macro; declare parm_*id* and define acceptableargc; put in the parameter
|
||||||
to match as a string as *name*. Set *argn* to the number of extra arguments
|
to match as a string as *name*. Set *argn* to the number of extra arguments
|
||||||
|
@ -1757,8 +1776,6 @@ static void Command_Map_f(void)
|
||||||
char *apromapname = NULL;
|
char *apromapname = NULL;
|
||||||
|
|
||||||
/* Keyword matching */
|
/* Keyword matching */
|
||||||
char *query;
|
|
||||||
char *key;
|
|
||||||
UINT8 *freq;
|
UINT8 *freq;
|
||||||
UINT8 freqc;
|
UINT8 freqc;
|
||||||
|
|
||||||
|
@ -1860,13 +1877,13 @@ static void Command_Map_f(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
query = ZZ_Alloc(strlen(mapname)+1);
|
|
||||||
freq = ZZ_Calloc(NUMMAPS * sizeof (UINT8));
|
freq = ZZ_Calloc(NUMMAPS * sizeof (UINT8));
|
||||||
|
|
||||||
for (i = 0, newmapnum = 1; i < NUMMAPS; ++i, ++newmapnum)
|
for (i = 0, newmapnum = 1; i < NUMMAPS; ++i, ++newmapnum)
|
||||||
if (mapheaderinfo[i])
|
if (mapheaderinfo[i])
|
||||||
{
|
{
|
||||||
realmapname = G_BuildMapTitle(newmapnum);
|
if (!( realmapname = G_BuildMapTitle(newmapnum) ))
|
||||||
|
continue;
|
||||||
|
|
||||||
/* Now that we found a perfect match no need to fucking guess. */
|
/* Now that we found a perfect match no need to fucking guess. */
|
||||||
if (strnicmp(realmapname, mapname, mapnamelen) == 0)
|
if (strnicmp(realmapname, mapname, mapnamelen) == 0)
|
||||||
|
@ -1886,16 +1903,9 @@ static void Command_Map_f(void)
|
||||||
}
|
}
|
||||||
else/* ...match individual keywords */
|
else/* ...match individual keywords */
|
||||||
{
|
{
|
||||||
strcpy(query, mapname);
|
freq[i] += measurekeywords(realmapname, mapname);
|
||||||
for (key = strtok(query, " ");
|
freq[i] += measurekeywords(mapheaderinfo[i]->keyword,
|
||||||
key;
|
mapname);
|
||||||
key = strtok(0, " "))
|
|
||||||
{
|
|
||||||
if (strcasestr(realmapname, key))
|
|
||||||
{
|
|
||||||
freq[i]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1926,7 +1936,6 @@ static void Command_Map_f(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
Z_Free(freq);
|
Z_Free(freq);
|
||||||
Z_Free(query);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1205,6 +1205,11 @@ static void readlevelheader(MYFILE *f, INT32 num)
|
||||||
mapheaderinfo[num-1]->typeoflevel = tol;
|
mapheaderinfo[num-1]->typeoflevel = tol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (fastcmp(word, "KEYWORD"))
|
||||||
|
{
|
||||||
|
deh_strlcpy(mapheaderinfo[num-1]->keyword, word2,
|
||||||
|
sizeof(mapheaderinfo[num-1]->keyword), va("Level header %d: keyword", num));
|
||||||
|
}
|
||||||
else if (fastcmp(word, "MUSIC"))
|
else if (fastcmp(word, "MUSIC"))
|
||||||
{
|
{
|
||||||
if (fastcmp(word2, "NONE"))
|
if (fastcmp(word2, "NONE"))
|
||||||
|
|
|
@ -286,6 +286,7 @@ typedef struct
|
||||||
UINT8 actnum; ///< Act number or 0 for none.
|
UINT8 actnum; ///< Act number or 0 for none.
|
||||||
UINT16 typeoflevel; ///< Combination of typeoflevel flags.
|
UINT16 typeoflevel; ///< Combination of typeoflevel flags.
|
||||||
INT16 nextlevel; ///< Map number of next level, or 1100-1102 to end.
|
INT16 nextlevel; ///< Map number of next level, or 1100-1102 to end.
|
||||||
|
char keyword[33]; ///< Keywords separated by space to search for. 32 characters.
|
||||||
char musname[7]; ///< Music track to play. "" for no music.
|
char musname[7]; ///< Music track to play. "" for no music.
|
||||||
UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore.
|
UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore.
|
||||||
UINT32 muspos; ///< Music position to jump to.
|
UINT32 muspos; ///< Music position to jump to.
|
||||||
|
|
|
@ -2014,6 +2014,8 @@ static int mapheaderinfo_get(lua_State *L)
|
||||||
lua_pushinteger(L, header->typeoflevel);
|
lua_pushinteger(L, header->typeoflevel);
|
||||||
else if (fastcmp(field,"nextlevel"))
|
else if (fastcmp(field,"nextlevel"))
|
||||||
lua_pushinteger(L, header->nextlevel);
|
lua_pushinteger(L, header->nextlevel);
|
||||||
|
else if (fastcmp(field,"keyword"))
|
||||||
|
lua_pushstring(L, header->keyword);
|
||||||
else if (fastcmp(field,"musname"))
|
else if (fastcmp(field,"musname"))
|
||||||
lua_pushstring(L, header->musname);
|
lua_pushstring(L, header->musname);
|
||||||
else if (fastcmp(field,"mustrack"))
|
else if (fastcmp(field,"mustrack"))
|
||||||
|
|
|
@ -211,6 +211,7 @@ static void P_ClearSingleMapHeaderInfo(INT16 i)
|
||||||
mapheaderinfo[num]->typeoflevel = 0;
|
mapheaderinfo[num]->typeoflevel = 0;
|
||||||
mapheaderinfo[num]->nextlevel = (INT16)(i + 1);
|
mapheaderinfo[num]->nextlevel = (INT16)(i + 1);
|
||||||
mapheaderinfo[num]->startrings = 0;
|
mapheaderinfo[num]->startrings = 0;
|
||||||
|
mapheaderinfo[num]->keyword[0] = '\0';
|
||||||
snprintf(mapheaderinfo[num]->musname, 7, "%sM", G_BuildMapName(i));
|
snprintf(mapheaderinfo[num]->musname, 7, "%sM", G_BuildMapName(i));
|
||||||
mapheaderinfo[num]->musname[6] = 0;
|
mapheaderinfo[num]->musname[6] = 0;
|
||||||
mapheaderinfo[num]->mustrack = 0;
|
mapheaderinfo[num]->mustrack = 0;
|
||||||
|
|
Loading…
Reference in New Issue